Introduction

I’m running some Reinforcement Learning (RL) experiments using Mujoco models and OpenAI Gym, but if you’ve worked with XML Mujoco models you’ll understand that they’re a pain to create and debug.

What I’m after is being able to design a mechanical system in a high-level CAD system like Autodesk Fusion 360 (which is my preferred weapon of choice currently), and easily export that model to Mujoco for simulation:

+------------+ .---------. +------------+ | Autodesk | | | | Mujoco | | Fusion 360 +-->| Converter +-->| XML | | Model | | | | Model | +------------+ +---------+ +------------+

What I really want to do is generate a cohort of Fusion 360 models using the parametric variable capabilities of Fusion 360, and simulate those in OpenAI Gym in bulk, as an experiment in geometry optimisation for robotic design:

+------------+ +------------+ +----------. | +----------+-+ .---------. | +----------+-+ | +---------+. | | .----------+-+ | | | | .----------+-+ | | .---------++ | | | Autodesk +->| Converter +->| | | Mujoco +->| | | OpenAI | +-+ | Fusion 360 | | | +-+ | XML + '+ | Gym | +-+ Model | +---------+ +-+ Model | '+ | +------------+ +------------+ +----------+

This is a similar approach that OpenAI are taking in developing their human-like robot hand, with the geometry optimisation aspect.

There are some impedance mismatches but this post describes the success I’ve had with a simple model.

The Fusion 360 Model

The mechanical system I’m working with is a four-legged robot with 4 joints:

Fusion 360 model

The model is parameterised in 5 variables:

Fusion 360 variables

You can download the Fusion 360 model using this link, or find it in the Github repository under “assets”.

There are several constraints on what model can be successfully converted:

  • All coordinate planes are aligned to Global XYZ
  • There’s one “root” body, defined by using the Fusion “ground” designation. This is the root body in the Mujoco simulation.
  • Only a single level of children, connected to the root, is supported.
  • Only “Revolute” joints are supported (as Mujoco “hinge” joints).

My long-term goal is to support a wider variety of model complexities and joint types.

Problems

There is some really weird behaviour w.r.t. the position of joints, for which I’ve posted on the Fusion forum: Weird joint origin behaviour

If you look at the code there’s a workaround based on the fillet radius, which is ugly, but works for now.

Usage

The code is on Github. The script in question is under

/fusion_script_to_mujoco

which can be loaded into Fusion 360 as a add-in.

The script will write the XML model to

/tmp

Once the model has been written, there is a rendering script that will render the model using the Mujoco viewer from mujoco-py.

$ python -m venv .env
$ source .env/bin/activate
$ make init
$ make test
$ fusion_mujoco_py/render_model.py /tmp/tmp.xml

Mujoco model

There’s also an option to not automatically run the simulation (useful for debugging the model):

$ fusion_mujoco_py/render_model.py /tmp/tmp.xml --nostep

Conclusion

Converting from one format to another is always perilous, since the domains aren’t necessarily well aligned, but (except for the joint origin bug I mentioned), I’m happy with where I am for now.

It’s good enough to create a cohort of models for simulation, and I will add more complexity to the converter over time.

The cohort generation code is also in the repo already, I will write a post about that next.

P.S. The code is good enough for a prototype, but is unlikely to support your model and doesn’t claim to be able to. (I don’t even know if anyone else in the world uses the Fusion and Mujoco combination).

If you’re interesting in developing this further drop me a line at ben@bjnortier.com, or follow me on Twitter.