Rename a few functions and variables to be a bit more Googley.

PiperOrigin-RevId: 523963645
Change-Id: Ife7ed3f44aa83c64dfbdc3ca78ee6de2092b0d63
This commit is contained in:
Saran Tunyasuvunakool
2023-04-13 04:23:41 -07:00
committed by Copybara-Service
parent 2e23594fe8
commit 5646c905cd
5 changed files with 191 additions and 190 deletions
+17 -16
View File
@@ -52,19 +52,20 @@ PYBIND11_MODULE(_simulate, pymodule) {
}))
.def(
"renderloop",
[](mujoco::Simulate& simulate) { simulate.renderloop(); },
[](mujoco::Simulate& simulate) { simulate.RenderLoop(); },
py::call_guard<py::gil_scoped_release>())
.def(
"load",
[](mujoco::Simulate& simulate, const std::string& path,
MjModelWrapper& m, MjDataWrapper& d) {
simulate.load(path.c_str(), m.get(), d.get());
simulate.Load(m.get(), d.get(), path.c_str());
},
py::call_guard<py::gil_scoped_release>())
.def("applyposepertubations", &mujoco::Simulate::applyposepertubations,
.def("apply_pose_perturbations",
&mujoco::Simulate::ApplyPosePerturbations,
py::call_guard<py::gil_scoped_release>())
.def("applyforceperturbations",
&mujoco::Simulate::applyforceperturbations,
.def("apply_force_perturbations",
&mujoco::Simulate::ApplyForcePerturbations,
py::call_guard<py::gil_scoped_release>())
.def(
@@ -74,18 +75,18 @@ PYBIND11_MODULE(_simulate, pymodule) {
},
py::call_guard<py::gil_scoped_release>(),
py::return_value_policy::reference)
.def_readonly("ctrlnoisestd", &mujoco::Simulate::ctrlnoisestd,
.def_readonly("ctrl_noise_std", &mujoco::Simulate::ctrl_noise_std,
py::call_guard<py::gil_scoped_release>())
.def_readonly("ctrlnoiserate", &mujoco::Simulate::ctrlnoiserate,
.def_readonly("ctrl_noise_rate", &mujoco::Simulate::ctrl_noise_rate,
py::call_guard<py::gil_scoped_release>())
.def_readonly("real_time_index", &mujoco::Simulate::realTimeIndex,
.def_readonly("real_time_index", &mujoco::Simulate::real_time_index,
py::call_guard<py::gil_scoped_release>())
.def_readwrite("speed_changed", &mujoco::Simulate::speedChanged,
.def_readwrite("speed_changed", &mujoco::Simulate::speed_changed,
py::call_guard<py::gil_scoped_release>())
.def_readwrite("measured_slowdown", &mujoco::Simulate::measuredSlowdown,
.def_readwrite("measured_slowdown", &mujoco::Simulate::measured_slowdown,
py::call_guard<py::gil_scoped_release>())
.def_readonly("refresh_rate", &mujoco::Simulate::refreshRate,
.def_readonly("refresh_rate", &mujoco::Simulate::refresh_rate,
py::call_guard<py::gil_scoped_release>())
.def_readonly("busywait", &mujoco::Simulate::busywait,
@@ -140,15 +141,15 @@ PYBIND11_MODULE(_simulate, pymodule) {
.def_property(
"load_error",
[](mujoco::Simulate& simulate) -> std::string {
return simulate.loadError;
return simulate.load_error;
},
[](mujoco::Simulate& simulate, const std::string& error) {
const auto max_length = sizeof_arr(simulate.loadError);
std::strncpy(simulate.loadError, error.c_str(), max_length - 1);
simulate.loadError[max_length - 1] = '\0';
const auto max_length = sizeof_arr(simulate.load_error);
std::strncpy(simulate.load_error, error.c_str(), max_length - 1);
simulate.load_error[max_length - 1] = '\0';
});
pymodule.def("setglfwdlhandle", [](std::uintptr_t dlhandle) {
pymodule.def("set_glfw_dlhandle", [](std::uintptr_t dlhandle) {
mujoco::Glfw(reinterpret_cast<void*>(dlhandle));
});
}
+12 -12
View File
@@ -33,7 +33,7 @@ import numpy as np
if not glfw._glfw: # pylint: disable=protected-access
raise RuntimeError('GLFW dynamic library handle is not available')
else:
_simulate.setglfwdlhandle(glfw._glfw._handle) # pylint: disable=protected-access
_simulate.set_glfw_dlhandle(glfw._glfw._handle) # pylint: disable=protected-access
# Logarithmically spaced realtime slow-down coefficients (percent).
PERCENT_REALTIME = (
@@ -100,7 +100,7 @@ def _reload(
assert m is not None and d is not None
path = load_tuple[2] if len(load_tuple) == 3 else ''
simulate.load(path, m, d)
simulate.load(m, d, path)
return m, d
@@ -109,7 +109,7 @@ def _physics_loop(simulate: Simulate, loader: Optional[_InternalLoaderType]):
"""Physics loop for the GUI, to be run in a separate thread."""
m: mujoco.MjModel = None
d: mujoco.MjData = None
ctrlnoise = np.array([])
ctrl_noise = np.array([])
reload = True
# CPU-sim synchronization point.
@@ -131,7 +131,7 @@ def _physics_loop(simulate: Simulate, loader: Optional[_InternalLoaderType]):
result = _reload(simulate, loader)
if result is not None:
m, d = result
ctrlnoise = np.zeros((m.nu,))
ctrl_noise = np.zeros((m.nu,))
reload = False
@@ -152,19 +152,19 @@ def _physics_loop(simulate: Simulate, loader: Optional[_InternalLoaderType]):
elapsedsim = d.time - syncsim
# Inject noise.
if simulate.ctrlnoisestd != 0.0:
if simulate.ctrl_noise_std != 0.0:
# Convert rate and scale to discrete time (OrnsteinUhlenbeck).
rate = math.exp(-m.opt.timestep /
max(simulate.ctrlnoiserate, mujoco.mjMINVAL))
scale = simulate.ctrlnoisestd * math.sqrt(1 - rate * rate)
max(simulate.ctrl_noise_rate, mujoco.mjMINVAL))
scale = simulate.ctrl_noise_std * math.sqrt(1 - rate * rate)
for i in range(m.nu):
# Update noise.
ctrlnoise[i] = (
rate * ctrlnoise[i] + scale * mujoco.mju_standardNormal(None))
ctrl_noise[i] = (rate * ctrl_noise[i] +
scale * mujoco.mju_standardNormal(None))
# Apply noise.
d.ctrl[i] = ctrlnoise[i]
d.ctrl[i] = ctrl_noise[i]
# Requested slow-down factor.
slowdown = 100 / PERCENT_REALTIME[simulate.real_time_index]
@@ -183,8 +183,8 @@ def _physics_loop(simulate: Simulate, loader: Optional[_InternalLoaderType]):
# Clear old perturbations, apply new.
d.xfrc_applied[:, :] = 0
simulate.applyposepertubations(0) # Move mocap bodies only.
simulate.applyforceperturbations()
simulate.apply_pose_perturbations(0) # Move mocap bodies only.
simulate.apply_force_perturbations()
# Run single step, let next iteration deal with timing.
mujoco.mj_step(m, d)