Defining contacts and detecting collisions

Discussion in 'Modeling' started by Nemanja, Feb 6, 2018.

  1. Hello,

    I am trying to detect (self)collisions in a simple FrankaEmika 7-DOF robot arm - self-collisions between the links and collision with a cylindrical static pedestal it's placed on.
    I am having problems figuring out the MuJoCo collision api, so I'll try to pose 3 questions:
    1. What do the Contacts in `env.unwrapped.data.obj.contact mean exactly, are these collision or just contacts between links defined by geoms?
    2. How is it possible to determine which geom pertains to which link or is it just in the order as they are nested?

    3. How does this relate to conaffinity and contype?
    I have read the explanations on http://mujoco.org/book/programming.html and http://mujoco.org/book/computation.html but I am having much difficulties understanding it.

    Thank you!
     
    Kyokushin likes this.
  2. Emo Todorov

    Emo Todorov Administrator Staff Member

    The contacts are returned in the mjContact structure defined here:

    http://www.mujoco.org/book/source/mjdata.h

    Each contact involves two geoms, whose geom ids are given in mjContact. The think you are calling a "link" is a body in MuJoCo. One body can have multiple geoms attached to id. So if you have the geomid, you can find the corresponding body in mjModel.geom_bodyid[geomid]. This is C, but you should be able to figure out the Python version.

    Contype and conaffinity determine which pairs of geoms are checked for collisions in the first place. Once the collision check passes, an mjContact is added to the list of contacts.
     
    blueyang and Kyokushin like this.
  3. Hi,

    I tried to print the contact info. It seems like some contacts are always in the list even though the two geoms are not contacting. Is the contacts list keep updating in simulation?

    Thank you!
     
  4. Hello,

    I know how to do that! There is a number ncon which indicate the number of contacts. I can read the first ncon from the contacts list to get current contacts!

    Thank you!