Commit 6818edae authored by Nicolas Van der Noot's avatar Nicolas Van der Noot
Browse files

correct real-time t!=0

parent ed529504
......@@ -69,15 +69,13 @@ int main(int argc, char const *argv[])
mbs_dirdyn->options->save2file = 1;
mbs_dirdyn->options->respath = PROJECT_SOURCE_DIR"/../resultsR";
mbs_dirdyn->options->adapt_time_step = 1;
mbs_dirdyn->options->adapt_rtoler = 1.0e-14;
mbs_dirdyn->options->adapt_atoler = 1.0e-14;
mbs_dirdyn->options->adapt_dt_max = 0.001;
mbs_dirdyn->options->adapt_verbose = 1;
//mbs_dirdyn->options->realtime = 1;
mbs_dirdyn->options->realtime = 1;
mbs_run_dirdyn(mbs_dirdyn, mbs_data);
......
......@@ -141,7 +141,7 @@ void mbs_dirdyn_init(MbsDirdyn* dd, MbsData* mbs_data){
#ifdef REAL_TIME
if (dd->options->realtime)
{
mbs_realtime_init(mbs_data, dd->options->dt0, dd->options->tf);
mbs_realtime_init(mbs_data, dd->options->t0, dd->options->tf, dd->options->dt0);
}
#else
if (dd->options->realtime)
......@@ -254,6 +254,7 @@ void mbs_dirdyn_loop(MbsDirdyn* dd, MbsData* mbs_data){
FILE *fileout_dopri5;
int i;
double **dopri5_alloc_tab;
double cur_t0, cur_tf;
// NUMERICAL INTEGRATION
// - - - - - - - - - - -
......@@ -277,7 +278,10 @@ void mbs_dirdyn_loop(MbsDirdyn* dd, MbsData* mbs_data){
dopri5_alloc_tab[i] = (double*) malloc (dd->nState*sizeof(double));
}
dopri5(dd->nState, mbs_fct_dirdyn, dd->options->t0, dd->y, dd->options->tf, &(dd->options->adapt_rtoler), &(dd->options->adapt_atoler),
cur_t0 = dd->options->t0;
cur_tf = dd->options->tf;
dopri5(dd->nState, mbs_fct_dirdyn, cur_t0, dd->y, cur_tf, &(dd->options->adapt_rtoler), &(dd->options->adapt_atoler),
0, solout_dopri5, 1, fileout_dopri5, 0.0, 0.0, 0.0, 0.0, 0.0, dd->options->adapt_dt_max, dd->options->dt0, dd->options->adapt_nmax,
1, 0, 0, NULL, 0, dopri5_alloc_tab, mbs_data, dd);
......@@ -428,7 +432,7 @@ void mbs_fct_dirdyn(double tsim, double y[], double dydt[], MbsData *s, MbsDirdy
*/
void save_realtime_update(MbsDirdyn* dd, MbsData* mbs_data)
{
#ifdef REAL_TIME
#ifdef REAL_TIME
Simu_realtime *realtime;
#endif
......
......@@ -29,10 +29,11 @@
/*! \brief initialize the real-time structures
*
* \param[in,out] mbs_data Robotran main structure
* \param[in] dt0 intitial time step [s]
* \param[in] t0 initial time [s]
* \param[in] tf final time [s]
* \param[in] dt0 intitial time step [s]
*/
void mbs_realtime_init(MbsData* mbs_data, double dt0, double tf)
void mbs_realtime_init(MbsData* mbs_data, double t0, double tf, double dt0)
{
// -- variables declaration -- //
Simu_realtime *realtime;
......@@ -41,6 +42,7 @@ void mbs_realtime_init(MbsData* mbs_data, double dt0, double tf)
options = init_Realtime_option(mbs_data);
// options determined by the simulation
options->t0 = t0;
options->tf = tf;
options->dt0 = dt0;
options->nb_q = mbs_data->njoint;
......
......@@ -149,7 +149,7 @@ typedef struct Simu_realtime
#ifdef __cplusplus
extern "C" {
#endif
void mbs_realtime_init(MbsData* mbs_data, double dt0, double tf);
void mbs_realtime_init(MbsData* mbs_data, double t0, double tf, double dt0);
void mbs_realtime_loop(Simu_realtime *realtime, double tsim);
void mbs_realtime_update(Simu_realtime *realtime, double tsim);
void mbs_realtime_finish(Simu_realtime *realtime);
......
......@@ -1818,6 +1818,14 @@ int str_label(char *str, double low_nb, double high_nb)
// string computation
diff_nb = fabs(high_nb - low_nb);
// numerical safety
if (fabs(diff_nb) < STR_LABEL_MIN)
{
sprintf(str,"[%.2f ; %.2f]", low_nb, high_nb );
return 0;
}
exp_inf = expo_ten_inf(diff_nb);
div_exp = pow_int(10.0, exp_inf);
......@@ -2466,7 +2474,6 @@ void plot_screen_sdl(Simu_realtime *realtime, double tsim, int screen_flag)
screen_sdl->last_plot_auto_scaling = screen_sdl->plot_auto_scaling;
// x label range
// corresponding index
......
......@@ -92,6 +92,8 @@
#define Y_LABEL_SHIFT_Y_START (Y_LABEL_SHIFT_Y + 9)
#define Y_LABEL_SHIFT_Y_END (Y_LABEL_SHIFT_Y - 10)
#define STR_LABEL_MIN 1.0e-9
// scaling
#define PLOT_SCALE_MAX 4.0
#define SCALING_MULT_THRESHOLD 4.0
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment