#include "mbs_data.h"
#include "realtime.h"
#include "user_realtime_visu.h"
#include "mbs_project_interface.h"
#include <stdint.h>
Go to the source code of this file.
Functions | |
void | user_realtime_plot (MbsData *mbs_data) |
assign values for the SDL functions More... | |
void | user_keyboard (MbsData *mbs_data, Simu_realtime *realtime, int cur_t_usec, const uint8_t *keystates) |
handle inputs comming from the keyboard More... | |
void | user_joystick_axes (MbsData *mbs_data, Simu_realtime *realtime, int nb_joysticks) |
handle inputs comming from joysticks axes More... | |
void | user_joystick_buttons (MbsData *mbs_data, int buttonID) |
handle inputs comming from joysticks buttons More... | |
void | wait_key (Simu_realtime *realtime, int cur_t_usec, double tsim) |
void | set_plot (double value, char *label) |
function called by the user to plot a curve More... | |
void set_plot | ( | double | value, |
char * | label | ||
) |
function called by the user to plot a curve
[in] | value | current value of the curve |
[in] | label | label of the curve |
void user_joystick_axes | ( | MbsData * | mbs_data, |
Simu_realtime * | realtime, | ||
int | nb_joysticks | ||
) |
handle inputs comming from joysticks axes
[in,out] | mbs_data | Robotran main structure |
[in] | realtime | real-time structure |
[in] | nb_joysticks | number of joysticks detected |
Use get_Joystick_axis(int joystickID, int axisID, Simu_realtime *realtime) to return the value associated with the joystick number joystickID
joystickID: ID of the joystick (starting at 0) axisID: ID of the axis (starting at 0)
get_Joystick_axis returns a value in [-1 ; 1] or -10 if this joystickID is not available
plugged joysticks are automatically detected at launch (see nb_joysticks)
example: joystick_val = get_Joystick_axis(0, 0, realtime); mbs_data->user_IO->my_variable = joystick_val * scaling_factor;
void user_joystick_buttons | ( | MbsData * | mbs_data, |
int | buttonID | ||
) |
handle inputs comming from joysticks buttons
[in,out] | mbs_data | Robotran main structure |
[in] | buttonID | ID of the joystick button |
buttonID takes a value (usually starting at 0) when a joystick button is pressed
Use printf to detect which 'buttonID' is used for the different buttons.
example: if (buttonID == 2) { mbs_data->user_IO->my_command++; }
void user_keyboard | ( | MbsData * | mbs_data, |
Simu_realtime * | realtime, | ||
int | cur_t_usec, | ||
const Uint8 * | keystates | ||
) |
handle inputs comming from the keyboard
[in,out] | mbs_data | Robotran main structure |
[in] | realtime | real-time structure |
[in] | cur_t_usec | curent time [us] |
[in] | keystates | state of the keys (from the keyboard) |
Use keystates'key code' to detect when the corresponding key is pressed and add your own functions according to the key pressed.
Call 'wait_key(realtime, cur_t_usec, time);' in the statement where you replace 'time' by a time in seconds if you want to wait before detecting a new user command. Pay attention, when you call 'wait_key', the program is automatically kept awake for a few seconds. Consequently, the process can not be realeased after a few seconds during a break in case 'wait_key' is always called.
example: if (keystates[SDL_SCANCODE_UP]) { mbs_data->user_IO->my_command++; wait_key(realtime, cur_t_usec, 0.1); } else if (keystates[SDL_SCANCODE_DOWN]) { mbs_data->user_IO->my_command–; wait_key(realtime, cur_t_usec, 0.1); }
void user_realtime_plot | ( | MbsData * | mbs_data | ) |
assign values for the SDL functions
[in] | mbs_data | Robotran main structure |
To plot a curve, use 'set_plot(value, label)' where 'value' is the value you want to plot and 'label' is a string corresponding to the curve label. You can use the 'set_plot' function in the following function ('user_realtime_plot') or anywhere in your code, provided you add the include '#include "user_realtime.h"' in the corresponding file. Using 'user_realtime_plot' is still useful to structure the code, avoiding to put the 'set_plot' function everywhere in the code. However, using 'set_plot' in other files can be faster and is especially relevant fot C++ code where some internal variables are private and cannot be used outside the corresponding class. To plot different curves, you must use different labels (otherwise, some curves won't be plotted).
example: set_plot(mbs_data->q[4], "q4 [rad]");
void wait_key | ( | Simu_realtime * | realtime, |
int | cur_t_usec, | ||
double | tsim | ||
) |