Handle None values for model and data in StepControl.advance.
The `StepControl.advance` method now checks if the provided `model` or `data` Python objects are `None` before attempting to cast them to `MjModelWrapper` or `MjDataWrapper`, passing `nullptr` to the underlying C++ function if they are `None`. This fixes an oversight in the python bindings, C++ code already supported null models. PiperOrigin-RevId: 937243996 Change-Id: Ie67b8603517e7390fb54bfefbfed79ccf7b2bc5e
This commit is contained in:
committed by
Copybara-Service
parent
a3039224ba
commit
38956ed95c
@@ -44,10 +44,16 @@ PYBIND11_MODULE(sim, m) {
|
|||||||
.def(
|
.def(
|
||||||
"advance",
|
"advance",
|
||||||
[](StepControl& self, py::object model_obj, py::object data_obj) {
|
[](StepControl& self, py::object model_obj, py::object data_obj) {
|
||||||
auto& model = py::cast<mujoco::python::MjModelWrapper&>(model_obj);
|
mjModel* m = nullptr;
|
||||||
auto& data = py::cast<mujoco::python::MjDataWrapper&>(data_obj);
|
mjData* d = nullptr;
|
||||||
|
if (!model_obj.is_none()) {
|
||||||
|
m = py::cast<mujoco::python::MjModelWrapper&>(model_obj).get();
|
||||||
|
}
|
||||||
|
if (!data_obj.is_none()) {
|
||||||
|
d = py::cast<mujoco::python::MjDataWrapper&>(data_obj).get();
|
||||||
|
}
|
||||||
py::gil_scoped_release no_gil;
|
py::gil_scoped_release no_gil;
|
||||||
return self.Advance(model.get(), data.get());
|
return self.Advance(m, d);
|
||||||
},
|
},
|
||||||
py::arg("model"), py::arg("data"),
|
py::arg("model"), py::arg("data"),
|
||||||
"Step physics forward, respecting speed settings and refresh budget.")
|
"Step physics forward, respecting speed settings and refresh budget.")
|
||||||
|
|||||||
Reference in New Issue
Block a user