|
Mujoco KDL Wrapper
0.1.0
MuJoCo + KDL bridge for robot kinematics and dynamics
|
A C++ library bridging MuJoCo 3.8 physics simulation with KDL for robot kinematics and dynamics.
![]() ex_gravity_comp — Single arm, KDL gravity compensation | ![]() ex_table_scene — Arm + table + scene objects |
![]() ex_pick — Pick-and-place with Robotiq 2F-85 | ![]() ex_dual_arm — Dual arm + grippers |
For a full step-by-step walkthrough, read docs/TUTORIAL.md. It starts from installation and gradually builds up robot control, attachments, asset-backed objects, reset hooks, cameras, the Simulate UI, recording, and multi-robot scenes.
build_scene() accepts MJCF files and builds floor, skybox, primitive objects, asset-backed objects, and cameras via mjSpec with no intermediate XML filesAttachmentSpec attaches any MJCF body (mount, FT sensor, gripper, arm on a mobile base) under any named body; chains of arbitrary length are applied in declaration orderSceneSpec::robotsEnv owns model/data, registered robots, and reset hooks for task-specific object/controller stateinit_robot_from_mjcf() builds a KDL chain directly from a compiled MuJoCo modelupdate() reads qpos/qvel/qfrc_actuator into *_msr and applies *_cmd in POSITION or TORQUE modetest/urdf_solver_probe.cpp uses the bundled Kinova GEN3 URDF to check ACHD fixed-joint outputs and compare URDF-vs-MuJoCo RNEA torquesinit_window_sim() + step() gives your code the control loop while the MuJoCo simulate UI runs in a background render threadVideoRecorder for EGL offscreen MP4 recording| Dependency | Version | Install |
|---|---|---|
| MuJoCo | 3.8.0 | download to /opt/mujoco-3.8.0 |
| GLFW | 3.x | sudo apt install libglfw3-dev |
| OpenGL / EGL | – | sudo apt install libgl-dev libegl-dev |
| orocos-kdl | – | sudo apt install liborocos-kdl-dev |
| ffmpeg | – | sudo apt install ffmpeg (for VideoRecorder) |
Only MuJoCo 3.8.0 is supported. CMake checks mjVERSION_HEADER and stops at configure time if MUJOCO_ROOT points to any other MuJoCo release.
Then add -DCMAKE_PREFIX_PATH=~/ws/install to the build below.
Optional flags:
| Flag | Default | Description |
|---|---|---|
BUILD_RECORDER=ON | ON | Enable VideoRecorder (EGL + ffmpeg headless recording) |
FETCH_MENAGERIE=ON | OFF | Download MuJoCo Menagerie robot models |
BUILD_TESTS=ON | ON | Build and register GoogleTest tests with CTest |
BUILD_DOCS=ON | OFF | Generate Doxygen HTML docs (cmake --build build --target docs) |
The repo also carries third_party/kinova/GEN3_URDF_V12.urdf for KDL parser diagnostics. The MuJoCo model remains sourced from Menagerie.
The simulate UI screenshot button (S key) is always enabled; it uses an ffmpeg pipe to write PNGs without any third-party lodepng dependency.
The local Simulate UI also includes wrapper-specific controls in the Simulation panel:
RTF shows the wrapper real-time factor controlled by , and ..Recorder lets you select output path, recording camera, resolution, FPS, and start/stop recording.When a tool (gripper) is attached, pass a ToolFrameSpec so KDL dynamics include the full tool inertia and FK uses the TCP site:
Chains are supported: push multiple AttachmentSpec entries in order (mount -> FT sensor -> gripper).
reset(Env*) resets the environment runtime to its initial keyframe, calls an optional environment reset hook, re-seeds all registered robots' command ports to the current measured state, and clears stale robot forces. Use the hook to put objects, controllers, and task state back at their episode start values:
Interactive recording is available from the Simulate UI:
Path, Camera, Resolution, and FPS.Start rec.Stop rec.The recorder camera list includes Current, Free, Tracking, robot MJCF cameras, and cameras added through SceneSpec::cameras. When ffmpeg closes successfully the terminal prints:
| Input | Action |
|---|---|
| Left drag | Orbit camera |
| Right drag | Pan camera |
| Scroll | Zoom |
| Double-click body | Select body for perturbation |
| Left drag (selected) | Apply translational force |
| Right drag (selected) | Apply torque |
D | Deselect body |
Space | Pause / resume |
, | Decrease wrapper real-time factor |
. | Increase wrapper real-time factor |
All other controls (reset, quit, rendering flags, live camera selection, and recording) are in the MuJoCo panels.
See test/README.md for the full list of tests.
See src/examples/README.md for the full list of examples.
| Path | Description |
|---|---|
third_party/menagerie/kinova_gen3/gen3.xml | Kinova GEN3 7-DOF arm (MuJoCo Menagerie) |
third_party/menagerie/robotiq_2f85/2f85.xml | Robotiq 2F-85 gripper (MuJoCo Menagerie) |