Robotran C Documentation
Macros | Functions
realtime.c File Reference
#include "realtime.h"
#include "time_functions.h"
#include "useful_functions.h"
#include "user_realtime.h"
#include "mbs_message.h"
#include "mbs_errors_names.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

Macros

#define USEC_TO_SEC   1.0e-6
 factor from us to s More...
 
#define DEFAULT_DELTA_T_USEC   (int) 1e5
 default time between 2 refresh moments (in us) More...
 
#define NB_REAL_TIME_CONSTRAINTS   2
 number of real-time constraints More...
 
#define REAL_TIME_SPEED_PERIOD_USEC   25e4
 real time speed factor computation time [s] More...
 
#define DEFAULT_MAX_MODELS   20
 default maximal numbers of models to load More...
 

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...
 
void mbs_realtime_update (Simu_realtime *realtime, double tsim)
 update save vectors for past investigations (graphs and Java visualization) More...
 
int mbs_realtime_loop (Simu_realtime *realtime, double tsim)
 one loop iteration of the real-time process More...
 
int mbs_realtime_finish (Simu_realtime *realtime)
 release memory used for the real-time related functions 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 *options)
 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 *options)
 automatically compute the buffer size More...
 
Realtime_constraintinit_realtime_constraint (int delta_t_usec, int cur_t_usec, double tsim)
 initialize one real-time constraint 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...
 
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_realtime_constraint (Realtime_constraint *constraint, int simu_speed_flag)
 update one real-time constraint More...
 
void update_simu_realtime (Simu_realtime *realtime)
 update the structure of all the constraints 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...
 
void update_realtime_constraints_break (Simu_realtime *realtime, int delta_break_u_sec)
 update the real-time constraints after a break More...
 

Macro Definition Documentation

◆ DEFAULT_DELTA_T_USEC

#define DEFAULT_DELTA_T_USEC   (int) 1e5

default time between 2 refresh moments (in us)

◆ DEFAULT_MAX_MODELS

#define DEFAULT_MAX_MODELS   20

default maximal numbers of models to load

◆ NB_REAL_TIME_CONSTRAINTS

#define NB_REAL_TIME_CONSTRAINTS   2

number of real-time constraints

◆ REAL_TIME_SPEED_PERIOD_USEC

#define REAL_TIME_SPEED_PERIOD_USEC   25e4

real time speed factor computation time [s]

◆ USEC_TO_SEC

#define USEC_TO_SEC   1.0e-6

factor from us to s

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