I was checking out the simulation options, pyBullet is nice and close to Python but it’s really a physics framework. MuJoCo was designed from ground up with simulating robots in mind. pyBullet is reading URDF files that are XML files defining how the single elements relate to each other as well as how joints and actuators are defined. MuJoCo is also using an XML file but how robots are defined is different from URDF, I actually need to read up the differences.
MuJoCo has decent Python support since version 3, so I thought I give it a spin.
Installing MuJoCo is easy as described in the /mujoco directory’s readme file: “pip3 install mujoco” which installs all necessary dependencies.
I wrote a little XML that simply shows a block and it also loads an STL file as asset, planning to use that as a start.
You can view that using “python3 -m mujoco.viewer” and drag the “hello.xml” file into the viewer window.
Next, I needed to define joints between multiple blocks, so this is what “helloLink.xml” will show you two links between blocks and it shows also that collision is not perfect:
Next, I needed to import more of Kayra’s STL files (“kayra.xml“) and body elements, the files are defined in relative paths so that the XML will access directly the files that are exported from freeCAD. You see that I also tried to match Kayra’s current 3D printing colors 🙂
Now we need to define the joints between the parts, an example is “kayraLink.xml“:
Next, it was important to understand the special construction of Kayra, since the parts are not connected in a “tree”, but partially in a “graph”, i.e. the knee and the foot are connected via two parts forming a parallelogram. It puzzled my mind, but interaction with the reddit community helped a lot. The construction is achieved using “equality constraints” as can bee seen in the example file “fourBars.xml“
Next I could apply this concept to the lower leg of Kayra in the file “kayraCircle.xml“. It’s not quite perfect yet as explained in this video:
I decided not to invest in this topic further for the moment, maybe some readers can help me out there later. I wanted to have at least both legs fully defined and maybe the servos added, which is the current end result of bringing Kayra into MuJoCo (“kayraLowerBody.xml“)
The next post will describe how the actuators are working and how to control them from outside via Python.
Leave a Reply