00001 #ifndef SimTK_SIMBODY_MATTER_SUBSYSTEM_H_
00002 #define SimTK_SIMBODY_MATTER_SUBSYSTEM_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
00035 #include "SimTKcommon.h"
00036 #include "simbody/internal/common.h"
00037 #include "simbody/internal/MobilizedBody.h"
00038
00039 #include <cassert>
00040 #include <vector>
00041 #include <iostream>
00042
00043 class SimbodyMatterSubsystemRep;
00044
00045 namespace SimTK {
00046
00047 class MobilizedBody;
00048 class MultibodySystem;
00049 class Constraint;
00050
00122 class SimTK_SIMBODY_EXPORT SimbodyMatterSubsystem : public Subsystem {
00123 public:
00125 SimbodyMatterSubsystem();
00126 explicit SimbodyMatterSubsystem(MultibodySystem&);
00127
00128 class Subtree;
00129 class SubtreeResults;
00130
00131
00132
00133 ~SimbodyMatterSubsystem() {
00134 }
00135 SimbodyMatterSubsystem(const SimbodyMatterSubsystem& ss) : Subsystem(ss) {
00136 }
00137 SimbodyMatterSubsystem& operator=(const SimbodyMatterSubsystem& ss) {
00138 Subsystem::operator=(ss);
00139 return *this;
00140 }
00141
00143 bool getShowDefaultGeometry() const;
00144
00146 void setShowDefaultGeometry(bool show);
00147
00148
00150
00152
00157 Real calcSystemMass(const State& s) const;
00158
00159
00165 Vec3 calcSystemMassCenterLocationInGround(const State& s) const;
00166
00167
00173 MassProperties calcSystemMassPropertiesInGround(const State& s) const;
00174
00180 Inertia calcSystemCentralInertiaInGround(const State& s) const;
00181
00187 Vec3 calcSystemMassCenterVelocityInGround(const State& s) const;
00188
00194 Vec3 calcSystemMassCenterAccelerationInGround(const State& s) const;
00195
00202 SpatialVec calcSystemMomentumAboutGroundOrigin(const State& s) const;
00203
00205
00207
00208
00209
00210
00211
00212
00213
00214 MobilizedBodyIndex adoptMobilizedBody(MobilizedBodyIndex parent, MobilizedBody& child);
00215 const MobilizedBody& getMobilizedBody(MobilizedBodyIndex) const;
00216 MobilizedBody& updMobilizedBody(MobilizedBodyIndex);
00217
00218
00219
00220
00221
00222
00223 const MobilizedBody::Ground& getGround() const;
00224 MobilizedBody::Ground& updGround();
00225 MobilizedBody::Ground& Ground() {return updGround();}
00226
00227 ConstraintIndex adoptConstraint(Constraint&);
00228 const Constraint& getConstraint(ConstraintIndex) const;
00229 Constraint& updConstraint(ConstraintIndex);
00230
00232
00234
00235
00236
00237
00253 void calcAcceleration(const State&,
00254 const Vector& mobilityForces,
00255 const Vector_<SpatialVec>& bodyForces,
00256 Vector& udot,
00257 Vector_<SpatialVec>& A_GB) const;
00258
00259
00266 void calcAccelerationIgnoringConstraints(const State&,
00267 const Vector& mobilityForces,
00268 const Vector_<SpatialVec>& bodyForces,
00269 Vector& udot,
00270 Vector_<SpatialVec>& A_GB) const;
00271
00281 void calcMInverseV(const State&,
00282 const Vector& v,
00283 Vector& MinvV,
00284 Vector_<SpatialVec>& A_GB) const;
00285
00287 void calcSpatialKinematicsFromInternal(const State&,
00288 const Vector& v,
00289 Vector_<SpatialVec>& Jv) const;
00290
00292 void calcInternalGradientFromSpatial(const State&,
00293 const Vector_<SpatialVec>& dEdR,
00294 Vector& dEdQ) const;
00295
00297 Real calcKineticEnergy(const State&) const;
00298
00304 void calcTreeEquivalentMobilityForces(const State&,
00305 const Vector_<SpatialVec>& bodyForces,
00306 Vector& mobilityForces) const;
00307
00309 void calcQDot(const State& s,
00310 const Vector& u,
00311 Vector& qdot) const;
00312
00314 void calcQDotDot(const State& s,
00315 const Vector& udot,
00316 Vector& qdotdot) const;
00317
00324 void multiplyByQMatrix(const State& s, bool transposeMatrix, const Vector& in, Vector& out) const;
00325
00332 void multiplyByQMatrixInverse(const State& s, bool transposeMatrix, const Vector& in, Vector& out) const;
00333
00341 void calcMobilizerReactionForces(const State& s, Vector_<SpatialVec>& forces) const;
00342
00343
00344
00353 int getNBodies() const;
00354
00357 int getNConstraints() const;
00358
00360 int getNParticles() const;
00361
00364 int getNMobilities() const;
00365
00368 int getTotalQAlloc() const;
00369
00372 int getTotalMultAlloc() const;
00373
00379 void setUseEulerAngles(State&, bool) const;
00380 bool getUseEulerAngles (const State&) const;
00381 int getNQuaternionsInUse(const State&) const;
00382
00383 void setMobilizerIsPrescribed(State&, MobilizedBodyIndex, bool) const;
00384 bool isMobilizerPrescribed (const State&, MobilizedBodyIndex) const;
00385 bool isUsingQuaternion(const State&, MobilizedBodyIndex) const;
00386 QuaternionPoolIndex getQuaternionPoolIndex(const State&, MobilizedBodyIndex) const;
00387 AnglePoolIndex getAnglePoolIndex(const State&, MobilizedBodyIndex) const;
00388 void setConstraintIsDisabled(State&, ConstraintIndex constraint, bool) const;
00389 bool isConstraintDisabled(const State&, ConstraintIndex constraint) const;
00390
00393 void convertToEulerAngles(const State& inputState, State& outputState) const;
00394
00397 void convertToQuaternions(const State& inputState, State& outputState) const;
00398
00399
00400
00401
00402 const SpatialVec& getCoriolisAcceleration(const State&, MobilizedBodyIndex) const;
00403
00404
00405 const SpatialVec& getTotalCoriolisAcceleration(const State&, MobilizedBodyIndex) const;
00406
00407 const SpatialVec& getGyroscopicForce(const State&, MobilizedBodyIndex) const;
00408 const SpatialVec& getCentrifugalForces(const State&, MobilizedBodyIndex) const;
00409 const SpatialMat& getArticulatedBodyInertia(const State& s, MobilizedBodyIndex) const;
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421 const Vector_<Vec3>& getAllParticleLocations (const State&) const;
00422 const Vector_<Vec3>& getAllParticleVelocities (const State&) const;
00423
00424 const Vec3& getParticleLocation(const State& s, ParticleIndex p) const {
00425 return getAllParticleLocations(s)[p];
00426 }
00427 const Vec3& getParticleVelocity(const State& s, ParticleIndex p) const {
00428 return getAllParticleVelocities(s)[p];
00429 }
00430
00431 Vector& updAllParticleMasses(State& s) const;
00432
00433 void setAllParticleMasses(State& s, const Vector& masses) const {
00434 updAllParticleMasses(s) = masses;
00435 }
00436
00437
00438
00439
00440
00441
00442 Vector_<Vec3>& updAllParticleLocations(State&) const;
00443 Vector_<Vec3>& updAllParticleVelocities(State&) const;
00444
00445
00446
00447
00448 Vec3& updParticleLocation(State& s, ParticleIndex p) const {
00449 return updAllParticleLocations(s)[p];
00450 }
00451 Vec3& updParticleVelocity(State& s, ParticleIndex p) const {
00452 return updAllParticleVelocities(s)[p];
00453 }
00454
00455 void setParticleLocation(State& s, ParticleIndex p, const Vec3& r) const {
00456 updAllParticleLocations(s)[p] = r;
00457 }
00458 void setParticleVelocity(State& s, ParticleIndex p, const Vec3& v) const {
00459 updAllParticleVelocities(s)[p] = v;
00460 }
00461
00462 void setAllParticleLocations(State& s, const Vector_<Vec3>& r) const {
00463 updAllParticleLocations(s) = r;
00464 }
00465 void setAllParticleVelocities(State& s, const Vector_<Vec3>& v) const {
00466 updAllParticleVelocities(s) = v;
00467 }
00468
00470 const Vector& getAllParticleMasses(const State&) const;
00471
00472 const Vector_<Vec3>& getAllParticleAccelerations(const State&) const;
00473
00474 const Vec3& getParticleAcceleration(const State& s, ParticleIndex p) const {
00475 return getAllParticleAccelerations(s)[p];
00476 }
00477
00478
00479
00480
00481
00485 void addInStationForce(const State&, MobilizedBodyIndex bodyB, const Vec3& stationOnB,
00486 const Vec3& forceInG, Vector_<SpatialVec>& bodyForcesInG) const;
00487
00490 void addInBodyTorque(const State&, MobilizedBodyIndex, const Vec3& torqueInG,
00491 Vector_<SpatialVec>& bodyForcesInG) const;
00492
00495 void addInMobilityForce(const State&, MobilizedBodyIndex, MobilizerUIndex which, Real f,
00496 Vector& mobilityForces) const;
00497
00498
00499
00505 bool projectQConstraints(State& s, Real consAccuracy, const Vector& yWeights,
00506 const Vector& ooTols, Vector& yErrest, System::ProjectOptions) const;
00507
00508
00509
00510
00511
00512
00513
00519 bool projectUConstraints(State& s, Real consAccuracy, const Vector& yWeights,
00520 const Vector& ooTols, Vector& yErrest, System::ProjectOptions) const;
00521
00522
00523
00524
00525
00526 SimTK_PIMPL_DOWNCAST(SimbodyMatterSubsystem, Subsystem);
00527 const SimbodyMatterSubsystemRep& getRep() const;
00528 SimbodyMatterSubsystemRep& updRep();
00529 };
00530
00531 SimTK_SIMBODY_EXPORT std::ostream&
00532 operator<<(std::ostream&, const SimbodyMatterSubsystem&);
00533
00534
00535 }
00536
00537 #endif // SimTK_SIMBODY_MATTER_SUBSYSTEM_H_