google-deepmind / mujoco

Multi-Joint dynamics with Contact. A general purpose physics simulator.
https://mujoco.org
Apache License 2.0
8.25k stars 823 forks source link

closed loop crash or not accurate when simulation. #2172

Closed WeisonWEileen closed 3 weeks ago

WeisonWEileen commented 4 weeks ago

Intro

Hi!

I am a undergrad student at sustech, I use MuJoCo for my research on sim2sim.

My setup

ubuntu22.04 mujoco 3.2.3

What's happening? What did you expect?

I use equality/connect to implement closed loop robot. However, it crash when moving. I am sure my relative coordinate is accurate because I get it from solidworks. I expect the two hole site of the two link are aligned to each other.

https://github.com/user-attachments/assets/e9734706-b7ad-432b-ab8d-09ca11ccebc6

Steps for reproduction

sw file too big to reproduce

Minimal model for reproduction

Code required for reproduction

<equality>
    <connect name="connect_l" active="true" body1="calf_l_Link" body2="shank_l_Link"
        anchor="0.56 0 0.00885" />

    <connect name="connect_r" active="true" body1="calf_r_Link" body2="shank_r_Link"
        anchor="0.56 0 0.00885" />
</equality>

Confirmations

yuvaltassa commented 4 weeks ago
  1. The video looks fine, where is the crash?
  2. Your model is not loadable without the assets, so we can't reproduce.
WeisonWEileen commented 3 weeks ago

Thanks for your reply. After days of trying, I tried to use <equality/connect> instead of <equality/anchor>(because I can access the accurate point of 2 link, I think using two sites in two body will working better. ). I was succussful to connect right leg of my closed loop . However, when I connect left leg, the simulation diverge. I try many approaches, but in vain。 here is my repo with all code and .stl model files.

https://github.com/WeisonWEileen/mujoco_test.git

only right leg (left leg without closed loop): works fine image

with left leg (cannot work): image

Thanks!

yuvaltassa commented 3 weeks ago

Are you aware the if you click the 'E' button in simulate, you can see the two points of the equality constraint? That should help you debug what is happening.

If that's doesn't help you solve it, and you still need us to look at your example, it would be much easier for us if you posted a file that only contains primitives and does not require meshes. You can easily ask MuJoCo to fit primitives in place of the meshes, then save the XML and delete all the mesh assets. This will give you a self-contained XML that you can paste here.

Regarding using sites to define the constraints, we just discovered several bugs thanks to @yinfanyi's #2179, so please don't use those until the fix has been submitted.

WeisonWEileen commented 3 weeks ago

oh, After I click 'E' button, I see there are difference between the two points I want to connect. What does it implied(right leg is successful connected)? Does it means the two sites of left leg are not coincident in position ? image original screenshot(without clicking E) image

yuvaltassa commented 3 weeks ago

This looks fine. These are just different kinds of z-fighting, the equality is satisfied in the default configuration.

Okay, I looked at your model posted above. I uncommented line 394 in test.xml and played with the mechanism, both constraints work fine. My assumption is that this is one of the bugs that was fixed in the change that fixed #2179. If you build from source everything will work as expected.

WeisonWEileen commented 3 weeks ago

Thanks for replied! After install the latest version of mujoco(3.2.5), the problem metioned above was successful solved. However, the constrained is not tight when moving, which caused a lot of trouble for my Angle conversion in the simulation. It is a bug ? @yuvaltassa

https://github.com/user-attachments/assets/55756c62-20f7-44c9-ba1c-0865783952cf

yuvaltassa commented 2 weeks ago

Not a bug. Default settings are fairly soft, make the equality constraints stiffer.