Robotran C Documentation
realtime.h
Go to the documentation of this file.
1 
7 #ifdef REAL_TIME
8 
9 #ifndef _REAL_TIME_H_
10 #define _REAL_TIME_H_
11 
12 #include "realtime_ext.h"
13 #include "color_sdl.h"
14 #include "mbs_data.h"
15 
16 #include "mbs_project_fct_ptr.h"
17 
18 // back in visualization period
19 #define PERIOD_BACK_IN_VISU 0.03 // [s]
20 #define INTERRUPT_BACK_IN_VISU 0.25 // [s]
21 
22 // -- Structures -- //
23 
26 typedef struct Realtime_extern
27 {
28  #ifdef SDL
29  Realtime_sdl *sdl;
30  #endif
31 
32  #ifdef VISU_3D
33  Realtime_visu *visu;
34  #endif
35 
37 
39 
43 {
44  // simulation
45  double t0;
46  double tf;
47  double dt0;
48 
49  // general
50  int init_break;
52 
54 
56 
57  // SDL plots and interactions
58  int flag_plot;
59 
63 
66 
67  double y_min_init;
68  double y_max_init;
69 
71 
72  double fqc_screen;
73 
74  // Java visualization
75  int flag_visu;
76 
77  int nb_models;
78  int *nb_q;
79  char **mbs_file;
80 
82 
83  double fqc_visu;
84 
85 };
86 
89 typedef struct Realtime_constraint
90 {
93  double next_tsim;
94 
96 
100 {
101  // flags
102  int simu_quit;
107 
108  // speed factors
111 
112  // time
113  double last_tsim;
114  double tsim;
115 
116  double t0;
117  double tf;
118 
120 
121  // initial time
124 
125  // last time
128 
129  // constraints
131 
132  // gates
134  double next_tsim_gate;
135 
136  int flag_plot;
137  int flag_visu;
138 
140 
142 
144 
146 
147 };
148 
149 // -- Functions prototypes -- //
150 
151 #ifdef __cplusplus
152 extern "C" {
153 #endif
154  void mbs_realtime_reset();
155  int mbs_realtime_init(MbsData* mbs_data, double t0, double tf, double dt0);
156  int mbs_realtime_loop(Simu_realtime *realtime, double tsim);
157  void mbs_realtime_update(Simu_realtime *realtime, double tsim);
158  int mbs_realtime_finish(Simu_realtime *realtime);
159 #ifdef __cplusplus
160 }
161 #endif
162 
163 Simu_realtime* init_realtime(MbsData* mbs_data, Realtime_option *options, int *err);
164 Simu_realtime* init_simu_realtime(MbsData* mbs_data, Realtime_option *options, int nb_constraints, double *fqc_tab, int *err);
165 Realtime_constraint* init_realtime_constraint(int delta_t_usec, int cur_t_usec, double tsim);
167 int free_simu_realtime(Simu_realtime *realtime);
168 void update_simu_realtime(Simu_realtime *realtime);
169 void update_realtime_constraint(Realtime_constraint *constraint, int simu_speed_flag);
170 void update_realtime_constraints_break(Simu_realtime *realtime, int delta_break_u_sec);
171 double get_simu_speed_factor(int simu_speed_flag);
172 int get_simu_speed_flag(double simu_speed_factor);
173 
178 
179 #ifdef __cplusplus
180 extern "C" {
181 #endif
182  void user_realtime_options(MbsData* mbs_data, Realtime_option *options);
183 #ifdef __cplusplus
184 }
185 #endif
186 
187 #endif
188 #endif
visu_past.h
functions used to go backward or forward in the simulation time for visualization
Realtime_constraint::next_tsim
double next_tsim
next gate to wait for simulation time [s]
Definition: realtime.h:93
Simu_realtime::real_simu_speed_factor
double real_simu_speed_factor
real speed factor
Definition: realtime.h:109
LIGHT_GREEN_SDL
@ LIGHT_GREEN_SDL
Definition: color_sdl.h:19
Simu_realtime::simu_break
int simu_break
1 to make a break, 0 otherwise
Definition: realtime.h:103
Realtime_option
user real-time option
Definition: realtime.h:42
Simu_realtime::options
Realtime_option * options
user options
Definition: realtime.h:145
Realtime_option::dt0
double dt0
simulation time step [s]
Definition: realtime.h:47
Realtime_option::tf
double tf
final simulation time [s]
Definition: realtime.h:46
Realtime_option::screen_width
int screen_width
plot screen width in number of pixels
Definition: realtime.h:61
USEC_TO_SEC
#define USEC_TO_SEC
factor from us to s
Definition: realtime.c:34
Realtime_option::max_nb_legends
int max_nb_legends
maximum number of curves legends indicated
Definition: realtime.h:65
get_simu_speed_flag
int get_simu_speed_flag(double simu_speed_factor)
get the 'simu_speed_flag' flag depending on simulation factor
Definition: realtime.c:924
useful_functions.h
init_realtime_constraint
Realtime_constraint * init_realtime_constraint(int delta_t_usec, int cur_t_usec, double tsim)
initialize one real-time constraint
Definition: realtime.c:544
BLUE_SDL
@ BLUE_SDL
Definition: color_sdl.h:18
MbsData::mbs_filename
char * mbs_filename
Path to mbs file including the file with the extension (.mbs)
Definition: mbs_data.h:310
mbs_project_fct_ptr.h
LIGHT_BLUE_SDL
@ LIGHT_BLUE_SDL
Definition: color_sdl.h:19
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
Definition: realtime.c:429
user_realtime_options
void user_realtime_options(MbsData *mbs_data, Realtime_option *options)
modify the real-time options
Definition: user_realtime_options.c:85
mbs_data.h
Simu_realtime::buffer_size
int buffer_size
size of the buffer for 3D and sdl
Definition: realtime.h:119
update_realtime_constraint
void update_realtime_constraint(Realtime_constraint *constraint, int simu_speed_flag)
update one real-time constraint
Definition: realtime.c:841
init_realtime
Simu_realtime * init_realtime(MbsData *mbs_data, Realtime_option *options, int *err)
initialize the real-time structure
Definition: realtime.c:569
MbsData::njoint
int njoint
Number of joints in the system.
Definition: mbs_data.h:162
Realtime_constraint::next_t_usec
int next_t_usec
next gate to wait for real time [us]
Definition: realtime.h:92
mbs_realtime_update
void mbs_realtime_update(Simu_realtime *realtime, double tsim)
update save vectors for past investigations (graphs and Java visualization)
Definition: realtime.c:113
Simu_realtime::init_t_sec
int init_t_sec
initial real time [s], without us
Definition: realtime.h:122
time_get
void time_get(int *t_sec, int *t_usec)
return the absolute time of the computer
Definition: time_functions.c:11
java_functions.h
Java functions used for the visualization.
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
Definition: realtime.c:952
Simu_realtime::last_break
int last_break
1 to indicate last break, 0 otherwise
Definition: realtime.h:104
Simu_realtime::simu_quit
int simu_quit
1 to quit the simulation, 0 otherwise
Definition: realtime.h:102
DARK_GREEN_SDL
@ DARK_GREEN_SDL
Definition: color_sdl.h:18
free_realtime_constraint
void free_realtime_constraint(Realtime_constraint *constraint)
free one real-time constraint
Definition: realtime.c:785
_MBS_ERR_INIT
#define _MBS_ERR_INIT
Generic error number Check user options at initialization = -10.
Definition: mbs_errors_names.h:156
Simu_realtime::last_real_simu_speed_factor
double last_real_simu_speed_factor
last real speed factor
Definition: realtime.h:110
PINK_SDL
@ PINK_SDL
Definition: color_sdl.h:19
TURQUOISE_SDL
@ TURQUOISE_SDL
Definition: color_sdl.h:18
Realtime_constraint::delta_t_usec
int delta_t_usec
delta time between to gates for real time [us]
Definition: realtime.h:91
realtime_ext.h
Real-time constraints header for external modules.
NB_COLORS_SDL
#define NB_COLORS_SDL
number of colors available to the user
Definition: color_sdl.h:12
mbs_realtime_update
void mbs_realtime_update(Simu_realtime *realtime, double tsim)
update save vectors for past investigations (graphs and Java visualization)
Definition: realtime.c:113
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
Definition: realtime.c:429
Simu_realtime::t0
double t0
initial simulation time [s]
Definition: realtime.h:116
mbs_realtime_finish
int mbs_realtime_finish(Simu_realtime *realtime)
release memory used for the real-time related functions
Definition: realtime.c:307
mbs_realtime_loop
int mbs_realtime_loop(Simu_realtime *realtime, double tsim)
one loop iteration of the real-time process
Definition: realtime.c:139
GREEN_SDL
@ GREEN_SDL
Definition: color_sdl.h:19
update_realtime_constraint
void update_realtime_constraint(Realtime_constraint *constraint, int simu_speed_flag)
update one real-time constraint
Definition: realtime.c:841
set_plot.h
set_plot function called by the user to plot a curve
init_Realtime_option
Realtime_option * init_Realtime_option(MbsData *mbs_data)
generates a real-time options structures with the default values
Definition: realtime.c:331
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
Definition: realtime.c:594
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
Definition: realtime.c:952
mbs_msg
void mbs_msg(char *msg,...)
Send a message.
Definition: mbs_message.c:76
Realtime_option::y_max_init
double y_max_init
initial upper bound for the y values plotted
Definition: realtime.h:68
Simu_realtime::ext
Realtime_extern * ext
external variables
Definition: realtime.h:143
plot_sdl.h
main SDL functions (plot curves and handles keyboard, joystick... inputs)
mbs_realtime_init
int mbs_realtime_init(MbsData *mbs_data, double t0, double tf, double dt0)
initialize the real-time structures
Definition: realtime.c:61
YELLOW_SDL
@ YELLOW_SDL
Definition: color_sdl.h:19
NB_REAL_TIME_CONSTRAINTS
#define NB_REAL_TIME_CONSTRAINTS
number of real-time constraints
Definition: realtime.c:36
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
Definition: realtime.c:594
Realtime_option::nb_models
int nb_models
number of models to load
Definition: realtime.h:77
Simu_realtime::tf
double tf
final simulation time [s]
Definition: realtime.h:117
Simu_realtime::constraints
Realtime_constraint ** constraints
structures of multiple real-time constraints
Definition: realtime.h:141
Realtime_option::fqc_visu
double fqc_visu
frequence of the 3D visualization refreshment [Hz]
Definition: realtime.h:83
time_functions.h
functions used to get the time expressed in us (micro seconds)
compute_buffer_size
void compute_buffer_size(Realtime_option *options)
automatically compute the buffer size
Definition: realtime.c:530
DEFAULT_DELTA_T_USEC
#define DEFAULT_DELTA_T_USEC
default time between 2 refresh moments (in us)
Definition: realtime.c:35
Realtime_option::y_min_init
double y_min_init
initial lower bound for the y values plotted
Definition: realtime.h:67
DARK_YELLOW_SDL
@ DARK_YELLOW_SDL
Definition: color_sdl.h:19
free_realtime_constraint
void free_realtime_constraint(Realtime_constraint *constraint)
free one real-time constraint
Definition: realtime.c:785
ORANGE_SDL
@ ORANGE_SDL
Definition: color_sdl.h:19
Realtime_constraint
one constraint strcuture
Definition: realtime.h:89
Realtime_option::curve_width
int curve_width
plot curve width in number of pixels
Definition: realtime.h:60
mbs_realtime_init
int mbs_realtime_init(MbsData *mbs_data, double t0, double tf, double dt0)
initialize the real-time structures
Definition: realtime.c:61
Simu_realtime::flag_plot
int flag_plot
1 if SDL plots features activated, 0 otherwise
Definition: realtime.h:136
init_realtime
Simu_realtime * init_realtime(MbsData *mbs_data, Realtime_option *options, int *err)
initialize the real-time structure
Definition: realtime.c:569
t_usec
int t_usec(int init_t_sec, int init_t_usec)
return the elapsed time (in us) since time 'init_t' (expressed in s and us)
Definition: time_functions.c:25
RED_SDL
@ RED_SDL
Definition: color_sdl.h:18
Simu_realtime::no_additional_constraint
int no_additional_constraint
1 if additional constraint, 0 otherwise
Definition: realtime.h:106
open_gl_c_int.h
interface to call C++ functions from C code
free_simu_realtime
int free_simu_realtime(Simu_realtime *realtime)
free the structure of all the real-time constraints
Definition: realtime.c:795
update_simu_realtime
void update_simu_realtime(Simu_realtime *realtime)
update the structure of all the constraints
Definition: realtime.c:860
mbs_realtime_loop
int mbs_realtime_loop(Simu_realtime *realtime, double tsim)
one loop iteration of the real-time process
Definition: realtime.c:139
Simu_realtime::tsim
double tsim
current simulation time [s]
Definition: realtime.h:114
Realtime_option::final_break
int final_break
1 to finish with a break, 0 otherwise
Definition: realtime.h:51
Simu_realtime::speed_last_tsim
double speed_last_tsim
last simulation time [s], to compute the simulation speed
Definition: realtime.h:127
get_simu_speed_factor
double get_simu_speed_factor(int simu_speed_flag)
get simulation factor depending on the 'simu_speed_flag' flag
Definition: realtime.c:903
mbs_message.h
Simu_realtime::next_tsim_gate
double next_tsim_gate
next gate to wait for simulation time [s]
Definition: realtime.h:134
MbsData::realtime
void * realtime
Pointer to Simu_realtime structure.
Definition: mbs_data.h:322
REAL_TIME_SPEED_PERIOD_USEC
#define REAL_TIME_SPEED_PERIOD_USEC
real time speed factor computation time [s]
Definition: realtime.c:37
Realtime_option::flag_visu
int flag_visu
1 if Java visualization features activated, 0 otherwise
Definition: realtime.h:75
color_sdl.h
colors description, used for the SDL plots
Simu_realtime::next_t_usec_gate
int next_t_usec_gate
next gate to wait for real time [us]
Definition: realtime.h:133
user_realtime_options
void user_realtime_options(MbsData *mbs_data, Realtime_option *options)
modify the real-time options
Definition: user_realtime_options.c:85
Realtime_option::mbs_file
char ** mbs_file
path and file name fot the .mbs file used for Java visualization (for each model)
Definition: realtime.h:79
Simu_realtime::first_break
int first_break
1 if during the first break, 0 otherwise
Definition: realtime.h:139
Realtime_option::init_break
int init_break
1 to start with a break, 0 otherwise
Definition: realtime.h:50
init_realtime_constraint
Realtime_constraint * init_realtime_constraint(int delta_t_usec, int cur_t_usec, double tsim)
initialize one real-time constraint
Definition: realtime.c:544
Realtime_option::buffer_size
int buffer_size
size of the buffer for 3D and sdl
Definition: realtime.h:53
Realtime_extern
external variables and stuctures
Definition: realtime.h:26
MbsData
Definition: mbs_data.h:149
realtime.h
Real-time constraints main header.
Simu_realtime
real-time structure
Definition: realtime.h:99
Realtime_option::nb_q
int * nb_q
number of joints in the .mbs used for visualization (for each model)
Definition: realtime.h:78
free_simu_realtime
int free_simu_realtime(Simu_realtime *realtime)
free the structure of all the real-time constraints
Definition: realtime.c:795
update_simu_realtime
void update_simu_realtime(Simu_realtime *realtime)
update the structure of all the constraints
Definition: realtime.c:860
Realtime_option::t0
double t0
initial simulation time [s]
Definition: realtime.h:45
Realtime_option::screen_height
int screen_height
plot screen height in number of pixels
Definition: realtime.h:62
Realtime_extern::mbs_data
MbsData * mbs_data
Robotran main structure.
Definition: realtime.h:36
Realtime_option::max_nb_curves
int max_nb_curves
maximum number of curves plotted
Definition: realtime.h:64
Simu_realtime::speed_last_t_usec
int speed_last_t_usec
last real time [us], to compute the simulation speed
Definition: realtime.h:126
mbs_realtime_finish
int mbs_realtime_finish(Simu_realtime *realtime)
release memory used for the real-time related functions
Definition: realtime.c:307
free_Realtime_option
void free_Realtime_option(Realtime_option *option)
release memory for the options structure
Definition: realtime.c:416
Realtime_option::flag_plot
int flag_plot
1 if SDL plots features activated, 0 otherwise
Definition: realtime.h:58
Simu_realtime::simu_speed_flag
int simu_speed_flag
used to compute the simulation factor
Definition: realtime.h:105
pow_int
double pow_int(double basis, int expo)
compute efficiently pow with an integer exponent
Definition: useful_functions.c:60
Realtime_option::init_speed_factor
double init_speed_factor
initial speed factor
Definition: realtime.h:55
free_Realtime_option
void free_Realtime_option(Realtime_option *options)
release memory for the options structure
Definition: realtime.c:416
compute_buffer_size
void compute_buffer_size(Realtime_option *option)
automatically compute the buffer size
Definition: realtime.c:530
PURPLE_SDL
@ PURPLE_SDL
Definition: color_sdl.h:18
get_simu_speed_factor
double get_simu_speed_factor(int simu_speed_flag)
get simulation factor depending on the 'simu_speed_flag' flag
Definition: realtime.c:903
Simu_realtime::init_t_usec
int init_t_usec
initial real time [us], without s (kind of modulo)
Definition: realtime.h:123
Realtime_option::fqc_screen
double fqc_screen
frequence of the SDL plots refreshment [Hz]
Definition: realtime.h:72
user_realtime.h
DEFAULT_MAX_MODELS
#define DEFAULT_MAX_MODELS
default maximal numbers of models to load
Definition: realtime.c:38
Simu_realtime::flag_visu
int flag_visu
1 if Java visualization features activated, 0 otherwise
Definition: realtime.h:137
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...
Definition: realtime.c:44
Simu_realtime::nb_constraints
int nb_constraints
number of real-time constraints
Definition: realtime.h:130
mbs_warning_msg
void mbs_warning_msg(char *msg,...)
Send a warning message.
Definition: mbs_message.c:89
get_simu_speed_flag
int get_simu_speed_flag(double simu_speed_factor)
get the 'simu_speed_flag' flag depending on simulation factor
Definition: realtime.c:924
Simu_realtime::last_tsim
double last_tsim
last simulation time [s]
Definition: realtime.h:113
Realtime_option::color_tab
int color_tab[NB_COLORS_SDL]
colors of the curves
Definition: realtime.h:70
Realtime_option::start_viewpoint
int start_viewpoint
initial visu viewpoint ID
Definition: realtime.h:81
mbs_errors_names.h
init_Realtime_option
Realtime_option * init_Realtime_option(MbsData *mbs_data)
generates a real-time options structures with the default values
Definition: realtime.c:331
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...
Definition: realtime.c:44