Refactor StepControl and GUI to return change status.
StepControl methods SetSpeed, SetNoiseParameters, and SetPauseState now return a boolean indicating whether the state was actually changed. The GUI functions NoiseGui and StepControlGui also return a boolean reflecting if any parameters were modified. Noise parameters are now directly managed by StepControl rather than being stored in UxState. The StepControlEvent message has been expanded to include all step control parameters. Keyboard event handling has been slightly refactored to better align with event-based updates. PiperOrigin-RevId: 940656342 Change-Id: I3701623a2fdcfc4c084b5db0ae19048669040de4
This commit is contained in:
committed by
Copybara-Service
parent
f4b2f76def
commit
58d6910afa
@@ -14,7 +14,6 @@
|
||||
|
||||
// Python bindings for MuJoCo platform UX components.
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
@@ -44,10 +43,6 @@ struct UxState {
|
||||
char watch_field_name[256] = {0};
|
||||
int watch_field_index = 0;
|
||||
|
||||
// Read/edited by noise_gui
|
||||
float noise_scale = 0.0f;
|
||||
float noise_rate = 0.0f;
|
||||
|
||||
// Read/edited by camera_selection_gui
|
||||
int camera_index = mujoco::platform::kTumbleCameraIdx;
|
||||
};
|
||||
@@ -75,8 +70,6 @@ PYBIND11_MODULE(ux, m) {
|
||||
.def_readwrite("state", &UxState::state)
|
||||
.def_readwrite("state_sig", &UxState::state_sig)
|
||||
.def_readwrite("watch_field_index", &UxState::watch_field_index)
|
||||
.def_readwrite("noise_scale", &UxState::noise_scale)
|
||||
.def_readwrite("noise_rate", &UxState::noise_rate)
|
||||
.def_readwrite("camera_index", &UxState::camera_index)
|
||||
.def_property(
|
||||
"watch_field_name",
|
||||
@@ -115,13 +108,11 @@ PYBIND11_MODULE(ux, m) {
|
||||
|
||||
m.def(
|
||||
"step_control_gui",
|
||||
[](const mujoco::python::MjModelWrapper& model,
|
||||
mujoco::platform::StepControl* step_control, UxState& ux_state) {
|
||||
[](mujoco::platform::StepControl* step_control, UxState& ux_state) {
|
||||
py::gil_scoped_release no_gil;
|
||||
mujoco::platform::StepControlGui(model.get(), step_control,
|
||||
ux_state.speed_index);
|
||||
mujoco::platform::StepControlGui(step_control, ux_state.speed_index);
|
||||
},
|
||||
py::arg("model"), py::arg("step_control"), py::arg("ux_state"),
|
||||
py::arg("step_control"), py::arg("ux_state"),
|
||||
"Render the simulation stepping control GUI. Modifies "
|
||||
"ux_state.speed_index.");
|
||||
|
||||
@@ -170,19 +161,25 @@ PYBIND11_MODULE(ux, m) {
|
||||
[](const mujoco::python::MjModelWrapper& model,
|
||||
mujoco::python::MjvCameraWrapper& camera, int request_idx) {
|
||||
py::gil_scoped_release no_gil;
|
||||
return mujoco::platform::SetCamera(model.get(), camera.get(), request_idx);
|
||||
return mujoco::platform::SetCamera(model.get(), camera.get(),
|
||||
request_idx);
|
||||
},
|
||||
py::arg("model"), py::arg("camera"), py::arg("request_idx"),
|
||||
"Set the camera index and update the camera object.");
|
||||
|
||||
m.def(
|
||||
"set_speed_index",
|
||||
[](mujoco::platform::StepControl* step_control, UxState& ux_state, int idx) {
|
||||
py::gil_scoped_release no_gil;
|
||||
mujoco::platform::SetSpeedIndex(step_control, ux_state.speed_index, idx);
|
||||
[](mujoco::platform::StepControl* step_control, int speed_index,
|
||||
int request_idx) {
|
||||
{
|
||||
py::gil_scoped_release no_gil;
|
||||
mujoco::platform::SetSpeedIndex(step_control, speed_index,
|
||||
request_idx);
|
||||
}
|
||||
return speed_index;
|
||||
},
|
||||
py::arg("step_control"), py::arg("ux_state"), py::arg("idx"),
|
||||
"Set the simulation speed index.");
|
||||
py::arg("step_control"), py::arg("speed_index"), py::arg("request_idx"),
|
||||
"Set the simulation speed index. Returns new_speed_index.");
|
||||
|
||||
m.def(
|
||||
"physics_gui",
|
||||
@@ -294,15 +291,11 @@ PYBIND11_MODULE(ux, m) {
|
||||
|
||||
m.def(
|
||||
"noise_gui",
|
||||
[](const mujoco::python::MjModelWrapper& model,
|
||||
mujoco::python::MjDataWrapper& data, UxState& ux_state) {
|
||||
[](mujoco::platform::StepControl* step_control) {
|
||||
py::gil_scoped_release no_gil;
|
||||
mujoco::platform::NoiseGui(model.get(), data.get(),
|
||||
ux_state.noise_scale, ux_state.noise_rate);
|
||||
mujoco::platform::NoiseGui(step_control);
|
||||
},
|
||||
py::arg("model"), py::arg("data"), py::arg("ux_state"),
|
||||
"Render the noise UI. Modifies ux_state.noise_scale and "
|
||||
"ux_state.noise_rate.");
|
||||
py::arg("step_control"), "Render the noise UI.");
|
||||
|
||||
m.def(
|
||||
"convergence_gui",
|
||||
|
||||
Reference in New Issue
Block a user