diff --git a/python/mujoco/simulate.cc b/python/mujoco/simulate.cc index 56fe44371d..decdbf3d5e 100644 --- a/python/mujoco/simulate.cc +++ b/python/mujoco/simulate.cc @@ -277,8 +277,10 @@ PYBIND11_MODULE(_simulate, pymodule) { .def_property_readonly("busywait", GetIfNotNull(&mujoco::Simulate::busywait), py::call_guard()) - .def_property_readonly("run", GetIfNotNull(&mujoco::Simulate::run), - py::call_guard()) + .def_property("run", + GetIfNotNull(&mujoco::Simulate::run), + SetIfNotNull(&mujoco::Simulate::run), + py::call_guard()) .def_property_readonly("exitrequest", CallIfNotNull(+[](mujoco::Simulate& sim) { diff --git a/python/mujoco/viewer.py b/python/mujoco/viewer.py index 65852c877f..f5a8dfbd09 100644 --- a/python/mujoco/viewer.py +++ b/python/mujoco/viewer.py @@ -115,6 +115,21 @@ def viewport(self): return sim.viewport return None + @property + def run(self): + sim = self._sim() + if sim is not None: + return sim.run + return None + + @run.setter + def run(self, value): + if value != 0 and value != 1: + raise ValueError('run must be 0 or 1') + sim = self._sim() + with sim.lock(): + sim.run = value + def set_figures(self, viewports_figures): sim = self._sim() if sim is not None: diff --git a/simulate/simulate.cc b/simulate/simulate.cc index bf4b4a13ef..9e9c3155c7 100644 --- a/simulate/simulate.cc +++ b/simulate/simulate.cc @@ -1553,7 +1553,7 @@ void UiEvent(mjuiState* state) { if (state->type==mjEVENT_KEY && state->key!=0) { switch (state->key) { case ' ': // Mode - if (!sim->is_passive_ && sim->m_) { + if (sim->m_ || sim->is_passive_) { sim->run = 1 - sim->run; sim->pert.active = 0; @@ -2122,7 +2122,7 @@ void Simulate::Sync() { // clear timers once profiler info has been copied ClearTimers(d_); - if (this->run || this->is_passive_) { + if (this->run) { // clear old perturbations, apply new mju_zero(d_->xfrc_applied, 6*m_->nbody); mjv_applyPerturbPose(m_, d_, &this->pert, 0); // mocap bodies only diff --git a/simulate/simulate.h b/simulate/simulate.h index cd654192e5..81530cbebc 100644 --- a/simulate/simulate.h +++ b/simulate/simulate.h @@ -289,7 +289,7 @@ class Simulate { // simulation section of UI const mjuiDef def_simulation[14] = { {mjITEM_SECTION, "Simulation", mjPRESERVE, nullptr, "AS"}, - {mjITEM_RADIO, "", 5, &this->run, "Pause\nRun"}, + {mjITEM_RADIO, "", 2, &this->run, "Pause\nRun"}, {mjITEM_BUTTON, "Reset", 2, nullptr, " #259"}, {mjITEM_BUTTON, "Reload", 5, nullptr, "CL"}, {mjITEM_BUTTON, "Align", 2, nullptr, "CA"},