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:
Yuval Tassa
2024-07-30 08:40:55 -07:00
committed by Copybara-Service
parent 123a01bd83
commit 24a555062d
13 changed files with 48 additions and 23 deletions
+5
View File
@@ -577,6 +577,11 @@ from its default.
This flag disables implicit integration with respect to joint damping in the Euler integrator. See the
:ref:`Numerical Integration<geIntegration>` section for more details.
.. _option-flag-autoreset:
:at:`autoreset`: :at-val:`[disable, enable], "enable"`
This flag disables the automatic reseting of the simulation state when numerical issues are detected.
.. _option-flag-override:
:at:`override`: :at-val:`[disable, enable], "disable"`
+3 -3
View File
@@ -35,11 +35,11 @@
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
| | | | :ref:`warmstart<option-flag-warmstart>` | :ref:`filterparent<option-flag-filterparent>` | :ref:`actuation<option-flag-actuation>` | :ref:`refsafe<option-flag-refsafe>` | |
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
| | | | :ref:`sensor<option-flag-sensor>` | :ref:`midphase<option-flag-midphase>` | :ref:`eulerdamp<option-flag-eulerdamp>` | :ref:`override<option-flag-override>` | |
| | | | :ref:`sensor<option-flag-sensor>` | :ref:`midphase<option-flag-midphase>` | :ref:`eulerdamp<option-flag-eulerdamp>` | :ref:`autoreset<option-flag-autoreset>` | |
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
| | | | :ref:`energy<option-flag-energy>` | :ref:`fwdinv<option-flag-fwdinv>` | :ref:`invdiscrete<option-flag-invdiscrete>` | :ref:`multiccd<option-flag-multiccd>` | |
| | | | :ref:`override<option-flag-override>` | :ref:`energy<option-flag-energy>` | :ref:`fwdinv<option-flag-fwdinv>` | :ref:`invdiscrete<option-flag-invdiscrete>` | |
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
| | | | :ref:`island<option-flag-island>` | | | | |
| | | | :ref:`multiccd<option-flag-multiccd>` | :ref:`island<option-flag-island>` | | | |
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
+------------------------------------+----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| mujoco |br| |L| | | .. table:: |
+2 -1
View File
@@ -8,7 +8,8 @@ Upcoming version (not yet released)
General
^^^^^^^
1. Renamed ``mjModel.tex_rbg`` to ``mjModel.tex_data``.
2. Added a new disable flag ``mjDSBL_AUTORESETNAN`` to disable automatic reset when NaNs or infinities are produced.
2. Added a new :ref:`autoreset<option-flag-autoreset>` flag to disable automatic reset when NaNs or infinities are
detected.
3. Added sub-elements to the MJCF :ref:`material<asset-material>` element, to allow specification of multiple textures
for rendering (e.g., :ref:`occlusion-roughness-metallic<material-orm>`). Note that the MuJoCo renderer doesn't
support these new features, and they are made available for use with external renderers.
+1 -1
View File
@@ -418,7 +418,7 @@ typedef enum mjtDisableBit_ { // disable default feature bitflags
mjDSBL_SENSOR = 1<<12, // sensors
mjDSBL_MIDPHASE = 1<<13, // mid-phase collision filtering
mjDSBL_EULERDAMP = 1<<14, // implicit integration of joint damping in Euler integrator
mjDSBL_AUTORESETNAN = 1<<15, // automatic reset when numerical issues are detected
mjDSBL_AUTORESET = 1<<15, // automatic reset when numerical issues are detected
mjNDISABLE = 16 // number of disable flags
} mjtDisableBit;
+1 -1
View File
@@ -61,7 +61,7 @@ typedef enum mjtDisableBit_ { // disable default feature bitflags
mjDSBL_SENSOR = 1<<12, // sensors
mjDSBL_MIDPHASE = 1<<13, // mid-phase collision filtering
mjDSBL_EULERDAMP = 1<<14, // implicit integration of joint damping in Euler integrator
mjDSBL_AUTORESETNAN = 1<<15, // automatic reset when numerical issues are detected
mjDSBL_AUTORESET = 1<<15, // automatic reset when numerical issues are detected
mjNDISABLE = 16 // number of disable flags
} mjtDisableBit;
+1 -1
View File
@@ -42,7 +42,7 @@ ENUMS: Mapping[str, EnumDecl] = dict([
('mjDSBL_SENSOR', 4096),
('mjDSBL_MIDPHASE', 8192),
('mjDSBL_EULERDAMP', 16384),
('mjDSBL_AUTORESETNAN', 32768),
('mjDSBL_AUTORESET', 32768),
('mjNDISABLE', 16),
]),
)),
+24 -2
View File
@@ -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) {
+1 -6
View File
@@ -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;
+4 -4
View File
@@ -52,7 +52,7 @@ void mj_checkPos(const mjModel* m, mjData* d) {
for (int i=0; i < m->nq; i++) {
if (mju_isBad(d->qpos[i])) {
mj_warning(d, mjWARN_BADQPOS, i);
if (!(m->opt.disableflags & mjDSBL_AUTORESETNAN)) {
if (!mjDISABLED(mjDSBL_AUTORESET)) {
mj_resetData(m, d);
}
d->warning[mjWARN_BADQPOS].number++;
@@ -69,7 +69,7 @@ void mj_checkVel(const mjModel* m, mjData* d) {
for (int i=0; i < m->nv; i++) {
if (mju_isBad(d->qvel[i])) {
mj_warning(d, mjWARN_BADQVEL, i);
if (!(m->opt.disableflags & mjDSBL_AUTORESETNAN)) {
if (!mjDISABLED(mjDSBL_AUTORESET)) {
mj_resetData(m, d);
}
d->warning[mjWARN_BADQVEL].number++;
@@ -86,12 +86,12 @@ void mj_checkAcc(const mjModel* m, mjData* d) {
for (int i=0; i < m->nv; i++) {
if (mju_isBad(d->qacc[i])) {
mj_warning(d, mjWARN_BADQACC, i);
if (!(m->opt.disableflags & mjDSBL_AUTORESETNAN)) {
if (!mjDISABLED(mjDSBL_AUTORESET)) {
mj_resetData(m, d);
}
d->warning[mjWARN_BADQACC].number++;
d->warning[mjWARN_BADQACC].lastinfo = i;
if (!(m->opt.disableflags & mjDSBL_AUTORESETNAN)) {
if (!mjDISABLED(mjDSBL_AUTORESET)) {
mj_forward(m, d);
}
return;
+1 -1
View File
@@ -58,7 +58,7 @@ const char* mjDISABLESTRING[mjNDISABLE] = {
"Sensor",
"Midphase",
"Eulerdamp",
"AutoResetNaN"
"AutoReset"
};
+3 -2
View File
@@ -115,9 +115,9 @@ const char* MJCF[nMJCF][mjXATTRNUM] = {
"solver", "iterations", "ls_iterations", "noslip_iterations", "mpr_iterations",
"sdf_iterations", "sdf_initpoints", "actuatorgroupdisable"},
{"<"},
{"flag", "?", "21", "constraint", "equality", "frictionloss", "limit", "contact",
{"flag", "?", "22", "constraint", "equality", "frictionloss", "limit", "contact",
"passive", "gravity", "clampctrl", "warmstart",
"filterparent", "actuation", "refsafe", "sensor", "midphase", "eulerdamp",
"filterparent", "actuation", "refsafe", "sensor", "midphase", "eulerdamp", "autoreset",
"override", "energy", "fwdinv", "invdiscrete", "multiccd", "island"},
{">"},
@@ -1122,6 +1122,7 @@ void mjXReader::Option(XMLElement* section, mjOption* opt) {
READDSBL("sensor", mjDSBL_SENSOR)
READDSBL("midphase", mjDSBL_MIDPHASE)
READDSBL("eulerdamp", mjDSBL_EULERDAMP)
READDSBL("autoreset", mjDSBL_AUTORESET)
#undef READDSBL
#define READENBL(NAME, MASK) \
+1
View File
@@ -1001,6 +1001,7 @@ void mjXWriter::Option(XMLElement* root) {
WRITEDSBL("sensor", mjDSBL_SENSOR)
WRITEDSBL("midphase", mjDSBL_MIDPHASE)
WRITEDSBL("eulerdamp", mjDSBL_EULERDAMP)
WRITEDSBL("autoreset", mjDSBL_AUTORESET)
#undef WRITEDSBL
#define WRITEENBL(NAME, MASK) \
+1 -1
View File
@@ -157,7 +157,7 @@ public enum mjtDisableBit : int{
mjDSBL_SENSOR = 4096,
mjDSBL_MIDPHASE = 8192,
mjDSBL_EULERDAMP = 16384,
mjDSBL_AUTORESETNAN = 32768,
mjDSBL_AUTORESET = 32768,
mjNDISABLE = 16,
}
public enum mjtEnableBit : int{