Commit 0501fae8 authored by Sébastien Timmermans's avatar Sébastien Timmermans
Browse files

[ErrMsg][Dirdyn] dirdyn.c management saving buffer

parent d8617e5c
......@@ -180,7 +180,7 @@ int mbs_run_dirdyn(MbsDirdyn* dd, MbsData* mbs_data)
// - - - - - - - - - - - -
err = mbs_dirdyn_finish(dd, mbs_data);
return 0;
return err;
}
int mbs_dirdyn_save(MbsDirdyn* dd, MbsData *mbs_data, double t) {
......@@ -200,8 +200,8 @@ int mbs_dirdyn_save(MbsDirdyn* dd, MbsData *mbs_data, double t) {
mbs_msg(">>DIRDYN>> ***** mbs_dirdyn_save : impossible to save the files *****\n");
mbs_msg(">>DIRDYN>> ***** during buffer save *****\n");
mbs_msg(">>DIRDYN>>\n");
mbs_error_msg("[%d] in mbs_fct_dirdyn !! \n", -400 + err);
return -400 + err;
mbs_error_msg("[%d] in mbs_fct_dirdyn !! \n", _MBS_ERR_MOD_DIRDYN + err);
return _MBS_ERR_MOD_DIRDYN + err;
}
err = mbs_growing_buffer_save(dd->user_buffer, t);
......@@ -211,8 +211,8 @@ int mbs_dirdyn_save(MbsDirdyn* dd, MbsData *mbs_data, double t) {
mbs_msg(">>DIRDYN>> ***** mbs_dirdyn_save : impossible to save the files *****\n");
mbs_msg(">>DIRDYN>> ***** during growing buffer save *****\n");
mbs_msg(">>DIRDYN>>\n");
mbs_error_msg("[%d] in mbs_fct_dirdyn !! \n", -400 + err);
return -400 + err;
mbs_error_msg("[%d] in mbs_fct_dirdyn !! \n", _MBS_ERR_MOD_DIRDYN + err);
return _MBS_ERR_MOD_DIRDYN + err;
}
if (dd->options->save_visu)
......@@ -232,8 +232,8 @@ int mbs_dirdyn_save(MbsDirdyn* dd, MbsData *mbs_data, double t) {
mbs_msg(">>DIRDYN>> ***** mbs_dirdyn_save : impossible to save the files *****\n");
mbs_msg(">>DIRDYN>> ***** during growing buffer save *****\n");
mbs_msg(">>DIRDYN>> in the REAL-TIME process \n");
mbs_error_msg("[%d] in mbs_fct_dirdyn !! \n", -400 + err);
exit(1);
mbs_error_msg("[%d] in mbs_fct_dirdyn !! \n", _MBS_ERR_MOD_DIRDYN + err);
return _MBS_ERR_MOD_DIRDYN + err;
}
#endif
}
......@@ -323,11 +323,18 @@ int mbs_dirdyn_init(MbsDirdyn* dd, MbsData* mbs_data)
#else
if (dd->options->realtime)
{
user_dirdyn_finish(mbs_data, dd);
free(f);
free(f_anim);
free(respath);
free(animpath);
free(fnameSuffix);
free(bufferIDs);
free(bufElemNb);
err = _MBS_ERR_INIT;
mbs_msg("\t >Real-time> To use the real-time features (mbs_dirdyn->options->realtime activated), set the CMake flag 'FLAG_REAL_TIME' to ON !\n");
mbs_error_msg("[%d] in mbs_dirdyn_init !! \n", -410);
return -410;
mbs_error_msg("[%d] in mbs_dirdyn_init !! \n", _MBS_ERR_MOD_DIRDYN + err);
return _MBS_ERR_MOD_DIRDYN + err;
}
#endif
......@@ -515,18 +522,34 @@ int mbs_dirdyn_init(MbsDirdyn* dd, MbsData* mbs_data)
#ifdef VISU_3D
if (!dd->options->realtime)
{
free(f);
free(f_anim);
free(respath);
free(animpath);
free(fnameSuffix);
free(bufferIDs);
free(bufElemNb);
mbs_msg("\t >Real-time> Error: real-time features must be activated to set 'save_visu' to 1 ! \n");
mbs_error_msg("[%d] in mbs_dirdyn_init !! \n", -410);
exit(1);
mbs_error_msg("[%d] in mbs_dirdyn_init !! \n", _MBS_ERR_MOD_DIRDYN + _MBS_ERR_INIT);
return _MBS_ERR_MOD_DIRDYN + _MBS_ERR_INIT;
}
realtime = (Simu_realtime*)mbs_data->realtime;
if (!realtime->options->flag_visu)
{
free(f);
free(f_anim);
free(respath);
free(animpath);
free(fnameSuffix);
free(bufferIDs);
free(bufElemNb);
mbs_msg("\t >Real-time> Error: flag_visu must be set to 1 to set 'save_value' to 1 ! \n");
mbs_error_msg("[%d] in mbs_dirdyn_init !! \n", -410);
exit(1);
mbs_error_msg("[%d] in mbs_dirdyn_init !! \n", _MBS_ERR_MOD_DIRDYN + _MBS_ERR_INIT);
return _MBS_ERR_MOD_DIRDYN + _MBS_ERR_INIT;
}
visu = realtime->ext->visu;
......@@ -541,8 +564,6 @@ int mbs_dirdyn_init(MbsDirdyn* dd, MbsData* mbs_data)
}
#else
user_dirdyn_finish(mbs_data, dd);
free(f);
free(f_anim);
free(respath);
......@@ -552,8 +573,8 @@ int mbs_dirdyn_init(MbsDirdyn* dd, MbsData* mbs_data)
free(bufElemNb);
mbs_msg("\t >Real-time> Error: Java libraries must be activated to set 'save_visu' to 1 ! \n");
mbs_error_msg("[%d] in mbs_dirdyn_init !! \n", -410);
return -410;
mbs_error_msg("[%d] in mbs_dirdyn_init !! \n", _MBS_ERR_MOD_DIRDYN + _MBS_ERR_INIT);
return _MBS_ERR_MOD_DIRDYN + _MBS_ERR_INIT;
#endif
}
......@@ -654,7 +675,7 @@ int mbs_dirdyn_loop(MbsDirdyn* dd, MbsData* mbs_data)
{
MbsDirdynOptions* opts;
double cur_t0, cur_tf;
int err = 0;
int err = 0, err2 =0;
opts = dd->options;
......@@ -676,9 +697,12 @@ int mbs_dirdyn_loop(MbsDirdyn* dd, MbsData* mbs_data)
if (err < 0){
err += _MBS_ERR_MOD_DIRDYN;
save_realtime_update(dd, mbs_data);
err2 = save_realtime_update(dd, mbs_data);
if (err2 < 0) {
mbs_msg("\t >Dirdyn> Error: in dirdyn loop during save realtime update ! \n");
}
mbs_error_msg(">>DIRDYN>> [%d] during direct dynamics loop.\n", err);
return err;
return (err<0)?err:err2;
}
// Update times
cur_t0 = cur_tf;
......@@ -749,6 +773,7 @@ int mbs_dirdyn_finish(MbsDirdyn* dd, MbsData* mbs_data) {
{
mbs_msg(">>DIRDYN>>\n");
mbs_msg(">>DIRDYN>> ***** mbs_dirdyn_write_buffers : impossible to save the files!\n");
return _MBS_ERR_MOD_DIRDYN + err1;
}
// free memory used by buffers
......@@ -915,8 +940,9 @@ int mbs_fct_dirdyn(double tsim, double y[], double dydt[], MbsData *s, MbsDirdyn
return 0;
}
void save_realtime_update(MbsDirdyn* dd, MbsData* mbs_data)
int save_realtime_update(MbsDirdyn* dd, MbsData* mbs_data)
{
int err = 0; // error_code
#ifdef REAL_TIME
Simu_realtime *realtime;
#endif
......@@ -928,7 +954,13 @@ void save_realtime_update(MbsDirdyn* dd, MbsData* mbs_data)
if (dd->savePeriodCounter%dd->options->saveperiod == 0)
{
mbs_dirdyn_save(dd, mbs_data, mbs_data->tsim);
err = mbs_dirdyn_save(dd, mbs_data, mbs_data->tsim);
if (err < 0) // Error management
{
mbs_msg("\t >Real-time> Error: during save_real_time_update ! \n");
return err;
}
}
}
......@@ -951,4 +983,6 @@ void save_realtime_update(MbsDirdyn* dd, MbsData* mbs_data)
}
}
#endif
return 0;
}
......@@ -169,7 +169,9 @@ int mbs_fct_dirdyn(double t, double y[], double dydt[], MbsData *s, MbsDirdyn *d
*
* \param[in] dd direct dynamics module
* \param[in] mbs_data Robotran main structure
*
* \return Error status, <0 in case of failure.
*/
void save_realtime_update(MbsDirdyn* dd, MbsData* mbs_data);
int save_realtime_update(MbsDirdyn* dd, MbsData* mbs_data);
#endif
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