00001 #ifndef SimTK_SIMBODY_CONSTRAINT_H_
00002 #define SimTK_SIMBODY_CONSTRAINT_H_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00045 #include "SimTKmath.h"
00046 #include "simbody/internal/common.h"
00047
00048 #include <cassert>
00049
00050 namespace SimTK {
00051
00052 class SimbodyMatterSubsystem;
00053 class SimbodyMatterSubtree;
00054 class MobilizedBody;
00055 class Constraint;
00056 class ConstraintImpl;
00057
00058
00059
00060 #ifndef SimTK_SIMBODY_DEFINING_CONSTRAINT
00061 extern template class PIMPLHandle<Constraint, ConstraintImpl, true>;
00062 #endif
00063
00065
00067
00073 class SimTK_SIMBODY_EXPORT Constraint : public PIMPLHandle<Constraint, ConstraintImpl, true> {
00074 public:
00075 Constraint() { }
00076 explicit Constraint(ConstraintImpl* r) : HandleBase(r) { }
00077
00078 void disable(State&) const;
00079 void enable(State&) const;
00080 bool isDisabled(const State&) const;
00081 bool isDisabledByDefault() const;
00082
00086 void setDisabledByDefault(bool shouldBeDisabled);
00087
00088
00089 operator ConstraintIndex() const {return getConstraintIndex();}
00090
00091
00092 ConstraintIndex getConstraintIndex() const;
00093 const SimbodyMatterSubsystem& getMatterSubsystem() const;
00094 SimbodyMatterSubsystem& updMatterSubsystem();
00095
00096 bool isInSubsystem() const;
00097 bool isInSameSubsystem(const MobilizedBody&) const;
00098
00099
00100
00106 int getNumConstrainedBodies() const;
00107
00110 const MobilizedBody& getMobilizedBodyFromConstrainedBody(ConstrainedBodyIndex) const;
00111
00116 const MobilizedBody& getAncestorMobilizedBody() const;
00117
00122 int getNumConstrainedMobilizers() const;
00123
00126 const MobilizedBody& getMobilizedBodyFromConstrainedMobilizer(ConstrainedMobilizerIndex) const;
00127
00128 const SimbodyMatterSubtree& getSubtree() const;
00129
00130
00131
00135 int getNumConstrainedQ(const State&, ConstrainedMobilizerIndex) const;
00139 int getNumConstrainedU(const State&, ConstrainedMobilizerIndex) const;
00140
00147 ConstrainedUIndex getConstrainedUIndex
00148 (const State&, ConstrainedMobilizerIndex, MobilizerUIndex which) const;
00155 ConstrainedQIndex getConstrainedQIndex
00156 (const State&, ConstrainedMobilizerIndex, MobilizerQIndex which) const;
00157
00160 int getNumConstrainedQ(const State&) const;
00161
00166 int getNumConstrainedU(const State&) const;
00167
00170 void getNumConstraintEquationsInUse(const State&, int& mp, int& mv, int& ma) const;
00171
00172
00173
00174
00175
00178 Vector getPositionErrorsAsVector(const State&) const;
00179 Vector calcPositionErrorFromQ(const State&, const Vector& q) const;
00180
00181
00182 Matrix calcPositionConstraintMatrixP(const State&) const;
00183 Matrix calcPositionConstraintMatrixPt(const State&) const;
00184
00185
00186 Matrix calcPositionConstraintMatrixPQInverse(const State&) const;
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202 void calcConstraintForcesFromMultipliers(const State&,
00203 const Vector& lambda,
00204 Vector_<SpatialVec>& bodyForcesInA,
00205 Vector& mobilityForces) const;
00206
00207
00210 Vector getVelocityErrorsAsVector(const State&) const;
00211 Vector calcVelocityErrorFromU(const State&,
00212 const Vector& u) const;
00213
00214
00215 Matrix calcVelocityConstraintMatrixV(const State&) const;
00216 Matrix calcVelocityConstraintMatrixVt(const State&) const;
00217
00218
00219
00220
00221
00224 Vector getAccelerationErrorsAsVector(const State&) const;
00225 Vector calcAccelerationErrorFromUDot(const State&,
00226 const Vector& udot) const;
00227
00230 Vector getMultipliersAsVector(const State&) const;
00231
00232
00233 Matrix calcAccelerationConstraintMatrixA(const State&) const;
00234 Matrix calcAccelerationConstraintMatrixAt(const State&) const;
00235
00236
00237
00238 class Rod; typedef Rod ConstantDistance;
00239 class Ball; typedef Ball CoincidentPoints;
00240 class Weld; typedef Weld CoincidentFrames;
00241 class PointInPlane;
00242 class PointOnLine;
00243 class ConstantAngle;
00244 class ConstantOrientation;
00245 class NoSlip1D;
00246 class ConstantSpeed;
00247 class Custom;
00248 class CoordinateCoupler;
00249 class SpeedCoupler;
00250 class PrescribedMotion;
00251
00252 class RodImpl;
00253 class BallImpl;
00254 class WeldImpl;
00255 class PointInPlaneImpl;
00256 class PointOnLineImpl;
00257 class ConstantAngleImpl;
00258 class ConstantOrientationImpl;
00259 class NoSlip1DImpl;
00260 class ConstantSpeedImpl;
00261 class CustomImpl;
00262 class CoordinateCouplerImpl;
00263 class SpeedCouplerImpl;
00264 class PrescribedMotionImpl;
00265 };
00266
00268
00270
00284 class SimTK_SIMBODY_EXPORT Constraint::Rod : public Constraint {
00285 public:
00286
00287 Rod(MobilizedBody& body1, MobilizedBody& body2,
00288 Real defaultLength=1);
00289 Rod(MobilizedBody& body1, const Vec3& defaultPoint1,
00290 MobilizedBody& body2, const Vec3& defaultPoint2,
00291 Real defaultLength=1);
00292
00293
00294 Rod& setDefaultPointOnBody1(const Vec3&);
00295 Rod& setDefaultPointOnBody2(const Vec3&);
00296 Rod& setDefaultRodLength(Real);
00297
00298
00299 MobilizedBodyIndex getBody1MobilizedBodyIndex() const;
00300 MobilizedBodyIndex getBody2MobilizedBodyIndex() const;
00301 const Vec3& getDefaultPointOnBody1() const;
00302 const Vec3& getDefaultPointOnBody2() const;
00303 Real getDefaultRodLength() const;
00304
00305
00306 const Vec3& getPointOnBody1(const State&) const;
00307 const Vec3& getPointOnBody2(const State&) const;
00308 Real getRodLength (const State&) const;
00309
00310
00311 Real getPositionError(const State&) const;
00312 Real getVelocityError(const State&) const;
00313
00314
00315 Real getAccelerationError(const State&) const;
00316 Real getMultiplier(const State&) const;
00317 Real getRodTension(const State&) const;
00318 SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(Rod, RodImpl, Constraint);
00319 };
00320
00322
00324
00335 class SimTK_SIMBODY_EXPORT Constraint::PointInPlane : public Constraint {
00336 public:
00337
00338 PointInPlane(MobilizedBody& planeBody_B, const UnitVec3& defaultPlaneNormal_B, Real defaultHeight,
00339 MobilizedBody& followerBody_F, const Vec3& defaultFollowerPoint_F);
00340
00341
00342
00343
00344 PointInPlane& setPlaneDisplayHalfWidth(Real);
00345 PointInPlane& setPointDisplayRadius(Real);
00346 Real getPlaneDisplayHalfWidth() const;
00347 Real getPointDisplayRadius() const;
00348
00349
00350 PointInPlane& setDefaultPlaneNormal(const UnitVec3&);
00351 PointInPlane& setDefaultPlaneHeight(Real);
00352 PointInPlane& setDefaultFollowerPoint(const Vec3&);
00353
00354
00355 MobilizedBodyIndex getPlaneMobilizedBodyIndex() const;
00356 MobilizedBodyIndex getFollowerMobilizedBodyIndex() const;
00357
00358 const UnitVec3& getDefaultPlaneNormal() const;
00359 Real getDefaultPlaneHeight() const;
00360 const Vec3& getDefaultFollowerPoint() const;
00361
00362
00363 const UnitVec3& getPlaneNormal(const State&) const;
00364 Real getPlaneHeight(const State&) const;
00365 const Vec3& getFollowerPoint(const State&) const;
00366
00367
00368 Real getPositionError(const State&) const;
00369 Real getVelocityError(const State&) const;
00370
00371
00372 Real getAccelerationError(const State&) const;
00373 Real getMultiplier(const State&) const;
00374 Real getForceOnFollowerPoint(const State&) const;
00375 SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(PointInPlane, PointInPlaneImpl, Constraint);
00376 };
00377
00379
00381
00392 class SimTK_SIMBODY_EXPORT Constraint::PointOnLine : public Constraint {
00393 public:
00394
00395 PointOnLine(MobilizedBody& lineBody_B, const UnitVec3& defaultLineDirection_B, const Vec3& defaultPointOnLine_B,
00396 MobilizedBody& followerBody_F, const Vec3& defaultFollowerPoint_F);
00397
00398
00399
00400
00401 PointOnLine& setLineDisplayHalfLength(Real);
00402 PointOnLine& setPointDisplayRadius(Real);
00403 Real getLineDisplayHalfLength() const;
00404 Real getPointDisplayRadius() const;
00405
00406
00407 PointOnLine& setDefaultLineDirection(const UnitVec3&);
00408 PointOnLine& setDefaultPointOnLine(const Vec3&);
00409 PointOnLine& setDefaultFollowerPoint(const Vec3&);
00410
00411
00412 MobilizedBodyIndex getLineMobilizedBodyIndex() const;
00413 MobilizedBodyIndex getFollowerMobilizedBodyIndex() const;
00414
00415 const UnitVec3& getDefaultLineDirection() const;
00416 const Vec3& getDefaultPointOnLine() const;
00417 const Vec3& getDefaultFollowerPoint() const;
00418
00419
00420 const UnitVec3& getLineDirection(const State&) const;
00421 const Vec3& getPointOnLine(const State&) const;
00422 const Vec3& getFollowerPoint(const State&) const;
00423
00424
00425 Vec2 getPositionErrors(const State&) const;
00426 Vec2 getVelocityErrors(const State&) const;
00427
00428
00429 Vec2 getAccelerationErrors(const State&) const;
00430 Vec2 getMultipliers(const State&) const;
00431 const Vec2& getForceOnFollowerPoint(const State&) const;
00432 SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(PointOnLine, PointOnLineImpl, Constraint);
00433 };
00434
00436
00438
00452 class SimTK_SIMBODY_EXPORT Constraint::ConstantAngle : public Constraint {
00453 public:
00454
00455 ConstantAngle(MobilizedBody& baseBody_B, const UnitVec3& defaultAxis_B,
00456 MobilizedBody& followerBody_F, const UnitVec3& defaultAxis_F,
00457 Real angle = Pi/2);
00458
00459
00460 ConstantAngle& setAxisDisplayLength(Real);
00461 ConstantAngle& setAxisDisplayWidth(Real);
00462 Real getAxisDisplayLength() const;
00463 Real getAxisDisplayWidth() const;
00464
00465
00466 ConstantAngle& setDefaultBaseAxis(const UnitVec3&);
00467 ConstantAngle& setDefaultFollowerAxis(const UnitVec3&);
00468 ConstantAngle& setDefaultAngle(Real);
00469
00470
00471 MobilizedBodyIndex getBaseMobilizedBodyIndex() const;
00472 MobilizedBodyIndex getFollowerMobilizedBodyIndex() const;
00473
00474 const UnitVec3& getDefaultBaseAxis() const;
00475 const UnitVec3& getDefaultFollowerAxis() const;
00476 Real getDefaultAngle() const;
00477
00478
00479 const UnitVec3& getBaseAxis(const State&) const;
00480 const UnitVec3& getFollowerAxis(const State&) const;
00481 Real getAngle(const State&) const;
00482
00483
00484 Real getPositionError(const State&) const;
00485 Real getVelocityError(const State&) const;
00486
00487
00488 Real getAccelerationError(const State&) const;
00489 Real getMultiplier(const State&) const;
00490 Real getTorqueOnFollowerBody(const State&) const;
00491 SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(ConstantAngle, ConstantAngleImpl, Constraint);
00492 };
00493
00495
00497
00511 class SimTK_SIMBODY_EXPORT Constraint::Ball : public Constraint {
00512 public:
00513
00514 Ball(MobilizedBody& body1, MobilizedBody& body2);
00515 Ball(MobilizedBody& body1, const Vec3& defaultPoint1,
00516 MobilizedBody& body2, const Vec3& defaultPoint2);
00517
00518
00519 Ball& setDefaultPointOnBody1(const Vec3&);
00520 Ball& setDefaultPointOnBody2(const Vec3&);
00521
00522
00523 Ball& setDefaultRadius(Real r);
00524 Real getDefaultRadius() const;
00525
00526
00527 MobilizedBodyIndex getBody1MobilizedBodyIndex() const;
00528 MobilizedBodyIndex getBody2MobilizedBodyIndex() const;
00529 const Vec3& getDefaultPointOnBody1() const;
00530 const Vec3& getDefaultPointOnBody2() const;
00531
00532
00533 const Vec3& getPointOnBody1(const State&) const;
00534 const Vec3& getPointOnBody2(const State&) const;
00535
00536
00537 Vec3 getPositionErrors(const State&) const;
00538 Vec3 getVelocityErrors(const State&) const;
00539
00540
00541 Vec3 getAccelerationErrors(const State&) const;
00542 Vec3 getMultipliers(const State&) const;
00543
00544
00545 const Vec3& getBallReactionForceOnBody1(const State&) const;
00546 const Vec3& getBallReactionForceOnBody2(const State&) const;
00547 SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(Ball, BallImpl, Constraint);
00548 };
00549
00551
00553
00570 class SimTK_SIMBODY_EXPORT Constraint::ConstantOrientation : public Constraint
00571 {
00572 public:
00573
00574 ConstantOrientation(MobilizedBody& baseBody_B, const Rotation& defaultRB,
00575 MobilizedBody& followerBody_F, const Rotation& defaultRF);
00576
00577
00578
00579
00580 ConstantOrientation& setDefaultBaseRotation(const Rotation&);
00581 ConstantOrientation& setDefaultFollowerRotation(const Rotation&);
00582
00583
00584 MobilizedBodyIndex getBaseMobilizedBodyIndex() const;
00585 MobilizedBodyIndex getFollowerMobilizedBodyIndex() const;
00586
00587 const Rotation& getDefaultBaseRotation() const;
00588 const Rotation& getDefaultFollowerRotation() const;
00589
00590
00591 const Rotation& getBaseRotation(const State&) const;
00592 const Rotation& getFollowerRotation(const State&) const;
00593
00594
00595 Vec3 getPositionErrors(const State&) const;
00596 Vec3 getVelocityErrors(const State&) const;
00597
00598
00599 Vec3 getAccelerationErrors(const State&) const;
00600 Vec3 getMultipliers(const State&) const;
00601 Vec3 getTorqueOnFollowerBody(const State&) const;
00602 SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(ConstantOrientation, ConstantOrientationImpl, Constraint);
00603 };
00604
00606
00608
00632 class SimTK_SIMBODY_EXPORT Constraint::Weld : public Constraint {
00633 public:
00634
00635
00638 Weld(MobilizedBody& body1, MobilizedBody& body2);
00639
00644 Weld(MobilizedBody& body1, const Transform& frame1,
00645 MobilizedBody& body2, const Transform& frame2);
00646
00647
00648
00652 Weld& setAxisDisplayLength(Real r);
00653
00657 Real getAxisDisplayLength() const;
00658
00659
00660
00664 Weld& setDefaultFrameOnBody1(const Transform&);
00665
00667 const Transform& getDefaultFrameOnBody1() const;
00668
00672 Weld& setDefaultFrameOnBody2(const Transform&);
00673
00675 const Transform& getDefaultFrameOnBody2() const;
00676
00677
00678
00679
00681 MobilizedBodyIndex getBody1MobilizedBodyIndex() const;
00682
00684 MobilizedBodyIndex getBody2MobilizedBodyIndex() const;
00685
00686
00687
00688 const Transform& getFrameOnBody1(const State&) const;
00689 const Transform& getFrameOnBody2(const State&) const;
00690
00691
00692 Vec6 getPositionErrors(const State&) const;
00693 Vec6 getVelocityErrors(const State&) const;
00694
00695
00696 Vec6 getAccelerationErrors(const State&) const;
00697 Vec6 getMultipliers(const State&) const;
00698
00699
00700 const SpatialVec& getWeldReactionOnBody1(const State&) const;
00701 const SpatialVec& getWeldReactionOnBody2(const State&) const;
00702 SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(Weld, WeldImpl, Constraint);
00703 };
00704
00706
00708
00720 class SimTK_SIMBODY_EXPORT Constraint::NoSlip1D : public Constraint {
00721 public:
00722
00723 NoSlip1D(MobilizedBody& caseBodyC, const Vec3& P_C, const UnitVec3& n_C,
00724 MobilizedBody& movingBody0, MobilizedBody& movingBody1);
00725
00726
00727
00728
00729 NoSlip1D& setDirectionDisplayLength(Real);
00730 NoSlip1D& setPointDisplayRadius(Real);
00731 Real getDirectionDisplayLength() const;
00732 Real getPointDisplayRadius() const;
00733
00734
00735 NoSlip1D& setDefaultDirection(const UnitVec3&);
00736 NoSlip1D& setDefaultContactPoint(const Vec3&);
00737
00738
00739 MobilizedBodyIndex getCaseMobilizedBodyIndex() const;
00740 MobilizedBodyIndex getMovingBodyMobilizedBodyIndex(int which) const;
00741
00742 const UnitVec3& getDefaultDirection() const;
00743 const Vec3& getDefaultContactPoint() const;
00744
00745
00746 const UnitVec3& getDirection(const State&) const;
00747 const Vec3& getContactPoint(const State&) const;
00748
00749
00750
00751 Real getVelocityError(const State&) const;
00752
00753
00754 Real getAccelerationError(const State&) const;
00755 Real getMultiplier(const State&) const;
00756 Real getForceAtContactPoint(const State&) const;
00757 SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(NoSlip1D, NoSlip1DImpl, Constraint);
00758 };
00759
00761
00763
00770 class SimTK_SIMBODY_EXPORT Constraint::ConstantSpeed : public Constraint
00771 {
00772 public:
00773
00774 ConstantSpeed(MobilizedBody& mobilizer, MobilizerUIndex, Real speed);
00775 ConstantSpeed(MobilizedBody& mobilizer, Real speed);
00776
00777
00778 MobilizedBodyIndex getMobilizedBodyIndex() const;
00779 MobilizerUIndex getWhichU() const;
00780 Real getDefaultSpeed() const;
00781
00782
00783
00784 Real getVelocityError(const State&) const;
00785
00786
00787 Real getAccelerationError(const State&) const;
00788 Real getMultiplier(const State&) const;
00789 Real getGeneralizedForce(const State&) const;
00790 SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(ConstantSpeed, ConstantSpeedImpl, Constraint);
00791 };
00792
00824 class SimTK_SIMBODY_EXPORT Constraint::Custom : public Constraint
00825 {
00826 public:
00827 class Implementation;
00828 class ImplementationImpl;
00829
00830
00831
00832
00833
00834
00835
00836 explicit Custom(Implementation* implementation);
00837 SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(Custom, CustomImpl, Constraint);
00838 protected:
00839 const Implementation& getImplementation() const;
00840 Implementation& updImplementation();
00841 };
00842
00843
00844
00845 #ifndef SimTK_SIMBODY_DEFINING_CONSTRAINT
00846 extern template class PIMPLHandle<Constraint::Custom::Implementation,
00847 Constraint::Custom::ImplementationImpl>;
00848 #endif
00849
00850 class SimTK_SIMBODY_EXPORT Constraint::Custom::Implementation
00851 : public PIMPLHandle<Implementation,ImplementationImpl>
00852 {
00853 public:
00854
00855
00856
00858 virtual ~Implementation() { }
00859
00864 virtual Implementation* clone() const = 0;
00865
00866
00870 Implementation(SimbodyMatterSubsystem&, int mp, int mv, int ma);
00871
00876 Implementation(SimbodyMatterSubsystem&);
00877
00878 const SimbodyMatterSubsystem& getMatterSubsystem() const;
00879
00880
00881
00888 void invalidateTopologyCache() const;
00889
00894 Implementation& setDefaultNumConstraintEquations(int mp, int mv, int ma);
00895
00900 Implementation& setDisabledByDefault(bool shouldBeDisabled);
00901
00907 ConstrainedBodyIndex addConstrainedBody(const MobilizedBody&);
00908
00914 ConstrainedMobilizerIndex addConstrainedMobilizer(const MobilizedBody&);
00915
00916 MobilizedBodyIndex getMobilizedBodyIndexOfConstrainedBody(ConstrainedBodyIndex) const;
00917 MobilizedBodyIndex getMobilizedBodyIndexOfConstrainedMobilizer(ConstrainedMobilizerIndex) const;
00918
00919
00920
00921
00922
00926 Real getOneQ(const State&, ConstrainedMobilizerIndex, MobilizerQIndex) const;
00932 Real getOneU(const State&, ConstrainedMobilizerIndex, MobilizerUIndex) const;
00933
00938 Real getOneQDot (const State&, ConstrainedMobilizerIndex, MobilizerQIndex, bool realizingVelocity=false) const;
00943 Real getOneQDotDot(const State&, ConstrainedMobilizerIndex, MobilizerQIndex, bool realizingAcceleration=false) const;
00948 Real getOneUDot(const State&, ConstrainedMobilizerIndex, MobilizerUIndex, bool realizingAcceleration=false) const;
00949
00955 void addInOneMobilityForce(const State&, ConstrainedMobilizerIndex, MobilizerUIndex whichU,
00956 Real force, Vector& mobilityForces) const;
00957
00958
00959
00964 const Transform& getBodyTransform(const State& s, ConstrainedBodyIndex B, bool realizingPosition=false) const;
00969 const SpatialVec& getBodyVelocity(const State& s, ConstrainedBodyIndex B, bool realizingVelocity=false) const;
00974 const SpatialVec& getBodyAcceleration(const State& s, ConstrainedBodyIndex B, bool realizingAcceleration=false) const;
00975
00976
00977
00982 const Rotation& getBodyRotation (const State& s, ConstrainedBodyIndex B, bool realizingPosition=false) const
00983 {return getBodyTransform(s,B,realizingPosition).R();}
00988 const Vec3& getBodyAngularVelocity (const State& s, ConstrainedBodyIndex B, bool realizingVelocity=false) const
00989 {return getBodyVelocity(s,B,realizingVelocity)[0];}
00994 const Vec3& getBodyAngularAcceleration(const State& s, ConstrainedBodyIndex B, bool realizingAcceleration=false) const
00995 {return getBodyAcceleration(s,B,realizingAcceleration)[0];}
00996
00997
00998
01003 const Vec3& getBodyOriginLocation (const State& s, ConstrainedBodyIndex B, bool realizingPosition=false) const
01004 {return getBodyTransform(s,B,realizingPosition).T();}
01009 const Vec3& getBodyOriginVelocity (const State& s, ConstrainedBodyIndex B, bool realizingVelocity=false) const
01010 {return getBodyVelocity(s,B,realizingVelocity)[1];}
01016 const Vec3& getBodyOriginAcceleration(const State& s, ConstrainedBodyIndex B, bool realizingAcceleration=false) const
01017 {return getBodyAcceleration(s,B,realizingAcceleration)[1];}
01018
01019
01020
01027 Vec3 findStationLocation(const State& s, ConstrainedBodyIndex B, const Vec3& p_BS, bool realizingPosition=false) const {
01028 return getBodyTransform(s,B,realizingPosition) * p_BS;
01029 }
01036 Vec3 findStationVelocity(const State& s, ConstrainedBodyIndex B, const Vec3& p_BS, bool realizingVelocity=false) const {
01037 const Vec3 p_AS = getBodyRotation(s,B) * p_BS;
01038 const SpatialVec& V_AB = getBodyVelocity(s,B,realizingVelocity);
01039 return V_AB[1] + (V_AB[0] % p_AS);
01040 }
01047 Vec3 findStationAcceleration(const State& s, ConstrainedBodyIndex B, const Vec3& p_BS, bool realizingAcceleration=false) const {
01048 const Vec3 p_AS = getBodyRotation(s,B) * p_BS;
01049 const Vec3& w_AB = getBodyAngularVelocity(s,B);
01050 const SpatialVec& A_AB = getBodyAcceleration(s,B,realizingAcceleration);
01051 return A_AB[1] + (A_AB[0] % p_AS) + w_AB % (w_AB % p_AS);
01052 }
01053
01054
01055
01059 void addInStationForce(const State& s, ConstrainedBodyIndex B, const Vec3& p_BS,
01060 const Vec3& forceInA, Vector_<SpatialVec>& bodyForcesInA) const;
01061
01064 void addInBodyTorque(const State& s, ConstrainedBodyIndex B,
01065 const Vec3& torqueInA, Vector_<SpatialVec>& bodyForcesInA) const;
01066
01067
01068 protected:
01077
01079
01080
01081
01082
01083
01084
01085
01086
01087 virtual void realizeTopology(State&) const { }
01088
01097 virtual void realizeModel(State&) const { }
01098
01102 virtual void realizeInstance(const State&) const { }
01103
01108 virtual void realizeTime(const State&) const { }
01109
01116 virtual void realizePosition(const State&) const { }
01117
01124 virtual void realizeVelocity(const State&) const { }
01125
01130 virtual void realizeDynamics(const State&) const { }
01131
01138 virtual void realizeAcceleration(const State&) const { }
01139
01144 virtual void realizeReport(const State&) const { }
01146
01153
01154
01155
01156
01157
01158 virtual void realizePositionErrors(const State&, int mp, Real* perr) const;
01159
01164 virtual void realizePositionDotErrors(const State&, int mp, Real* pverr) const;
01165
01170 virtual void realizePositionDotDotErrors(const State&, int mp, Real* paerr) const;
01171
01184 virtual void applyPositionConstraintForces
01185 (const State&, int mp, const Real* multipliers,
01186 Vector_<SpatialVec>& bodyForces,
01187 Vector& mobilityForces) const;
01189
01192
01193
01194
01195
01196
01197 virtual void realizeVelocityErrors(const State&, int mv, Real* verr) const;
01198
01203 virtual void realizeVelocityDotErrors(const State&, int mv, Real* vaerr) const;
01204
01218 virtual void applyVelocityConstraintForces
01219 (const State&, int mv, const Real* multipliers,
01220 Vector_<SpatialVec>& bodyForces,
01221 Vector& mobilityForces) const;
01223
01226
01227
01228
01229
01230
01231 virtual void realizeAccelerationErrors(const State&, int ma, Real* aerr) const;
01245 virtual void applyAccelerationConstraintForces
01246 (const State&, int ma, const Real* multipliers,
01247 Vector_<SpatialVec>& bodyForces,
01248 Vector& mobilityForces) const;
01250
01257 virtual void calcDecorativeGeometryAndAppend
01258 (const State& s, Stage stage, std::vector<DecorativeGeometry>& geom) const
01259 {
01260 }
01261
01262 friend class Constraint::CustomImpl;
01263 };
01264
01272 class SimTK_SIMBODY_EXPORT Constraint::CoordinateCoupler : public Constraint::Custom {
01273 public:
01286 CoordinateCoupler(SimbodyMatterSubsystem& matter, const Function<1>* function, const std::vector<MobilizedBodyIndex>& coordBody, const std::vector<MobilizerQIndex>& coordIndex);
01287 };
01288
01300 class SimTK_SIMBODY_EXPORT Constraint::SpeedCoupler : public Constraint::Custom {
01301 public:
01314 SpeedCoupler(SimbodyMatterSubsystem& matter, const Function<1>* function, const std::vector<MobilizedBodyIndex>& speedBody, const std::vector<MobilizerUIndex>& speedIndex);
01331 SpeedCoupler(SimbodyMatterSubsystem& matter, const Function<1>* function, const std::vector<MobilizedBodyIndex>& speedBody, const std::vector<MobilizerUIndex>& speedIndex,
01332 const std::vector<MobilizedBodyIndex>& coordBody, const std::vector<MobilizerQIndex>& coordIndex);
01333 };
01334
01341 class SimTK_SIMBODY_EXPORT Constraint::PrescribedMotion : public Constraint::Custom {
01342 public:
01353 PrescribedMotion(SimbodyMatterSubsystem& matter, const Function<1>* function, MobilizedBodyIndex coordBody, MobilizerQIndex coordIndex);
01354 };
01355
01356 }
01357
01358 #endif // SimTK_SIMBODY_CONSTRAINT_H_
01359
01360
01361