Assign point in 2 mesh and connect them

Discussion in 'Modeling' started by Hao, Jul 19, 2017.

  1. Hao

    Hao

    I have some questions about how to connect 2 meshes as connect them together.
    Suppose I have 2 meshes, all I know is position "p1" in "mesh 1" is connecting to "p2" in "mesh 2", p1 and p2 are expressed in their own frame (in other words, p1 is expressed in the frame of mesh 1).
    Is it possible to assign these two points connected easily? As far as I know, if I try to connect the 2nd object under the 1st object, I have to define in the following way
    Code:
    <body name="obj1" pos="0 0 0">
       <geom type ="mesh" mesh="mesh1"/>
      <body name ="obj2" pos = "pos of obj2's com in obj1">
         <geom type ="mesh" mesh="mesh2"/>
      </body>
    </body>
    
    In this way, I have to know obj2's com position in obj1's frame, which is not simple to get if the geometry is complicated.
    Is there any easy way that I can give 2 points and expressed them in their own frame and connect them together?
     
  2. Emo Todorov

    Emo Todorov Administrator Staff Member

    When you define an equality constraint of type "connect" you specify two bodies and an anchor point. See documentation here:

    http://www.mujoco.org/book/modeling.html#equality-connect

    You have to make sure that the two points you are trying to connect coincide in the configuration in which the model is defined. Then you provide the coordinates of this point as anchor.

    If you cannot make the two points coincide in the initial model configuration, you can fix the issue after compilation. In mjModel, the anchor is stored twice, in the local frame of each body. So you can change that data programmatically if you want.
     
  3. Hao

    Hao

    Does that mean, even originally I assign 2 sphere
    body1 pos="0 0 1"
    body2 pos="0 0 2"
    I could still make their center coincide on the same point by equality?

    Why I feel like assign <body pos="pos of connected point in parent">
    and <geom pos="pos of connected point in child"/>
    might be better?
     
  4. Emo Todorov

    Emo Todorov Administrator Staff Member

    Equality constraints are defined between bodies, not geoms. This is because one body can have multiple geoms rigidly attached to it, so the body is the thing that actually has kinematic and inertial properties, while the geoms are needed for visualization and collisions (as well as automated mass and inertia computation).
     
  5. Hao

    Hao

    I found that I don't really understand the meaning of anchor point, in the manual it said it is rather in global coordinate or body1's coordinate. However, if it is in global frame, what will happen if it moves? (I thought global frame is like base frame), but if it is in body1's frame, how could I connect two object with only one point defined in onee frame?

    suppose I want to attach the green foot panel with foot, how could I do that?

    upload_2017-8-8_23-49-11.png
     
  6. Emo Todorov

    Emo Todorov Administrator Staff Member

    In the XML , the anchor point is defined once in global coordinates. In the compiled model, it is saved twice, in the local coordinates of each body. The simulator then pushes these two points towards each other.

    After compilation, you could modify the local coordinates of the anchor point if you want.