Debugging oscillation/explosion during rolling contacts

Discussion in 'Simulation' started by Alex Ray, Dec 8, 2017.

  1. I have a very simple model of a ball which rolls around on a plane. My goal is motion similar to Sphereo robots.

    When I give it random actions in [-1, 1], inevitably the rotational degrees of freedom oscillate and grow until I get a QACC warning and the simulation resets. (qvel for the hinges flips in sign and grows every step)

    This seems to be an issue with how contacts are simulated.

    Code:
    <mujoco>
        <worldbody>
            <geom size="1 1 1" type="plane" condim="6"/>
            <body name="a" pos="0 0 .1">
                <joint name="sx" type="slide" axis="1 0 0"/>
                <joint name="sy" type="slide" axis="0 1 0"/>
                <joint name="sz" type="slide" axis="0 0 1"/>
                <joint name="rx" type="hinge" axis="1 0 0"/>
                <joint name="ry" type="hinge" axis="0 1 0"/>
                <joint name="rz" type="hinge" axis="0 0 1"/>
                <geom type="sphere" size=".1" condim="6" rgba="1 0 0 1"/>
            </body>
        </worldbody>
        <actuator>
            <motor name="mx" gear="100" joint="sx"/>
            <motor name="my" gear="100" joint="sy"/>
        </actuator>
    </mujoco>
    
     
  2. Emo Todorov

    Emo Todorov Administrator Staff Member

    Creating a ball joint out of hinge joints is not a good idea, because the resulting joint has singularities where things go wrong numerically. Your model can be improved by using the RK4 integrator and a smaller time step, but still, it goes unstable after a while.

    Here is a better way to implement the same model -- using a free joint (which uses a quaternion to represent rotation) and then specifying 6D gear ratios for the motors (3 for translation, 3 for rotation).

    <mujoco>
    <worldbody>
    <geom size="1 1 1" type="plane" condim="6"/>
    <body name="a" pos="0 0 .1">
    <freejoint name="free"/>
    <geom type="sphere" size=".1" condim="6" rgba="1 0 0 1"/>
    </body>
    </worldbody>
    <actuator>
    <motor name="mx" gear="100 0 0 0 0 0" joint="free"/>
    <motor name="my" gear="0 100 0 0 0 0" joint="free"/>
    </actuator>
    </mujoco>