1 #ifndef SimTK_SIMBODY_MOBILIZED_BODY_H_
2 #define SimTK_SIMBODY_MOBILIZED_BODY_H_
48 class SimbodyMatterSubsystem;
51 class MobilizedBodyImpl;
56 #ifndef SimTK_SIMBODY_DEFINING_MOBILIZED_BODY
57 extern template class PIMPLHandle<MobilizedBody, MobilizedBodyImpl, true>;
259 void unlock(
State& state)
const;
262 bool isLocked(
const State& state)
const
272 Vector getLockValueAsVector(
const State& state)
const;
285 bool isLockedByDefault()
const
326 return getBodyTransform(state).R();
333 return getBodyTransform(state).p();
354 return getBodyVelocity(state)[0];
361 return getBodyVelocity(state)[1];
383 return getBodyAcceleration(state)[0];
391 return getBodyAcceleration(state)[1];
401 "MobilizedBody::getMobilizerAcceleration() not yet implemented -- volunteers?");
417 return getBodyMassProperties(state).getMass();
424 return getBodyMassProperties(state).getMassCenter();
431 return getBodyMassProperties(state).getUnitInertia();
467 int getNumQ(
const State& state)
const;
470 int getNumU(
const State& state)
const;
494 Real getOneQ(
const State& state,
int which)
const;
499 Real getOneU(
const State& state,
int which)
const;
514 Real getOneQDot (
const State& state,
int which)
const;
524 Real getOneUDot(
const State& state,
int which)
const;
529 Real getOneQDotDot(
const State& state,
int which)
const;
538 Vector getQDotDotAsVector(
const State& state)
const;
561 void setOneQ(
State& state,
int which,
Real v)
const;
566 void setOneU(
State& state,
int which,
Real v)
const;
571 void setQFromVector(
State& state,
const Vector& v)
const;
575 void setUFromVector(
State& state,
const Vector& v)
const;
610 void setQToFitTransform(
State& state,
const Transform& X_FM)
const;
616 void setQToFitRotation(
State& state,
const Rotation& R_FM)
const;
623 void setQToFitTranslation(
State& state,
const Vec3& p_FM)
const;
637 void setUToFitAngularVelocity(
State& state,
const Vec3& w_FM)
const;
644 void setUToFitLinearVelocity(
State& state,
const Vec3& v_FM)
const;
720 const Transform& X_GB = this->getBodyTransform(state);
734 const Rotation& R_GB = this->getBodyRotation(state);
745 Vec3 findBodyOriginLocationInAnotherBody
748 getBodyOriginLocation(state));
759 const SpatialVec& V_GB = this->getBodyVelocity(state);
762 const Vec3 w_AB_G = V_GB[0]-V_GA[0];
766 const Transform& X_GB = getBodyTransform(state);
769 const Vec3 p_AB_G = X_GB.
p() - X_GA.
p();
771 const Vec3 p_AB_G_dot = V_GB[1] - V_GA[1];
774 const Vec3 v_AB_G = p_AB_G_dot - V_GA[0] % p_AB_G;
785 Vec3 findBodyAngularVelocityInAnotherBody(
const State& state,
788 const Vec3& w_GB = getBodyAngularVelocity(state);
791 const Vec3 w_AB_G = w_GB-w_GA;
802 Vec3 findBodyOriginVelocityInAnotherBody(
const State& state,
806 return findBodyVelocityInAnotherBody(state,inBodyA)[1];
821 const Transform& X_GB = this->getBodyTransform(state);
822 const SpatialVec& V_GB = this->getBodyVelocity(state);
823 const SpatialVec& A_GB = this->getBodyAcceleration(state);
834 Vec3 findBodyAngularAccelerationInAnotherBody
839 const Vec3& w_GB = this->getBodyAngularVelocity(state);
841 const Vec3& b_GB = this->getBodyAngularAcceleration(state);
844 const Vec3 w_AB_G = w_GB - w_GA;
845 const Vec3 w_AB_G_dot = b_GB - b_GA;
850 const Vec3 b_AB_G = w_AB_G_dot - w_GA % w_AB_G;
853 return ~R_GA * b_AB_G;
862 Vec3 findBodyOriginAccelerationInAnotherBody(
const State& state,
867 return findBodyAccelerationInAnotherBody(state,inBodyA)[1];
877 SpatialVec findMobilizerReactionOnBodyAtMInGround(
const State& state)
const;
885 SpatialVec findMobilizerReactionOnBodyAtOriginInGround
886 (
const State& state)
const;
896 SpatialVec findMobilizerReactionOnParentAtFInGround(
const State& state)
const;
905 SpatialVec findMobilizerReactionOnParentAtOriginInGround
906 (
const State& state)
const;
914 Vec3 findStationLocationInGround
916 return getBodyTransform(state) * stationOnB;
928 Vec3 findStationLocationInAnotherBody
933 findStationLocationInGround(state,stationOnB));
942 Vec3 findStationVelocityInGround
944 const Vec3& w = getBodyAngularVelocity(state);
945 const Vec3& v = getBodyOriginVelocity(state);
946 const Vec3 r = expressVectorInGroundFrame(state,stationOnB);
956 Vec3 findStationVelocityInAnotherBody(
const State& state,
957 const Vec3& stationOnBodyB,
961 findBodyVelocityInAnotherBody(state, inBodyA);
964 expressVectorInAnotherBodyFrame(state, stationOnBodyB, inBodyA);
965 return V_AB[1] + (V_AB[0] % p_BS_A);
976 Vec3 findStationAccelerationInGround
978 const Vec3& w = getBodyAngularVelocity(state);
979 const Vec3& b = getBodyAngularAcceleration(state);
980 const Vec3& a = getBodyOriginAcceleration(state);
982 const Vec3 r = expressVectorInGroundFrame(state,stationOnB);
983 return a + b % r + w % (w % r);
991 Vec3 findStationAccelerationInAnotherBody(
const State& state,
992 const Vec3& stationOnBodyB,
996 findBodyAngularVelocityInAnotherBody(state,inBodyA);
998 findBodyAccelerationInAnotherBody(state,inBodyA);
1001 expressVectorInAnotherBodyFrame(state, stationOnBodyB, inBodyA);
1003 return A_AB[1] + (A_AB[0] % p_BS_A) + w_AB % (w_AB % p_BS_A);
1009 void findStationLocationAndVelocityInGround
1011 Vec3& locationOnGround,
Vec3& velocityInGround)
const
1013 const Vec3& p_GB = getBodyOriginLocation(state);
1014 const Vec3 p_BS_G = expressVectorInGroundFrame(state,locationOnB);
1015 locationOnGround = p_GB + p_BS_G;
1017 const Vec3& w_GB = getBodyAngularVelocity(state);
1018 const Vec3& v_GB = getBodyOriginVelocity(state);
1019 velocityInGround = v_GB + w_GB % p_BS_G;
1027 void findStationLocationVelocityAndAccelerationInGround
1029 Vec3& locationOnGround,
Vec3& velocityInGround,
Vec3& accelerationInGround)
1032 const Rotation& R_GB = getBodyRotation(state);
1033 const Vec3& p_GB = getBodyOriginLocation(state);
1036 const Vec3 r = R_GB*locationOnB;
1037 locationOnGround = p_GB + r;
1039 const Vec3& w = getBodyAngularVelocity(state);
1040 const Vec3& v = getBodyOriginVelocity(state);
1041 const Vec3& b = getBodyAngularAcceleration(state);
1042 const Vec3& a = getBodyOriginAcceleration(state);
1044 const Vec3 wXr = w % r;
1045 velocityInGround = v + wXr;
1046 accelerationInGround = a + b % r + w % wXr;
1052 return findStationLocationInGround(state,getBodyMassCenterStation(state));
1058 Vec3 findMassCenterLocationInAnotherBody
1060 return findStationLocationInAnotherBody(state,
1061 getBodyMassCenterStation(state),toBodyA);
1070 Vec3 findStationAtGroundPoint
1072 return ~getBodyTransform(state) * locationInG;
1080 Vec3 findStationAtAnotherBodyStation
1082 const Vec3& stationOnA)
const {
1089 Vec3 findStationAtAnotherBodyOrigin
1091 return findStationAtGroundPoint(state,
1098 Vec3 findStationAtAnotherBodyMassCenter
1101 getBodyMassCenterStation(state),*
this);
1109 return getBodyTransform(state) * frameOnB;
1119 return SpatialVec(getBodyAngularVelocity(state),
1120 findStationVelocityInGround(state,frameOnB.
p()));
1130 return SpatialVec(getBodyAngularAcceleration(state),
1131 findStationAccelerationInGround(state,frameOnB.
p()));
1137 Vec3 expressVectorInGroundFrame
1139 return getBodyRotation(state)*vectorInB;
1146 Vec3 expressGroundVectorInBodyFrame
1148 return ~getBodyRotation(state)*vectorInG;
1156 Vec3 expressVectorInAnotherBodyFrame
1161 expressVectorInGroundFrame(state,vectorInB));
1170 const Rotation& R_GB = getBodyRotation(state);
1181 const Rotation R_AB = findBodyRotationInAnotherBody(state,inBodyA);
1217 const Rotation& R_GB = getBodyRotation(state);
1230 return getBodyMassProperties(state).calcCentralInertia();
1236 Inertia calcBodyInertiaAboutAnotherBodyStation
1238 const Vec3& aboutLocationOnBodyA)
const
1245 const Vec3 p_Bo_PA =
1246 findStationAtAnotherBodyStation(state, inBodyA, aboutLocationOnBodyA);
1263 const MassProperties M_Bo_G = expressMassPropertiesInGroundFrame(state);
1264 const SpatialVec& V_GB = getBodyVelocity(state);
1270 SpatialVec calcBodyMomentumAboutBodyMassCenterInGround
1273 const Rotation& R_GB = getBodyRotation(state);
1280 const Vec3& w_GB = getBodyAngularVelocity(state);
1291 const Vec3& locationOnBodyB,
1293 const Vec3& locationOnBodyA)
const
1295 if (isSameMobilizedBody(bodyA))
1296 return (locationOnBodyA-locationOnBodyB).norm();
1298 const Vec3 r_Go_PB =
1299 this->findStationLocationInGround(state,locationOnBodyB);
1300 const Vec3 r_Go_PA =
1302 return (r_Go_PA - r_Go_PB).
norm();
1310 Real calcStationToStationDistanceTimeDerivative
1312 const Vec3& locationOnBodyB,
1314 const Vec3& locationOnBodyA)
const
1316 if (isSameMobilizedBody(bodyA))
1319 Vec3 rB, rA, vB, vA;
1320 this->findStationLocationAndVelocityInGround(state,locationOnBodyB,rB,vB);
1322 const Vec3 r = rA-rB, v = vA-vB;
1328 if (d==0)
return v.
norm();
1329 else return dot(v, r/d);
1338 Real calcStationToStationDistance2ndTimeDerivative
1340 const Vec3& locationOnBodyB,
1342 const Vec3& locationOnBodyA)
const
1344 if (isSameMobilizedBody(bodyA))
1347 Vec3 rB, rA, vB, vA, aB, aA;
1348 this->findStationLocationVelocityAndAccelerationInGround
1349 (state,locationOnBodyB,rB,vB,aB);
1351 (state,locationOnBodyA,rA,vA,aA);
1353 const Vec3 r = rA-rB, v = vA-vB, a = aA-aB;
1368 if (s==0)
return a.
norm();
1369 else return dot(a, v/s);
1374 const Vec3 vp = v -
dot(v,u)*u;
1375 return dot(a,u) +
dot(vp,v)/d;
1381 Vec3 calcBodyMovingPointVelocityInBody
1383 const Vec3& locationOnBodyB,
1384 const Vec3& velocityOnBodyB,
1388 "MobilizedBody::calcBodyMovingPointVelocityInBody()"
1389 " is not yet implemented -- any volunteers?");
1397 Vec3 calcBodyMovingPointAccelerationInBody
1399 const Vec3& locationOnBodyB,
1400 const Vec3& velocityOnBodyB,
1401 const Vec3& accelerationOnBodyB,
1405 "MobilizedBody::calcBodyMovingPointAccelerationInBody()"
1406 " is not yet implemented -- any volunteers?");
1416 Real calcMovingPointToPointDistanceTimeDerivative
1418 const Vec3& locationOnBodyB,
1419 const Vec3& velocityOnBodyB,
1421 const Vec3& locationOnBodyA,
1422 const Vec3& velocityOnBodyA)
const
1425 "MobilizedBody::calcMovingPointToPointDistanceTimeDerivative()"
1426 " is not yet implemented -- any volunteers?");
1437 Real calcMovingPointToPointDistance2ndTimeDerivative
1439 const Vec3& locationOnBodyB,
1440 const Vec3& velocityOnBodyB,
1441 const Vec3& accelerationOnBodyB,
1443 const Vec3& locationOnBodyA,
1444 const Vec3& velocityOnBodyA,
1445 const Vec3& accelerationOnBodyA)
const
1448 "MobilizedBody::calcMovingPointToPointDistance2ndTimeDerivative()"
1449 " is not yet implemented -- any volunteers?");
1479 const Body& getBody()
const;
1503 return updBody().addDecoration(X_BD, geometry);
1508 return updBody().addDecoration(geometry);
1517 int addOutboardDecoration(
const Transform& X_MD,
1520 int getNumOutboardDecorations()
const;
1532 int addInboardDecoration(
const Transform& X_FD,
1535 int getNumInboardDecorations()
const;
1548 updBody().setDefaultRigidBodyMassProperties(m);
1555 return getBody().getDefaultRigidBodyMassProperties();
1565 void adoptMotion(
Motion& ownerHandle);
1575 bool hasMotion()
const;
1583 const Motion& getMotion()
const;
1602 const Transform& getDefaultInboardFrame()
const;
1606 const Transform& getDefaultOutboardFrame()
const;
1643 bool isInSubsystem()
const;
1658 bool isGround()
const;
1664 int getLevelInMultibodyTree()
const;
1677 Real getOneFromQPartition
1678 (
const State& state,
int which,
const Vector& qlike)
const;
1684 Real& updOneFromQPartition
1685 (
const State& state,
int which,
Vector& qlike)
const;
1690 Real getOneFromUPartition
1691 (
const State& state,
int which,
const Vector& ulike)
const;
1697 Real& updOneFromUPartition(
const State& state,
int which,
Vector& ulike)
const;
1704 void applyOneMobilityForce(
const State& state,
int which,
Real f,
1705 Vector& mobilityForces)
const
1707 updOneFromUPartition(state,which,mobilityForces) += f;
1746 void convertQForceToUForce(
const State& state,
1756 void applyBodyForce(
const State& state,
const SpatialVec& spatialForceInG,
1764 void applyBodyTorque(
const State& state,
const Vec3& torqueInG,
1777 void applyForceToBodyPoint
1778 (
const State& state,
const Vec3& pointInB,
const Vec3& forceInG,
1859 class UniversalImpl;
1861 class BendStretchImpl;
1866 class TranslationImpl;
1867 class SphericalCoordsImpl;
1869 class LineOrientationImpl;
1873 class EllipsoidImpl;
1876 class FunctionBasedImpl;
1881 #endif // SimTK_SIMBODY_MOBILIZED_BODY_H_