rigidBodyDynamics: Removed quaternion counter and index: 'nw', 'wIndex'
Replaced with 'unitQuaterion()' virtual function to indicate if the joint uses a unit quaternion to represent rotation.
This commit is contained in:
@ -61,7 +61,7 @@ int main(int argc, char *argv[])
|
|||||||
Field<spatialVector> fx(sphericalJoint.nBodies(), Zero);
|
Field<spatialVector> fx(sphericalJoint.nBodies(), Zero);
|
||||||
|
|
||||||
// Set the angle of the pendulum to 0.3rad
|
// Set the angle of the pendulum to 0.3rad
|
||||||
sphericalJoint.joints()[1]
|
sphericalJoint.joints()[1].unitQuaternion
|
||||||
(
|
(
|
||||||
quaternion(quaternion::ZYX, vector(0.3, 0, 0)),
|
quaternion(quaternion::ZYX, vector(0.3, 0, 0)),
|
||||||
sphericalJoint.state().q()
|
sphericalJoint.state().q()
|
||||||
@ -87,7 +87,7 @@ int main(int argc, char *argv[])
|
|||||||
// using 'gnuplot sphericalJoint.gnuplot'
|
// using 'gnuplot sphericalJoint.gnuplot'
|
||||||
omegaFile
|
omegaFile
|
||||||
<< t << " "
|
<< t << " "
|
||||||
<< sphericalJoint.joints()[1]
|
<< sphericalJoint.joints()[1].unitQuaternion
|
||||||
(
|
(
|
||||||
sphericalJoint.state().q()
|
sphericalJoint.state().q()
|
||||||
).eulerAngles(quaternion::ZYX).x()
|
).eulerAngles(quaternion::ZYX).x()
|
||||||
|
|||||||
@ -84,9 +84,9 @@ Foam::RBD::joints::Rs::~Rs()
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::label Foam::RBD::joints::Rs::nw() const
|
bool Foam::RBD::joints::Rs::unitQuaternion() const
|
||||||
{
|
{
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ void Foam::RBD::joints::Rs::jcalc
|
|||||||
const scalarField& qDot
|
const scalarField& qDot
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
J.X.E() = operator()(q).R().T();
|
J.X.E() = joint::unitQuaternion(q).R().T();
|
||||||
J.X.r() = Zero;
|
J.X.r() = Zero;
|
||||||
|
|
||||||
J.S = Zero;
|
J.S = Zero;
|
||||||
|
|||||||
@ -88,9 +88,8 @@ public:
|
|||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
//- Return the number of additional state variable for this joint
|
//- Return true as this joint describes rotation using a quaternion
|
||||||
// For the quaternion this is 1 in addition to the 3 stored in q
|
virtual bool unitQuaternion() const;
|
||||||
virtual label nw() const;
|
|
||||||
|
|
||||||
//- Update the model state for this joint
|
//- Update the model state for this joint
|
||||||
virtual void jcalc
|
virtual void jcalc
|
||||||
|
|||||||
@ -86,12 +86,6 @@ Foam::RBD::joints::composite::~composite()
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::label Foam::RBD::joints::composite::nw() const
|
|
||||||
{
|
|
||||||
return last().nw();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Foam::RBD::joints::composite::jcalc
|
void Foam::RBD::joints::composite::jcalc
|
||||||
(
|
(
|
||||||
joint::XSvc& J,
|
joint::XSvc& J,
|
||||||
|
|||||||
@ -101,9 +101,6 @@ public:
|
|||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
//- Return the number of additional state variables need by this joint
|
|
||||||
virtual label nw() const;
|
|
||||||
|
|
||||||
//- Update the model state for this joint
|
//- Update the model state for this joint
|
||||||
virtual void jcalc
|
virtual void jcalc
|
||||||
(
|
(
|
||||||
|
|||||||
@ -93,9 +93,6 @@ protected:
|
|||||||
//- Index of this joints data in the rigidBodyModel state
|
//- Index of this joints data in the rigidBodyModel state
|
||||||
label qIndex_;
|
label qIndex_;
|
||||||
|
|
||||||
//- Index of this joints quaternion data in the rigidBodyModel state
|
|
||||||
label wIndex_;
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -113,12 +110,6 @@ private:
|
|||||||
return qIndex_;
|
return qIndex_;
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Allow the rigidBodyModel to set the wIndex for this joint
|
|
||||||
label& wIndex()
|
|
||||||
{
|
|
||||||
return wIndex_;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -213,8 +204,8 @@ public:
|
|||||||
//- Return the number of degrees of freedom in this joint
|
//- Return the number of degrees of freedom in this joint
|
||||||
inline label nDoF() const;
|
inline label nDoF() const;
|
||||||
|
|
||||||
//- Return the number of additional state variables need by this joint
|
//- Return true if this joint describes rotation using a quaternion
|
||||||
inline virtual label nw() const;
|
inline virtual bool unitQuaternion() const;
|
||||||
|
|
||||||
//- Return the index of this joint in the model
|
//- Return the index of this joint in the model
|
||||||
inline label index() const;
|
inline label index() const;
|
||||||
@ -223,10 +214,6 @@ public:
|
|||||||
// in the rigidBodyModel state fields
|
// in the rigidBodyModel state fields
|
||||||
inline label qIndex() const;
|
inline label qIndex() const;
|
||||||
|
|
||||||
//- Return start index for the additional state variables for this joint
|
|
||||||
// in the rigidBodyModel w state field
|
|
||||||
inline label wIndex() const;
|
|
||||||
|
|
||||||
//- Return the joint motion sub-space
|
//- Return the joint motion sub-space
|
||||||
inline const List<spatialVector>& S() const;
|
inline const List<spatialVector>& S() const;
|
||||||
|
|
||||||
@ -245,16 +232,16 @@ public:
|
|||||||
|
|
||||||
// Member Operators
|
// Member Operators
|
||||||
|
|
||||||
//- Return the state quaternion for this joint
|
//- Return the unit quaternion for this joint
|
||||||
// if it uses a quaternion representation for rotation
|
// if it uses a quaternion representation for rotation
|
||||||
inline quaternion operator()
|
inline quaternion unitQuaternion
|
||||||
(
|
(
|
||||||
const scalarField& q
|
const scalarField& q
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- Set the state quaternion for this joint
|
//- Set the unit quaternion for this joint
|
||||||
// if it uses a quaternion representation for rotation
|
// if it uses a quaternion representation for rotation
|
||||||
inline void operator()
|
inline void unitQuaternion
|
||||||
(
|
(
|
||||||
const quaternion& quat,
|
const quaternion& quat,
|
||||||
scalarField& q
|
scalarField& q
|
||||||
|
|||||||
@ -29,8 +29,7 @@ inline Foam::RBD::joint::joint(const label nDoF)
|
|||||||
:
|
:
|
||||||
S_(nDoF),
|
S_(nDoF),
|
||||||
index_(0),
|
index_(0),
|
||||||
qIndex_(0),
|
qIndex_(0)
|
||||||
wIndex_(0)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
@ -41,9 +40,9 @@ inline Foam::label Foam::RBD::joint::nDoF() const
|
|||||||
return S_.size();
|
return S_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Foam::label Foam::RBD::joint::nw() const
|
inline bool Foam::RBD::joint::unitQuaternion() const
|
||||||
{
|
{
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Foam::label Foam::RBD::joint::index() const
|
inline Foam::label Foam::RBD::joint::index() const
|
||||||
@ -56,11 +55,6 @@ inline Foam::label Foam::RBD::joint::qIndex() const
|
|||||||
return qIndex_;
|
return qIndex_;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Foam::label Foam::RBD::joint::wIndex() const
|
|
||||||
{
|
|
||||||
return wIndex_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline const Foam::List<Foam::spatialVector>& Foam::RBD::joint::S() const
|
inline const Foam::List<Foam::spatialVector>& Foam::RBD::joint::S() const
|
||||||
{
|
{
|
||||||
return S_;
|
return S_;
|
||||||
@ -69,12 +63,12 @@ inline const Foam::List<Foam::spatialVector>& Foam::RBD::joint::S() const
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||||
|
|
||||||
inline Foam::quaternion Foam::RBD::joint::operator()
|
inline Foam::quaternion Foam::RBD::joint::unitQuaternion
|
||||||
(
|
(
|
||||||
const scalarField& q
|
const scalarField& q
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
if (nw() != 1)
|
if (!unitQuaternion())
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< "Attempt to get the quaternion for a non-spherical joint"
|
<< "Attempt to get the quaternion for a non-spherical joint"
|
||||||
@ -85,13 +79,13 @@ inline Foam::quaternion Foam::RBD::joint::operator()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void Foam::RBD::joint::operator()
|
inline void Foam::RBD::joint::unitQuaternion
|
||||||
(
|
(
|
||||||
const quaternion& quat,
|
const quaternion& quat,
|
||||||
scalarField& q
|
scalarField& q
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
if (nw() != 1)
|
if (!unitQuaternion())
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< "Attempt to set quaternion for a non-spherical joint"
|
<< "Attempt to set quaternion for a non-spherical joint"
|
||||||
|
|||||||
@ -52,7 +52,7 @@ void Foam::RBD::rigidBodyModel::initializeRootBody()
|
|||||||
XT_.append(spatialTransform());
|
XT_.append(spatialTransform());
|
||||||
|
|
||||||
nDoF_ = 0;
|
nDoF_ = 0;
|
||||||
nw_ = 0;
|
unitQuaternions_ = false;
|
||||||
|
|
||||||
resizeState();
|
resizeState();
|
||||||
}
|
}
|
||||||
@ -204,11 +204,10 @@ Foam::label Foam::RBD::rigidBodyModel::join_
|
|||||||
joint& curJoint = joints_[joints_.size() - 1];
|
joint& curJoint = joints_[joints_.size() - 1];
|
||||||
curJoint.index() = joints_.size() - 1;
|
curJoint.index() = joints_.size() - 1;
|
||||||
curJoint.qIndex() = prevJoint.qIndex() + prevJoint.nDoF();
|
curJoint.qIndex() = prevJoint.qIndex() + prevJoint.nDoF();
|
||||||
curJoint.wIndex() = prevJoint.wIndex() + prevJoint.nw();
|
|
||||||
|
|
||||||
// Increment the degrees of freedom
|
// Increment the degrees of freedom
|
||||||
nDoF_ += curJoint.nDoF();
|
nDoF_ += curJoint.nDoF();
|
||||||
nw_ += curJoint.nw();
|
unitQuaternions_ = unitQuaternions_ || curJoint.unitQuaternion();
|
||||||
|
|
||||||
resizeState();
|
resizeState();
|
||||||
|
|
||||||
|
|||||||
@ -123,11 +123,8 @@ protected:
|
|||||||
// used to set the size of the of joint state fields q, qDot and qDdot.
|
// used to set the size of the of joint state fields q, qDot and qDdot.
|
||||||
label nDoF_;
|
label nDoF_;
|
||||||
|
|
||||||
//- The number of additional state variable needed to describe the joint
|
//- True if any of the joints using quaternions
|
||||||
// states. Typically this is the number of quaternion joints for which
|
bool unitQuaternions_;
|
||||||
// the 'w' element is additional to the 3-degrees of freedom of the
|
|
||||||
// joint.
|
|
||||||
label nw_;
|
|
||||||
|
|
||||||
//- Motion restraints
|
//- Motion restraints
|
||||||
PtrList<restraint> restraints_;
|
PtrList<restraint> restraints_;
|
||||||
@ -242,11 +239,8 @@ public:
|
|||||||
// used to set the size of the of joint state fields q, qDot and qDdot.
|
// used to set the size of the of joint state fields q, qDot and qDdot.
|
||||||
inline label nDoF() const;
|
inline label nDoF() const;
|
||||||
|
|
||||||
//- Return the number of additional state variable needed to describe
|
//- Return true if any of the joints using quaternions
|
||||||
// the joint states. Typically this is the number of quaternion
|
inline bool unitQuaternions() const;
|
||||||
// joints for which the 'w' element is additional to the 3-degrees of
|
|
||||||
// freedom of the joint.
|
|
||||||
inline label nw() const;
|
|
||||||
|
|
||||||
//- Return the acceleration due to gravity
|
//- Return the acceleration due to gravity
|
||||||
inline const vector& g() const;
|
inline const vector& g() const;
|
||||||
|
|||||||
@ -58,9 +58,9 @@ inline Foam::label Foam::RBD::rigidBodyModel::nDoF() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline Foam::label Foam::RBD::rigidBodyModel::nw() const
|
inline bool Foam::RBD::rigidBodyModel::unitQuaternions() const
|
||||||
{
|
{
|
||||||
return nw_;
|
return unitQuaternions_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -56,13 +56,13 @@ Foam::RBD::rigidBodySolver::~rigidBodySolver()
|
|||||||
|
|
||||||
void Foam::RBD::rigidBodySolver::correctQuaternionJoints()
|
void Foam::RBD::rigidBodySolver::correctQuaternionJoints()
|
||||||
{
|
{
|
||||||
if (model_.nw())
|
if (model_.unitQuaternions())
|
||||||
{
|
{
|
||||||
forAll (model_.joints(), i)
|
forAll (model_.joints(), i)
|
||||||
{
|
{
|
||||||
const label qi = model_.joints()[i].qIndex();
|
const label qi = model_.joints()[i].qIndex();
|
||||||
|
|
||||||
if (model_.joints()[i].nw() == 1)
|
if (model_.joints()[i].unitQuaternion())
|
||||||
{
|
{
|
||||||
// Calculate the change in the normalized quaternion axis
|
// Calculate the change in the normalized quaternion axis
|
||||||
vector dv((q().block<vector>(qi) - q0().block<vector>(qi)));
|
vector dv((q().block<vector>(qi) - q0().block<vector>(qi)));
|
||||||
@ -76,11 +76,11 @@ void Foam::RBD::rigidBodySolver::correctQuaternionJoints()
|
|||||||
// Transform the previous time quaternion
|
// Transform the previous time quaternion
|
||||||
quaternion quat
|
quaternion quat
|
||||||
(
|
(
|
||||||
normalize(model_.joints()[i](q0())*dQuat)
|
normalize(model_.joints()[i].unitQuaternion(q0())*dQuat)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Update the joint state
|
// Update the joint state
|
||||||
model_.joints()[i](quat, q());
|
model_.joints()[i].unitQuaternion(quat, q());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user