google / brax

Massively parallel rigidbody physics simulation on accelerator hardware.
Apache License 2.0
2.25k stars 249 forks source link

unstable at smaller inertia values #329

Closed Flogg0 closed 1 year ago

Flogg0 commented 1 year ago

Hi, I am currently working on a project where I want to replicate this robot in brax grafik It was originally simulated in pybullet and described as an urdf file.

I rebuilt the robot as a mujoco file similar to the examples in envs and enabled "inertiafromgeom". When visualizing the simulation in the first few steps everything seems normal then the robot quickly spirales out of control and then does not exist anymore.

I did further testing where i spawned the 3 parts of the robot as free moving objects and let them fall to the floor. They again fall normally towards the floor until they contact it and also cease to exist. Which makes me believe that something odd is happening when calculating with the bodies inertias since no torque should be applied to the bodies before they hit the floor. I checked against the reference inertia values from the urdf file and the inertias computed from the geometry were quite similar. Iterations up to 1e5 did not fix the issue with dt= 0.01 and generalized backend. Did i do a bad setup or is this a bug?

Further Information: Position of objects before they hit the floor: grafik

After they hit the floor: grafik

I set up a repo where you could replicate this problem with the robot and with the parts falling to the floor: https://github.com/Flogg0/inertia_demo

btaba commented 1 year ago

Thanks @Flogg0 for creating the issue and for the detailed explanation (and nice github repo). I was able to get stable simulation with:

    <numeric data="0" name="matrix_inv_iterations"/>
    <numeric data="50" name="solver_maxls"/>

using an exact mass matrix inv solver rather than the approximate one, and tweaking the projected gradient solver param. You might need some other tweaking (damping, lowering timestep -> you can set n_frames to skip the added frames, etc.). Hope that helps for now.

Similarly for the other physics backends (positional, and spring especially), you'll need a lot more tweaking and would probably need to modify the inertias as they are quite small

Flogg0 commented 1 year ago

Thank you very much, this seemed to fix my problem