Rename mjDSBL_AUTORESETNAN to mjDSBL_AUTORESET.
- Expose in MJCF. - Add documentation. - Improve handling in simulate. PiperOrigin-RevId: 657606140 Change-Id: I6a27c2f4842d7d4ae32642f2a6255e5f8f1f605a
This commit is contained in:
committed by
Copybara-Service
parent
123a01bd83
commit
24a555062d
+24
-2
@@ -199,6 +199,16 @@ void scanPluginLibraries() {
|
||||
|
||||
//------------------------------------------- simulation -------------------------------------------
|
||||
|
||||
const char* Diverged(int disableflags, const mjData* d) {
|
||||
if (disableflags & mjDSBL_AUTORESET) {
|
||||
for (mjtWarning w : {mjWARN_BADQACC, mjWARN_BADQVEL, mjWARN_BADQPOS}) {
|
||||
if (d->warning[w].number > 0) {
|
||||
return mju_warningText(w, d->warning[w].lastinfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
mjModel* LoadModel(const char* file, mj::Simulate& sim) {
|
||||
// this copy is needed so that the mju::strlen call below compiles
|
||||
@@ -356,7 +366,13 @@ void PhysicsLoop(mj::Simulate& sim) {
|
||||
|
||||
// run single step, let next iteration deal with timing
|
||||
mj_step(m, d);
|
||||
stepped = true;
|
||||
const char* message = Diverged(m->opt.disableflags, d);
|
||||
if (message) {
|
||||
sim.run = 0;
|
||||
mju::strcpy_arr(sim.load_error, message);
|
||||
} else {
|
||||
stepped = true;
|
||||
}
|
||||
}
|
||||
|
||||
// in-sync: step until ahead of cpu
|
||||
@@ -381,7 +397,13 @@ void PhysicsLoop(mj::Simulate& sim) {
|
||||
|
||||
// call mj_step
|
||||
mj_step(m, d);
|
||||
stepped = true;
|
||||
const char* message = Diverged(m->opt.disableflags, d);
|
||||
if (message) {
|
||||
sim.run = 0;
|
||||
mju::strcpy_arr(sim.load_error, message);
|
||||
} else {
|
||||
stepped = true;
|
||||
}
|
||||
|
||||
// break if reset
|
||||
if (d->time < prevSim) {
|
||||
|
||||
@@ -739,18 +739,12 @@ void MakePhysicsSection(mj::Simulate* sim) {
|
||||
for (int i=0; i<mjNDISABLE; i++) {
|
||||
mju::strcpy_arr(defFlag[0].name, mjDISABLESTRING[i]);
|
||||
defFlag[0].pdata = sim->disable + i;
|
||||
if ((1 << i) == mjDSBL_AUTORESETNAN) {
|
||||
defFlag[0].state = 0;
|
||||
} else {
|
||||
defFlag[0].state = 2;
|
||||
}
|
||||
mjui_add(&sim->ui0, defFlag);
|
||||
}
|
||||
mjui_add(&sim->ui0, defEnableFlags);
|
||||
for (int i=0; i<mjNENABLE; i++) {
|
||||
mju::strcpy_arr(defFlag[0].name, mjENABLESTRING[i]);
|
||||
defFlag[0].pdata = sim->enable + i;
|
||||
defFlag[0].state = 2;
|
||||
mjui_add(&sim->ui0, defFlag);
|
||||
}
|
||||
// add contact override
|
||||
@@ -1956,6 +1950,7 @@ void Simulate::Sync() {
|
||||
if (pending_.reset) {
|
||||
mj_resetData(m_, d_);
|
||||
mj_forward(m_, d_);
|
||||
load_error[0] = '\0';
|
||||
update_profiler = true;
|
||||
update_sensor = true;
|
||||
scrub_index = 0;
|
||||
|
||||
Reference in New Issue
Block a user