#include <tutsim.hpp>
Static Public Member Functions | |
static void | set_robot_filename (char const *robot_filename) |
Override the default robot filename with something else. | |
static void | set_rates (double gfx_rate_hz, double servo_rate_hz, double sim_rate_hz) |
Override the default update rates. | |
static void | set_window_params (int width, int height, char const *title) |
Override the default parameters that get passed to the fltk window. | |
static void | draw_robot (jspace::Vector const &jpos, int width, unsigned char red, unsigned char green, unsigned char blue, double x0, double y0, double scale) |
Draw the robot as if it were at the given joint configuration. | |
static void | draw_delta_jpos (jspace::Vector const &jpos, int width, unsigned char red, unsigned char green, unsigned char blue, double x0, double y0, double scale) |
Draw the difference between the current simulated robot configuration and the given jpos. | |
static void | set_draw_cb (void(*draw_cb)(double x0, double y0, double scale)) |
Set a custom function for drawing additional information. | |
static int | run (bool(*servo_cb)(size_t toggle_count, double wall_time_ms, double sim_time_ms, jspace::State &state, jspace::Vector &command)) |
Sets up the planar tutorial simulator and runs it, calling the supplied function whenever the servo needs to be updated. |
We use a struct instead of a namespace in order to profit from compile-time method signature checks.
Definition at line 40 of file tutsim.hpp.
void tutsim::set_robot_filename | ( | char const * | robot_filename | ) | [static] |
Override the default robot filename with something else.
The default should be correctly set up by the CMake build system to point to the file tutrob.xml in the source directory of the tutorials. In case that goes wrong somehow, you can always override it here at runtime.
Definition at line 414 of file tutsim.cpp.
References robot_filename().
void tutsim::set_rates | ( | double | gfx_rate_hz, | |
double | servo_rate_hz, | |||
double | sim_rate_hz | |||
) | [static] |
Override the default update rates.
At the time of writing, these were gfx_rate_hz=20, servo_rate_hz=400, and sim_rate_hz=1600.
Definition at line 421 of file tutsim.cpp.
References gfx_rate_hz(), servo_rate_hz(), and sim_rate_hz().
void tutsim::set_window_params | ( | int | width, | |
int | height, | |||
char const * | title | |||
) | [static] |
Override the default parameters that get passed to the fltk window.
At the time of writing, these were width=300, height=200, title="utaustin-wbc tutorial".
Definition at line 432 of file tutsim.cpp.
References win_height(), win_title(), and win_width().
void tutsim::draw_robot | ( | jspace::Vector const & | jpos, | |
int | width, | |||
unsigned char | red, | |||
unsigned char | green, | |||
unsigned char | blue, | |||
double | x0, | |||
double | y0, | |||
double | scale | |||
) | [static] |
Draw the robot as if it were at the given joint configuration.
Uses the specified line width and color. To be used from inside a function that you register with set_draw_cb(), which gets the correct x0, y0, and scale passed to it..
Definition at line 441 of file tutsim.cpp.
References raw_draw_tree(), scratch_tree, and write_state_to_tree().
Referenced by draw_cb().
void tutsim::draw_delta_jpos | ( | jspace::Vector const & | jpos, | |
int | width, | |||
unsigned char | red, | |||
unsigned char | green, | |||
unsigned char | blue, | |||
double | x0, | |||
double | y0, | |||
double | scale | |||
) | [static] |
Draw the difference between the current simulated robot configuration and the given jpos.
Definition at line 454 of file tutsim.cpp.
References find_node(), id1(), id2(), id3(), id4(), read_state_from_tree(), scratch_tree, sim_tree, and write_state_to_tree().
Referenced by draw_cb().
void tutsim::set_draw_cb | ( | void(*)(double x0, double y0, double scale) | draw_cb | ) | [static] |
Set a custom function for drawing additional information.
Use e.g. draw_robot(), or you can emit raw fltk drawing commands. In the latter case, you need to take into account the x0, y0, and scale parameters, and keep in mind that fltk uses screen coordinates where the Y-axis is pointing down. For instance, if you want to draw a line from (ax, ay) to (bx, by) you have to say:
fl_line(x0 + ax * scale, y0 - ay * scale, x0 + bx * scale, y0 - by * scale);
Definition at line 508 of file tutsim.cpp.
References draw_cb.
Referenced by main().
int tutsim::run | ( | bool(*)(size_t toggle_count, double wall_time_ms, double sim_time_ms, jspace::State &state, jspace::Vector &command) | servo_cb | ) | [static] |
Sets up the planar tutorial simulator and runs it, calling the supplied function whenever the servo needs to be updated.
Inside your callback, you can either override the state and return false, in which case the simulator state gets re-initialized to whatever you specified; or you can set the command vector and return true, in which case the simulator will be used to update the robot state based on its rigid body dynamics and your supplied command torques. The toggle_count gets incremented each time the "Toggle" button gets pressed in the GUI, allowing very simple interaction with your callback.
Definition at line 515 of file tutsim.cpp.
References gfx_rate_hz(), jspace::State::init(), robot_filename(), scratch_tree, servo_cb, servo_rate_hz(), sim_tree, win_height(), win_title(), win_width(), and write_state_to_tree().
Referenced by main().