Hello! I am aware of the fact that the MuJoCo simulator monitors the system state for large numbers or infs/nans, and resets automatically if it finds them. For me, rather than automatically reseting the MuJoCo simulator, I just want to exit from the int main() function with a specific return value. For this, is there any function or bit that I can check of whether an "Inf or Huge value in QACC" error occurred? If so, my aim is then to write the following pseudo-code: if( "Inf or Huge value in QACC" error occurred == TRUE ) { cout << "QACC error occurred! Halting Simulation" << endl; return MY_ERROR_FLAG; } I will thoroughly appreciate any help related to this. Thank you very much.
You can write your own function and call it before mj_step, like this (do the same for qvel and qacc as well): int mj_checkPos(const mjModel* m, mjData* d) { for( int i=0; i<m->nq; i++ ) if( mju_isBad(d->qpos) ) return 1; return 0; } The function mju_isBad is defined as: int mju_isBad(mjtNum x) { return( x!=x || x>mjMAXVAL || x<-mjMAXVAL ); }