Repository navigation
pycvc: mujoco_robot from Python, the Go2 gym's reset and step (stacked on #1266) - #1268
Merged
Merged
Conversation
…ee Go2 first cvc::physics::mujoco_robot owns one robot's mjModel and mjData, built from an MJCF file (the Menagerie's unitree_go2/scene.xml) with its floor replaced by a cvc::height_field. MuJoCo's hfield has the height field's layout and diagonal, so the robot stands on field->height(x, y). It steps at a fixed dt and takes position targets (MuJoCo-side servos, written into its own model) or torques per actuator. It applies wrenches for pushes, reads qpos, qvel, actuator forces and contacts, and reads MuJoCo's own energies (mjENBL_ENERGY) next to books of the work each kind of force did. It also saves and restores snapshots. No process-wide state: no mju_user_* handlers, no plugin registration. CVC_WITH_MUJOCO is off by default. MuJoCo 4 is found in the deps prefix only (cvcpkg's mujoco), never the system's paths. As with Jolt, the MuJoCo TU is its own private target (cvc_physics_mujoco); a shared libcvc links the shared libmujoco and exports none of it. run_mujoco_trial and `cvc mujoco info|stand` run a standing and push trial. The new CI job `mujoco` builds a minimal libcvc with the option on, from cvcpkg's mujoco and mujoco-menagerie, and runs the tests: - the Go2 stands on flat ground and on 10 degree slopes; - a 60 N push perturbs it and it recovers, and 300 N knocks it over; - MuJoCo's energy change matches the books to 2e-5 of the gross work, and the residual halves with the step; - two runs, a run read every step, and a restored snapshot all end on the same bits. The legged plant kind (legged:go2 in plant_host) is left for later: nav's command(steer, accel) needs a locomotion policy to become leg motion (docs/MUJOCO.md).
pycvc_mujoco.i puts cvc::physics::mujoco_robot in every pycvc: pycvc.mujoco_robot(model, terrain=height_field, ...) with the C++ options as keywords. It binds the commands (position or torque, per actuator or all), pushes, step() (without the GIL), the readouts (qpos, qvel, commands and actuator forces as read-only float64 numpy copies; base() and contacts() as dicts), energy() and books(), save/restore, and run_mujoco_trial as a dict. Without CVC_WITH_MUJOCO, mujoco_available() is False and the constructor raises. mujoco_robot::reset() goes back to the robot as built (state, modes, gains and books), for a gym's reset. ResetReplaysAFreshRobot checks it to the bit. test_pycvc_mujoco.py has 112 checks. The push moves the Go2 1.66 cm, as in C++. The books close to 2.9e-5 J of 5.9 J. reset() and a restored snapshot replay an episode bitwise, and another thread runs while step() does. The CI job `mujoco` now also builds pycvc (Python 3.12, numpy and SWIG from cvcpkg) and runs it, failing if it skips.
transfix
enabled auto-merge (squash)
November 15, 2026 08:48
transfix
added a commit
that referenced
this pull request
Nov 16, 2026
…#1253, #1255, #1256, #1264, #1268, #1271, #1273, #1277) - ci.yml: the sanitizer list keeps this branch's tests (stream_test, net_ws_client_test, ariadne_host_test) and master's segmentation_intrinsics_test. - STATE_EXEC_THREADED.md: the room-call verbs (room-run is #1273's) and #1252's segment.seeded provider in the provider table, both registered without a kind. room-call's async functions stay on the app's host: a reply settles on the relay client's reader thread through host.finish, so moving them to *ictx.host needs a finisher first.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #1266. It includes #1266's commit (2837de0); the new work is the top commit, eca31f9. The base is master because
ci.ymlruns pull requests only into master, develop, main andperf/**, and changing a PR's base later doesn't re-run CI. Once #1266 merges, the diff here shrinks to this commit. Merge after #1266, and only on Joe's OK.This puts
cvc::physics::mujoco_robotin pycvc as the base for the C-PHAST lab's gym (Phase 6 of PH-COMPOSE-ROADMAP.md on #1227): areset/steploop with MuJoCo's Go2 as the plant.What's in it
bindings/pycvc/pycvc_mujoco.iis%included bypycvc.iafterpycvc_physics.i, so every pycvc has it. WithoutCVC_WITH_MUJOCO,pycvc.mujoco_available()is False and the constructor raises.pycvc.mujoco_robot(model, terrain=height_field, ...)takes the C++ options as keywords. The terrain is copied in.apply_wrenchandapply_force_at.step(n)releases the GIL.qpos,qvel,commandsandactuator_forcesare read-only float64 numpy copies (pycvc_world.i'scopy_of).base(),contacts(),energy()andbooks()return dicts.save/restore/reset, andpycvc.run_mujoco_trial(), which returns a dict.mujoco_robot::reset()(C++) goes back to the robot as built: its state, modes, gains and books. This is the gym's reset. The new C++ testResetReplaysAFreshRobotchecks it bitwise.test_pycvc_mujoco.py(ctestpycvc_mujoco, 112 checks):reset(), a restored snapshot and a second robot all replay an episode bitwise;step()does;mujocojob now also installs Python 3.12, numpy and SWIG from cvcpkg, builds pycvc with MuJoCo on, and runspycvc_mujocowith-V. It fails if the test skips or doesn't report its checks. The other pycvc lanes run the same test with MuJoCo off, which checks the refusal.Checked locally (Linux x86_64, Release)
physics_mujoco_robot_test11/11, andpycvc_mujoco112 checks passed.pycvc_mujocopasses on the refusal path (2 checks).pycvc's objects is clean, and clang-format is clean on the changed lines.Not here
The gym itself (a scenario registry starting with push recovery, observation and reward conventions, and C-PHAST as the planning baseline) comes with the lab. The
leggedplant kind still waits for a locomotion policy (see #1266).