Margin/gap parameter changing contact forces (Mujoco 1.50)

Discussion in 'Bug Reports' started by Ingmar Kanitscheider, Apr 4, 2019.

  1. I am simulating an environment containing sphere-like agents and ramps. An important feature of the environment is that agents can slide up ramps (see screenshot below; agent in red and ramp in blue). In addition, I would like to measure distances between agents and specific geoms using inactive contacts. My understanding is that if I set the margin/gap parameter in the agent xml to an equal positive value, inactive contacts are enabled but the physics should be unchanged.

    However, it seems that setting agent's margin/gap parameter is changing the actual contact forces. When agents approach the oblique side of the ramp, the contact force is horizontal to the ground (as if the ramp were a box) and agents cannot slide up the ramp anymore. If margin/gap is zero, this problem does not occur (the contact force is vertical to the oblique surface).

    Is this a bug in Mujoco and/or is there a workaround?
     

    Attached Files:

  2. Emo Todorov

    Emo Todorov Administrator Staff Member

    With perfectly accurate collision detection the physics will indeed remain unchanged. But that implies replacing each mesh vertex with a spherical patch when the margin parameter is increased. The collision library does not handle this exactly. It is exact with spheres, planes and some other combinations of geometric primitives, but not in the general case.

    Here is an (ugly) workaround. Replicate the geometry twice, and use one half for regular contacts with margin=gap=0 and the other half for inactive contacts. For the latter, set margin to whatever you need, and gap to a very large value (so that the contact will never generate contact force, but will be included in mjData.contact)

    I am currently using the margin/gap machinery in a new trajectory optimizer I am developing on top of MuJoCo. If I come up with improvements in the physics/geometry along the way, they will appear in a future release. Can you send me the XML?