mujoco
mujoco copied to clipboard
`mjContact.vert` bugs for `flexcomp`-`geom` collisions
Intro
Hi!
I am an Australian PhD researcher at the University of Queensland, and I use MuJoCo for my robotics research.
My setup
MuJoCo version: 3.2.3 API: Python Architecture: x86_64 OS: Ubuntu 22.04.1 LTS
What's happening? What did you expect?
I'm trying to use MuJoCo's elasticity plugin to accurately simulate contact forces on soft, deformable robots. However, I've noticed that mjContact.vert
returns incorrect flex vertex ids when simulating a simple flexcomp
soft cube colliding with a plane
geom.
Note that the cube that I have considered in my tests was meshed in gmsh. The picture below shows the vertex ids of the meshed cube in GMSH. In particular, note that the base of the cube has vertex ids 1, 2, 3, 4 and 9. From personal experiments, I've noticed that MuJoCo uses the same vertex id labelling scheme as GMSH, however all ids are based from 0 in MuJoCo (i.e., each id in GMSH is subtracted by 1 for zero-indexing).
When I set the value of euler
of my flexcomp
cube to non-trivial values, bugs arise.
Steps for reproduction
- Download the contents of softbox.zip.
- In the same directory create a new empty Python file called
minimal.py
and copy and paste the Python code below into your script. Make sure you adjust thexml_filepath
variable in line 4 accordingly! - Set
euler
in line 25 ofsoftbox.xml
to the following values:"euler = 1 0 0"
,"euler = 2 0 0"
,"euler = 45 0 0"
,"euler = 0 1 0"
. For each case, runminimal.py
. In each case, the box is dropped from a height and ultimately lands on flex vertex ids 0, 1, 2, 3 and 8 (or 1, 2, 3, 4 and 9 are the GMSH ids as mentioned earlier). However, if you inspect the terminal output, there are some flex vertex ids that are repeated, and we get the incorrect flex vertex ids involved in the contact between theflexcomp
andplane
in each case. - Confusingly, if you uncomment the
if
condition in line 14 ofminimal.py
and repeat step 3 for all cases, we get the correct output/flex vertex ids for all cases. What is causing this!? - Repeat step 3 for the following values:
"euler = 90 0 0"
,"euler = 90 90 0"
,"euler = 90 0 90"
and"euler = 90 0 180"
. You will get the correct flex vertex ids regardless of whether the if statement in line 14 ofminimal.py
is commented out or not. So it seems 90-degree rotations are handled correctly, but anything else produces erroneous bugs?
Minimal model for reproduction
The following zip folder contains the mesh of my soft cube - softbox.msh
- and a minimal MJCF file called softbox.xml
:
softbox.zip.
Please run the Python code below following the instructions above to reproduce the bugs.
Code required for reproduction
import mujoco
import os
xml_filepath = "path/to/softbox.xml"
model = mujoco.MjModel.from_xml_path(xml_filepath)
data = mujoco.MjData(model)
duration = 3.0
n_steps = int(duration/model.opt.timestep) #timestep = 0.0005
for i in range(n_steps):
mujoco.mj_step(model, data)
# if i == n_steps - 1:
print("t = ", data.time, "\n")
for con_id, con in enumerate(data.contact):
print("Contact #", con_id+1)
print("con.vert = ", con.vert, "\n")
Confirmations
- [X] I searched the latest documentation thoroughly before posting.
- [X] I searched previous Issues and Discussions, I am certain this has not been raised before.