Skip to content

Latest commit

 

History

History
30 lines (18 loc) · 1.08 KB

README.md

File metadata and controls

30 lines (18 loc) · 1.08 KB

pydantic_mujoco

A pydantic BaseModel to make it easier to programatically manipulate mujoco .MJCF files.

Example Usage:

from pydantic_mujoco.model import Mujoco as MujocoModel

model = MujocoModel.load(Path("models/gait2354.xml"))

# Print the names of all the bodies in the model
print([body.name_ for body in model.worldbody_.bodies()])

# Get the pose of a body as a numpy array
model.worldbody_.body_[0].pose

# Show the kinematic tree in graphviz
model.to_dot()

And here's what the generated graph looks like: graph

How it Works:

We use Mujoco's mj_printSchema to generate its XML schema in HTML. That HTML is parsed and then used to render a jinja2 template descrbing a pydantic base model (this all happens in scripts/generate_base_model.py).

To make the resulting model easier to work with, we add a few additional methods for loading / saving the model as well as walking its kinematic tree etc.