Robotran C Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Functions
user_realtime.h File Reference
#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...
 

Function Documentation

◆ set_plot()

void set_plot ( double  value,
char *  label 
)

function called by the user to plot a curve

Parameters
[in]valuecurrent value of the curve
[in]labellabel of the curve

◆ user_joystick_axes()

void user_joystick_axes ( MbsData mbs_data,
Simu_realtime realtime,
int  nb_joysticks 
)

handle inputs comming from joysticks axes

Parameters
[in,out]mbs_dataRobotran main structure
[in]realtimereal-time structure
[in]nb_joysticksnumber 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;

◆ user_joystick_buttons()

void user_joystick_buttons ( MbsData mbs_data,
int  buttonID 
)

handle inputs comming from joysticks buttons

Parameters
[in,out]mbs_dataRobotran main structure
[in]buttonIDID 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++; }

◆ user_keyboard()

void user_keyboard ( MbsData mbs_data,
Simu_realtime realtime,
int  cur_t_usec,
const Uint8 keystates 
)

handle inputs comming from the keyboard

Parameters
[in,out]mbs_dataRobotran main structure
[in]realtimereal-time structure
[in]cur_t_useccurent time [us]
[in]keystatesstate 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); }

◆ user_realtime_plot()

void user_realtime_plot ( MbsData mbs_data)

assign values for the SDL functions

Parameters
[in]mbs_dataRobotran 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]");

◆ wait_key()

void wait_key ( Simu_realtime realtime,
int  cur_t_usec,
double  tsim 
)