MuJoCo + Pinocchio robot description interface and associated tools for simulation.
- Python 3.10
- Pinocchio
- MuJoCo
- robot_descriptions
python3 -m pip install --upgrade pip pinocchio mujoco robot_descriptions
This repo provides a wrapper to interface MuJoCo for the simulation environment and Pinocchio library for efficient kino-dyamic computations.
Defined in the RobotWrapperAbstract
class. This class provides tools to interface model descriptions from both MuJoCo and Pinocchio. It also checks that both descriptions are similar.
Paths of urdf
and mjcf
(as xml
) description files needs to be provided. One can use RobotModelLoader
to get the paths automatically given the robot name (now only working with go2
robot). The model will be loaded in the custom environment defined in scene.xml
.
-
get_pin_state
andget_mj_state
return the state of robot respectively in Pinocchio and MuJoCo format (different quaternion representation). One can also access to the joint names or end effector names. -
get_j_eeff_contact_with_floor
returns which end effectors is in contact with the floor in the simulation as a map {end effector name : True/False}
QuadrupedWrapperAbstract
inherits from RobotWrapperAbstract
and provide additional tools for quadruped robots by abstracting the robot description.
get_pin_feet_position_world
returns the feet positions in world frame (same forhip
,thigh
andcalf
).
For custom usage of the wrapper, two abstract classes used in the Simulator
need to be inherited.
-
ControllerAbstract
Implements the robot controller or policy. The following method should be inherited.-
get_torques(q, v, robot_data)
This method is called every simulation step by the simulator. It takes as input the robot position stateq: np.array
, the robot velocity statev: np.array
and the simulation datarobot_data: MjData
. It should return the torques for each actuator as a map {joint name :$\tau$ }. One can find the joint names theRobotWrapperAbstract
.
See
BiConMPC
for exemple of inheritance. -
-
DataRecorderAbstract
Implements a class to record the data from the simulation. The following method should be inherited.-
record(q, v, robot_data)
This method is called every simulation step by the simulator. It takes as input the robot position stateq: np.array
, the robot velocity statev: np.array
and the simulation datarobot_data: MjData
.
-
One can run the simulation with or without viewer using the run
method.