8#ifndef RBDL_CONSTRAINT_H
9#define RBDL_CONSTRAINT_H
154 virtual void bind(
const Model &model)=0;
185 bool updateKinematics=
false) = 0;
218 bool updateKinematics=
false) = 0;
248 bool updateKinematics=
false) = 0;
286 bool updateKinematics=
false) = 0;
354 std::vector< unsigned int > &constraintBodiesOutput,
355 std::vector< Math::SpatialTransform > &constraintBodyFramesOutput,
356 std::vector< Math::SpatialVector > &constraintForcesOutput,
358 bool resolveAllInRootFrame =
false,
359 bool updateKinematics=
false) = 0;
387 unsigned int typeOfConstraint,
388 unsigned int sizeOfConstraint,
389 unsigned int userDefinedIdNumber):
390 typeOfConstraint(typeOfConstraint),
391 id(userDefinedIdNumber),
392 sizeOfConstraint(sizeOfConstraint),
393 baumgarteParameters(1./0.1,1./0.1),
394 baumgarteEnabled(false)
397 if(nameOfConstraint){
398 name = nameOfConstraint;
400 positionConstraint.resize(sizeOfConstraint);
401 velocityConstraint.resize(sizeOfConstraint);
402 for(
unsigned int i=0; i<sizeOfConstraint;++i){
403 positionConstraint[i]=
false;
404 velocityConstraint[i]=
false;
417 const unsigned int rowIndex)
419 rowInSystem = rowIndex;
443 GConstraint = GSys.
block(rowInSystem,0,sizeOfConstraint,GSys.
cols());
454 gammaConstraint = gammaSys.
block(rowInSystem,0,sizeOfConstraint,1);
464 errConstraint = errSys.
block(rowInSystem,0,sizeOfConstraint,1);
475 derrConstraint = derrSys.
block(rowInSystem,0,sizeOfConstraint,1);
485 bgParamsUpd = baumgarteParameters;
498 baumgarteForces=(-2*baumgarteParameters[0]*errVel
499 -baumgarteParameters[1]*baumgarteParameters[1]*errPos);
514 for(
unsigned int i=0; i<sizeOfConstraint;++i){
515 gammaSysOutput[rowInSystem+i] +=
516 -2.*baumgarteParameters[0]*errVelSys[rowInSystem+i]
517 -(baumgarteParameters[1]*baumgarteParameters[1]
518 )*errPosSys[rowInSystem+i];
527 return typeOfConstraint;
534 return sizeOfConstraint;
557 baumgarteParameters[0] = 1./tStab;
558 baumgarteParameters[1] = 1./tStab;
567 baumgarteEnabled = flagEnableBaumgarteStabilization;
574 return baumgarteEnabled;
586 assert(constraintSubIndex < sizeOfConstraint);
587 positionConstraint[constraintSubIndex] =
true;
588 velocityConstraint[constraintSubIndex] =
true;
601 assert(constraintSubIndex < sizeOfConstraint);
602 positionConstraint[constraintSubIndex] =
false;
603 velocityConstraint[constraintSubIndex] =
true;
617 assert(constraintSubIndex < sizeOfConstraint);
618 positionConstraint[constraintSubIndex] =
false;
619 velocityConstraint[constraintSubIndex] =
false;
629 for(
unsigned int i=0; i<sizeOfConstraint;++i){
630 positionConstraint[i] =
true;
631 velocityConstraint[i] =
true;
642 for(
unsigned int i=0; i<sizeOfConstraint;++i){
643 positionConstraint[i] =
false;
644 velocityConstraint[i] =
true;
655 for(
unsigned int i=0; i<sizeOfConstraint;++i){
656 positionConstraint[i] =
false;
657 velocityConstraint[i] =
false;
669 assert(constraintSubIndex < sizeOfConstraint);
670 return positionConstraint[constraintSubIndex];
680 assert(constraintSubIndex < sizeOfConstraint);
681 return velocityConstraint[constraintSubIndex];
unsigned int cols() const
MX_Xd_SubMatrix block(unsigned int row_start, unsigned int col_start)
Interface to define general-purpose constraints.
Math::Vector2d baumgarteParameters
void setEnableBaumgarteStabilization(bool flagEnableBaumgarteStabilization)
bool baumgarteEnabled
A flag which enables or disables Baumgarte stabilization.
void enableConstraintErrorFromPositionLevel()
: Will set the all elements in positionConstraint and velocityConstraint to be consistent with a cons...
unsigned int getUserDefinedId()
void enableConstraintErrorFromAccelerationLevel(unsigned int constraintSubIndex)
: Will set the vectors positionConstraint and velocityConstraint to be consistent with a constraint t...
virtual void calcConstraintJacobian(Model &model, const double time, const Math::VectorNd &Q, const Math::VectorNd &QDot, Math::MatrixNd &GSysOutput, ConstraintCache &cache, bool updateKinematics=false)=0
In this function the matrix of this contraint is inserted into the system constraint Jacobian (GSys...
void setBaumgarteTimeConstant(double tStab)
Calculates and sets the Baumgarte stabilization coefficients as a function of tStab,...
bool getVelocityLevelError(unsigned int constraintSubIndex)
Returns the boolean value that determines whether or not velocity-level errors are computed for this ...
unsigned int getConstraintSize()
const std::vector< Math::SpatialTransform > & getBodyFrames()
void setUserDefinedId(unsigned int userDefinedId)
void getGamma(const Math::VectorNd &gammaSys, Math::VectorNd &gammaConstraint)
void enableConstraintErrorFromVelocityLevel()
: Will set the all elements in positionConstraint and velocityConstraint to be consistent with a cons...
virtual void calcGamma(Model &model, const double time, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::MatrixNd &GSys, Math::VectorNd &gammaSysOutput, ConstraintCache &cache, bool updateKinematics=false)=0
In this function the vector of this constraint is inserted into the right-hand-side vector of the s...
void getBaumgarteStabilizationParameters(Math::Vector2d &bgParamsUpd)
std::vector< Math::SpatialTransform > bodyFrames
Transform from the frame of the predecessor body to the constraint frame.
unsigned int rowInSystem
The first row in G that corresponds to this constraint.
void enableConstraintErrorFromPositionLevel(unsigned int constraintSubIndex)
: Will set the vectors positionConstraint and velocityConstraint to be consistent with a constraint t...
void getBaumgarteStabilizationForces(const Math::VectorNd &errPos, const Math::VectorNd &errVel, Math::VectorNd &baumgarteForces)
std::vector< bool > positionConstraint
void getConstraintJacobian(const Math::MatrixNd &GSys, Math::MatrixNd &GConstraint)
unsigned int getConstraintIndex()
const std::vector< unsigned int > & getBodyIds()
unsigned int sizeOfConstraint
The number of rows that this constraint adds to G.
std::string name
A user defined name which is unique to this constraint set.
void enableConstraintErrorFromVelocityLevel(unsigned int constraintSubIndex)
: Will set the vectors positionConstraint and velocityConstraint to be consistent with a constraint t...
virtual void calcConstraintForces(Model &model, const double time, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::MatrixNd &GSys, const Math::VectorNd &LagrangeMultipliersSys, std::vector< unsigned int > &constraintBodiesOutput, std::vector< Math::SpatialTransform > &constraintBodyFramesOutput, std::vector< Math::SpatialVector > &constraintForcesOutput, ConstraintCache &cache, bool resolveAllInRootFrame=false, bool updateKinematics=false)=0
This function resolves the generalized forces this constraint applies to the system into the wrenches...
bool isBaumgarteStabilizationEnabled()
void addToConstraintSet(const unsigned int rowIndex)
This function is called by the functions in ConstraintSet that add a Constraint to the system....
unsigned int id
A user defined id which is unique to this constraint set.
bool getPositionLevelError(unsigned int constraintSubIndex)
Returns the boolean value that determines whether or not position-level errors are computed for this ...
void getVelocityError(const Math::VectorNd &derrSys, Math::VectorNd &derrConstraint)
virtual void calcPositionError(Model &model, const double time, const Math::VectorNd &Q, Math::VectorNd &errSysOutput, ConstraintCache &cache, bool updateKinematics=false)=0
In this function the sub vector of this constraint is inserted into the position error vector of the...
std::vector< unsigned int > bodyIds
The index of the predecessor body in the vector of bodies in Model.
void getPositionError(const Math::VectorNd &errSys, Math::VectorNd &errConstraint)
std::vector< bool > velocityConstraint
void addInBaumgarteStabilizationForces(const Math::VectorNd &errPosSys, const Math::VectorNd &errVelSys, Math::VectorNd &gammaSysOutput)
virtual void bind(const Model &model)=0
Any local memory that has a dimension of N, where N is the length of QDot, is resized in this functio...
unsigned int getConstraintType()
unsigned int typeOfConstraint
The type of this constraint.
virtual void calcVelocityError(Model &model, const double time, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::MatrixNd &GSys, Math::VectorNd &derrSysOutput, ConstraintCache &cache, bool updateKinematics=false)=0
In this function the sub vector of this constraint is inserted into the position error vector of the...
Constraint(const char *nameOfConstraint, unsigned int typeOfConstraint, unsigned int sizeOfConstraint, unsigned int userDefinedIdNumber)
void enableConstraintErrorFromAccelerationLevel()
: Will set the all elements in positionConstraint and velocityConstraint to be consistent with a cons...
ConstraintType
Enum to describe the type of a constraint.
Math::SpatialVector svecB
Math::SpatialVector svecA
Working SpatialVectors.
Math::SpatialTransform stB
Math::SpatialTransform stA
Working SpatialTransforms.
Math::VectorNd vecNA
Working vectors that are sized to match the length of qdot.
Math::SpatialVector svecD
Math::SpatialVector svecE
Math::SpatialVector svecF
Math::SpatialTransform stD
Math::VectorNd vecNZeros
Here N is taken to mean the number of elements in QDot.
Math::Vector3d vec3A
Working Vector3d entries.
Math::Matrix3d mat3A
Working Matrix3d entries.
Math::SpatialVector svecC
Math::SpatialTransform stC
Compact representation of spatial transformations.