How to Calculate the contact orces and Individual Forces Experienced by Bodies with Parent-Child Relationships #2168
-
IntroHi! I am a researcher, I use MuJoCo for my research on contact forces. My setupmujoco 3.20 My questionHello, I'm attempting to use d->cfrc_ext to analyze external contact forces. My understanding is that this is the resultant external force acting on the geom within a body. However, if I embed another body within this body, the contact forces experienced by the new body will not be reflected in the d->cfrc_ext of its parent body. It seems that embedding a geom within a body works fine. I would like to know if there's any way to calculate the resultant forces experienced by bodies with a parent-child relationship and their individual forces. Minimal model and/or code that explain my questionModel: <body name="ship1" pos="0 0 1">
<site name="force_sensor1" group="1"/>
<freejoint/>
<light name="ship1top light" pos="0 0 2" mode="trackcom" diffuse=".4 .4 .4"/>
<light name="ship1front light" pos=".1 0 .02" dir="2 0 -1" diffuse="1 1 1"/>
<geom type="box" pos="0.6 -.0 0" euler="0 45 0" size=".01315 .045 .5" rgba="0 0 0.8 1" solref="0.1 1"/>
<body name="child" pos="0 0 4">
<geom type="box" pos="0.6 -.0 0" euler="0 45 0" size=".01315 .045 .5" rgba="0 0 0.8 1" solref="0.1 1"/>
</body>
</body>
<body name="ship2" pos="0 0 4">
<site name="force_sensor2" group="1"/>
<freejoint/>
<light name="ship2top light" pos="0 0 2" mode="trackcom" diffuse=".4 .4 .4"/>
<light name="ship2 light" pos=".1 0 .02" dir="2 0 -1" diffuse="1 1 1"/>
<geom type="box" pos="0.6 -.0 0" euler="0 45 0" size=".01315 .045 .5" rgba="0 0 0.8 1" solref="0.1 1"/>
</body>
</worldbody>
<sensor>
<force site="force_sensor1"/>
</sensor>
<sensor>
<force site="force_sensor2"/>
</sensor>
Code: auto extForces = std::make_unique<externalforce[]>(m->nbody);
const mjtNum* external_force = d->cfrc_ext;
extForces[*index].forceX = std::make_unique<double>(0.0);
extForces[*index].forceY = std::make_unique<double>(0.0);
extForces[*index].forceZ = std::make_unique<double>(0.0);
extForces[*index].torqueX = std::make_unique<double>(0.0);
extForces[*index].torqueY = std::make_unique<double>(0.0);
extForces[*index].torqueZ = std::make_unique<double>(0.0);
*extForces[*index].forceX = external_force[3 + 6 * (*index + 1)];
*extForces[*index].forceY = external_force[4 + 6 * (*index + 1)];
*extForces[*index].forceZ = external_force[5 + 6 * (*index + 1)];
*extForces[*index].torqueX = external_force[0 + 6 * (*index + 1)];
*extForces[*index].torqueY = external_force[1 + 6 * (*index + 1)];
*extForces[*index].torqueZ = external_force[2 + 6 * (*index + 1)]; The index is the index of the body, and since I only have two bodies, they are indexed as 0 and 1. Confirmations
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Beta Was this translation helpful? Give feedback.
cfrc_ext
are external forces acting on the body (e.g. contacts),cfrc_int
are the forces inside the kinematic tree. Perhaps it would help to read this and this.