MuJoCo wrapper for BiConMP solver in a docker container.
This project uses VS Code devcontainer. To run this workspace, please first install VS Code with the following extensions:
- Dev Containers (ms-vscode-remote.remote-containers)
- Remote Developement (ms-vscode-remote.vscode-remote-extensionpack)
- Docker (ms-azuretools.vscode-docker)
After that is done, clone this repository onto your developement PC.
git clone --recurse-submodules https://github.com/Atarilab/biconmp_mujoco.git
Then, enter the directory downloaded and open it in vscode
cd biconmp_mujoco && code .
After VS Code has started, there should be a prompt to start this workspace as a container. Otherwise, you can also do ctrl + shift + p then select Dev Container: Rebuild and Reopen in Container to start it manually.
The environment is set up automatically with BiConMP installed.
This repo provides a wrapper to interface MuJoCo for the simulation environment and Pinocchio used by BiConMP. The source code is in project/example/mj_pin_wrapper
.
The wrapper is imported as a submodule in the project from this repository.
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).
-
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_mj_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.
See main.py
for a minimal example.