# Preparing a robot for simulation in MuJoCo
## If you designed your robot in OnShape
### Make sure to design you robot according to onshape-to-robot constraints
https://onshape-to-robot.readthedocs.io/en/latest/design.html
The urdf will contain frames named `closing_<...>_1` and `closing_<...>_2` that you can use to close the loops in the mjcf file.
### Get get robot urdf from onshape
Run
```bash
$ onshape-to-robot robots/bd1/
```
#### (Optional) If you have closing loops, follow the instructions for handling them in the documentation of onshape-to-robotn then:
In `robot.urdf`, add :
```xml
...
```
# Convert URDF to MJCF (MuJoCo)
## Get MuJoCo binaries
Download mujoco binaries somewhere https://github.com/google-deepmind/mujoco/releases
unpack and run
```bash
$ ./compile robot.urdf robot.xml
```
## In robot.xml, add actuators :
Example :
```xml
```
## Add a freejoint
encapsulate the body in a freejoint
```xml
...
...
```
## (Optional) Constrain closing loop
Add the following to the mjcf file
```xml
```
the x, y, z values can be found in the .urdf
```xml
...
```
## Setup collision groups, damping and friction
/!\ remove actuatorfrcrange in joints
Put that inside the bracket
```xml
...
...
```
still need to add :
- change frames to sites
## Visualize
```bash
$ python3 -m mujoco.viewer --mjcf=/scene.xml
```
or
```bash
$ /bin/simulate /scene.xml
```