Multiple inconsistent contacts computed by mj_forward

Discussion in 'Simulation' started by shormilt, Jan 15, 2018.

  1. This is using mujoco 1.50 (also tested under 1.40 and 1.31, and all 3 versions have the same issue).

    Using the attached xml and cpp source code, it will print out the following:

    Distance: 0.079283 Geom 1: link0 Geom 2: link9
    Distance: -0.277932 Geom 1: link0 Geom 2: link9
    Distance: 0.087159 Geom 1: link1 Geom 2: link2
    Distance: 0.087159 Geom 1: link1 Geom 2: link2
    Distance: 0.087159 Geom 1: link1 Geom 2: link2
    Distance: 0.087159 Geom 1: link1 Geom 2: link2
    Distance: 0.087159 Geom 1: link1 Geom 2: link2
    Distance: 0.087159 Geom 1: link1 Geom 2: link2
    Distance: 0.087159 Geom 1: link1 Geom 2: link2
    Distance: 0.087159 Geom 1: link1 Geom 2: link2
    We can see that two contacts are created between link0 and link9 but with different distance. If you inspect the scene visually, these two geoms are not in contact. However one of the computed contacts have negative distance. This behavior only occurs if both margin and gap are set to greater than 0. Could this be a bug?
     

    Attached Files:

    Last edited: Jan 15, 2018
  2. Emo Todorov

    Emo Todorov Administrator Staff Member

    It is not a bug. Box-box collisions can return up to 8 contact points for the same geom pair. When you increase the contact margin above 0, you are essentially making the geoms larger for collision purposes, so the collision detector can generate contact points with negative distance.
     
  3. Thank you for your quick reply. So the computed distance is with respect to the enlarged geoms? Still the distance -0.2779 does not really make sense, and it seems like the same contact as the first one (with distance 0.0792) but somehow erroneously accounting for the margin / gap of 0.1.
     
  4. I simplified the model to the inline xml file below:

    HTML:
    <mujoco model="MuJoCo Model">
        <worldbody>
            <body>
                <freejoint />
                <geom name="link1" margin="0.1" gap="0.1" size="0.02 0.415 0.185" pos="-0.96 0. 0.095" type="box" rgba="0.4 0.34 0.19 1" quat="0 0 0 1"/>
            </body>
            <body>
                <freejoint />
                <geom name="link2" margin="0.1" gap="0.1" quat="0.227831438918552 -0.169192837203671 0.0834433313067649 -0.955250663302415" pos="-0.76587217 0.06373818 0.32043694" rgba="0.34 1 0.59 1" size="0.063674 0.106164 0.023" type="box" />
            </body>
        </worldbody>
    </mujoco>
    Here Mujoco detects two contacts, one with distance 0.079 and another with distance -0.2779. If I change all margins and gaps to 0.09, these two outputs stay the same, so this does not seem to be affected by the two parameters.
     
    Last edited: Jan 15, 2018
  5. Emo Todorov

    Emo Todorov Administrator Staff Member

    The computed distance is always with respect to the original geom size. The margin and gap parameters determine if a contact is included or not. So when the contact margin is positive, contacts will be detected up to a distance specified by the margin.
     
  6. Is there a reference of the underlying algorithm for box-box collision detection? I still don't understand why the distance can be negative in this case, and it's affecting our trajectory optimization algorithm.
     
  7. Emo Todorov

    Emo Todorov Administrator Staff Member