Robotran C Documentation
Classes | Macros | Functions
realtime.h File Reference

Real-time constraints main header. More...

#include "realtime_ext.h"
#include "color_sdl.h"
#include "mbs_data.h"
#include "mbs_project_fct_ptr.h"

Go to the source code of this file.

Classes

struct  Realtime_extern
 external variables and stuctures More...
 
struct  Realtime_option
 user real-time option More...
 
struct  Realtime_constraint
 one constraint strcuture More...
 
struct  Simu_realtime
 real-time structure More...
 

Macros

#define PERIOD_BACK_IN_VISU   0.03
 
#define INTERRUPT_BACK_IN_VISU   0.25
 

Functions

void mbs_realtime_reset ()
 reset the realtime structures and flag. Useful in case we want to run several simulations in a row in the same process. More...
 
int mbs_realtime_init (MbsData *mbs_data, double t0, double tf, double dt0)
 initialize the real-time structures More...
 
int mbs_realtime_loop (Simu_realtime *realtime, double tsim)
 one loop iteration of the real-time process More...
 
void mbs_realtime_update (Simu_realtime *realtime, double tsim)
 update save vectors for past investigations (graphs and Java visualization) More...
 
int mbs_realtime_finish (Simu_realtime *realtime)
 release memory used for the real-time related functions More...
 
Simu_realtimeinit_realtime (MbsData *mbs_data, Realtime_option *options, int *err)
 initialize the real-time structure More...
 
Simu_realtimeinit_simu_realtime (MbsData *mbs_data, Realtime_option *options, int nb_constraints, double *fqc_tab, int *err)
 initialize the structure with all the real-time constraints More...
 
Realtime_constraintinit_realtime_constraint (int delta_t_usec, int cur_t_usec, double tsim)
 initialize one real-time constraint More...
 
void free_realtime_constraint (Realtime_constraint *constraint)
 free one real-time constraint More...
 
int free_simu_realtime (Simu_realtime *realtime)
 free the structure of all the real-time constraints More...
 
void update_simu_realtime (Simu_realtime *realtime)
 update the structure of all the constraints More...
 
void update_realtime_constraint (Realtime_constraint *constraint, int simu_speed_flag)
 update one real-time constraint More...
 
void update_realtime_constraints_break (Simu_realtime *realtime, int delta_break_u_sec)
 update the real-time constraints after a break More...
 
double get_simu_speed_factor (int simu_speed_flag)
 get simulation factor depending on the 'simu_speed_flag' flag More...
 
int get_simu_speed_flag (double simu_speed_factor)
 get the 'simu_speed_flag' flag depending on simulation factor More...
 
Realtime_optioninit_Realtime_option (MbsData *mbs_data)
 generates a real-time options structures with the default values More...
 
void free_Realtime_option (Realtime_option *option)
 release memory for the options structure More...
 
int check_user_realtime_options (Realtime_option *options)
 check that the modifications performed by the user on the options are correct More...
 
void compute_buffer_size (Realtime_option *option)
 automatically compute the buffer size More...
 
void user_realtime_options (MbsData *mbs_data, Realtime_option *options)
 modify the real-time options More...
 

Detailed Description

Real-time constraints main header.

Author
Nicolas Van der Noot

Macro Definition Documentation

◆ INTERRUPT_BACK_IN_VISU

#define INTERRUPT_BACK_IN_VISU   0.25

◆ PERIOD_BACK_IN_VISU

#define PERIOD_BACK_IN_VISU   0.03

Function Documentation

◆ check_user_realtime_options()

int check_user_realtime_options ( Realtime_option options)

check that the modifications performed by the user on the options are correct

Parameters
[in,out]optionsoptions structure
Returns
Error status, <0 in case of failure.

◆ compute_buffer_size()

void compute_buffer_size ( Realtime_option options)

automatically compute the buffer size

Parameters
[in,out]optionsoptions structure

◆ free_realtime_constraint()

void free_realtime_constraint ( Realtime_constraint constraint)

free one real-time constraint

Parameters
[out]constraintconstraint to release memory

◆ free_Realtime_option()

void free_Realtime_option ( Realtime_option options)

release memory for the options structure

Parameters
[out]optionsoptions structure

◆ free_simu_realtime()

int free_simu_realtime ( Simu_realtime realtime)

free the structure of all the real-time constraints

Parameters
[out]realtimereal-time structure to release memory
Returns
Error status, <0 in case of failure.

◆ get_simu_speed_factor()

double get_simu_speed_factor ( int  simu_speed_flag)

get simulation factor depending on the 'simu_speed_flag' flag

Parameters
[in]simu_speed_flagindex used to compute the speed factor
Returns
speed factor

◆ get_simu_speed_flag()

int get_simu_speed_flag ( double  simu_speed_factor)

get the 'simu_speed_flag' flag depending on simulation factor

Parameters
[in]simu_speed_factorspeed factor
Returns
index used to compute the speed factor

◆ init_realtime()

Simu_realtime* init_realtime ( MbsData mbs_data,
Realtime_option options,
int *  err 
)

initialize the real-time structure

Parameters
[in,out]mbs_dataRobotran main structure
[in]optionsoptions structure
[in,out]err<0 if error occurs
Returns
real-time structure initialized

◆ init_realtime_constraint()

Realtime_constraint* init_realtime_constraint ( int  delta_t_usec,
int  cur_t_usec,
double  tsim 
)

initialize one real-time constraint

Parameters
[in]delta_t_usectime step for this constraint [us]
[in]cur_t_useccurrent time (real-time) [us]
[in]tsimcurrent simulation time [s]

◆ init_Realtime_option()

Realtime_option* init_Realtime_option ( MbsData mbs_data)

generates a real-time options structures with the default values

Returns
requested real-time options structure

< initial simulation time [s]

< final simulation time [s]

< simulation time step [s]

< 1 to start with a break, 0 otherwise

< 1 to finish with a break, 0 otherwise

< size of the buffer for 3D visu and sdl

< initial speed factor

< 1 if SDL plots features activated, 0 otherwise

< plot curve width in number of pixels

< plot screen width in number of pixels

< plot screen height in number of pixels

< maximum number of curves plotted

< maximum number of curves legends indicated

< initial lower bound for the y values plotted

< initial upper bound for the y values plotted

< frequence of the SDL plots refreshment [Hz]

< 1 if Java visualization features activated, 0 otherwise

< number of models to load

< initial visu viewpoint ID

< frequence of the 3D visualization refreshment [Hz]

◆ init_simu_realtime()

Simu_realtime* init_simu_realtime ( MbsData mbs_data,
Realtime_option options,
int  nb_constraints,
double *  fqc_tab,
int *  err 
)

initialize the structure with all the real-time constraints

Parameters
[in,out]mbs_dataRobotran main structure
[in]optionsoptions structure
[in]nb_constraintsnumber of real-time constraints
[in]fqc_tabtabular with the constraints freqeuncies
[in,out]err<0 if error occurs
Returns
real-time structure initialized

◆ mbs_realtime_finish()

int mbs_realtime_finish ( Simu_realtime realtime)

release memory used for the real-time related functions

Parameters
[out]realtimereal-time structure to release memory
Returns
Error status, <0 in case of failure.

◆ mbs_realtime_init()

int mbs_realtime_init ( MbsData mbs_data,
double  t0,
double  tf,
double  dt0 
)

initialize the real-time structures

Parameters
[in,out]mbs_dataRobotran main structure
[in]t0initial time [s]
[in]tffinal time [s]
[in]dt0intitial time step [s]
Returns
Error status, <0 in case of failure.

◆ mbs_realtime_loop()

int mbs_realtime_loop ( Simu_realtime realtime,
double  tsim 
)

one loop iteration of the real-time process

Parameters
[in,out]realtimereal-time structure
[in]tsimcurrent simulation time [s]
Returns
Error status, <0 in case of failure.

◆ mbs_realtime_reset()

void mbs_realtime_reset ( )

reset the realtime structures and flag. Useful in case we want to run several simulations in a row in the same process.

◆ mbs_realtime_update()

void mbs_realtime_update ( Simu_realtime realtime,
double  tsim 
)

update save vectors for past investigations (graphs and Java visualization)

Parameters
[in,out]realtimereal-time structure
[in]tsimcurrent simulation time [s]

◆ update_realtime_constraint()

void update_realtime_constraint ( Realtime_constraint constraint,
int  simu_speed_flag 
)

update one real-time constraint

Parameters
[in]constraintreal-time constraint
[in]simu_speed_flagindex used to compute the speed factor

◆ update_realtime_constraints_break()

void update_realtime_constraints_break ( Simu_realtime realtime,
int  delta_break_u_sec 
)

update the real-time constraints after a break

Parameters
[in,out]realtimereal-time structure
[in]delta_break_u_secdelta of time for next gate [us]

◆ update_simu_realtime()

void update_simu_realtime ( Simu_realtime realtime)

update the structure of all the constraints

Parameters
[in,out]realtimereal-time structure

◆ user_realtime_options()

void user_realtime_options ( MbsData mbs_data,
Realtime_option options 
)

modify the real-time options

Parameters
[in]mbs_dataRobotran main structure
[out]optionsreal-time options

These are the options that the user can configure:

  • Simulation options
    • options->t0: initial simulation time s
    • options->tf: final simulation time [s] (default: mbs_dirdyn->options->tf)
    • options->dt0: simulation time step [s] (default: mbs_dirdyn->options->dt0)
    • options->buffer_size: size of the buffer for 3D visualization and sdl (default: -1). This size corresponds to the number of time steps saved to analyze what happened back in time. When the buffers are full, they erase the oldest values with the new ones (rotating buffer). If you put a value <= 0, the size is automatically computed so that the buffer is big enough for the whole simulation.
    • options->init_speed_factor: initial speed factor (default: 1.0) For speed factors equal or higher than one, this factor should be an integer. For speed factors in ]0;1[, this factor is set as 2^x, where x is a negative integer. So, if your factor does not match these requirements, it will be rounded to fulfill them. Note: there is a minimal speed factor value related to the simulation time step and to the refreshment rate of the plots and the visualization. min speed factor = mbs_dirdyn->options->dt0 * max(options->fqc_screen, options->fqc_visu) Modify these options for very slow motions.
  • SDL plots options
    • options->flag_plot: 1 to activate SDL plots features (and keyboard/joystick interactions), 0 otherwise (default: 1)
    • options->curve_width: curves width in number of pixels (default: 3)
    • options->screen_width: plot screen width in number of pixels (default: 660)
    • options->screen_height: plot screen height in number of pixels (default: 520) For 'screen_width' and 'screen_height', pay attention that the plot layout was optimized for a size of 660x520. Consequently, layout could be deteriorated in some cases if you modify it, especially when you decrease these values.
    • options->max_nb_curves: maximum number of curves plotted (default: 12)
    • options->max_nb_legends: maximum number of curves legends indicated (default: 6)
    • options->y_min_init: initial lower bound for the y values plotted (default: -1.0)
    • options->y_max_init: initial upper bound for the y values plotted (default: 1.0)
    • options->init_break: 1 to start with a break, 0 otherwise (default: 0)
    • options->final_break: 1 to finish with a break, 0 otherwise (default: 0)
    • options->color_tab[i]: colors of the curves (default: 0:BLUE_SDL, 1:RED_SDL, 2:DARK_GREEN_SDL, 3:PURPLE_SDL, 4:ORANGE_SDL, 5:LIGHT_BLUE_SDL, 6:PINK_SDL, 7:TURQUOISE_SDL, 8:LIGHT_GREEN_SDL, 9: DARK_YELLOW_SDL, 10:YELLOW_SDL, 11:GREEN_SDL). You can modify some curve colors, replacing 'i' by a number between 0 and 11 (included). Use the colors listed in the default values. For instance: 'options->color_tab[0] = ORANGE_SDL;'. If you have more than 12 curves, the curve index modulo 12 is used to determine the colour.
    • options->fqc_screen: frequence of the SDL plots refreshment Hz This frequence also determines the speed of the moving cursor.
  • Java visualization options
    • options->flag_visu: 1 to activate Java visualization features, 0 otherwise (default: 1) Activating the Java visualization features might prevent you from using a debugger. Consequently, it is better to set this flag to 0 before entering in debugging mode. Also, when a seg fault appears in the code and the Java visualization features are activated, a Java error message will appear. This does not mean that the error is related to Java.
    • options->nb_models: number of .mbs models to load (default: 1)
    • options->nb_q[i]: number of joints in the .mbs files used for visualization of model i (see 'nb_models') (default: mbs_data->njoint for nb_q[0]; 0 for the others) 'nb_q' has a size of 20. If 'nb_models' is more than 20, you have to manually deallocate and reallocate it to a size of 'nb_models'.
    • options->mbs_file[i]: path and file name for the .mbs file used for Java visualization for model i (default: .mbs file indicated in workR, in 'mbs_load', for mbs_file[0]; NULL for the others) 'mbs_file' has a size of 20. If 'nb_models' is more than 20, you have to manually deallocate and reallocate it to a size of 'nb_models'.
    • options->start_viewpoint: initial visualization viewpoint ID, defined in the .mbs file (default: 0). Use -1 to start with the default viewpoint when opening MBSysPad.
    • options->fqc_visu: frequence of the 3D visualization refreshment Hz

example: options->y_min_init = 0.0; options->y_max_init = 10.0;