1 #include <gtest/gtest.h> 34 ostringstream dof_stream(ostringstream::out);
35 dof_stream <<
"custom (" << c.transpose() <<
")";
62 VectorNd q = VectorNd::Zero(model->q_size);
63 VectorNd qdot = VectorNd::Zero(model->q_size);
65 for (
unsigned int i = 0; i < q.size(); i++)
71 MatrixNd H = MatrixNd::Zero(model->q_size, model->q_size);
74 double kinetic_energy_ref = 0.5 * qdot.transpose() * H * qdot;
77 EXPECT_EQ(ke, kinetic_energy_ref);
83 Matrix3d inertia = Matrix3d::Identity(3, 3);
85 Joint joint(
SpatialVector(0., 0., 0., 1., 0., 0.),
SpatialVector(0., 0., 0., 0., 1., 0.),
SpatialVector(0., 0., 0., 0., 0., 1.));
91 EXPECT_EQ(0., potential_energy_zero);
95 EXPECT_EQ(4.905, potential_energy_lifted);
101 Matrix3d inertia = Matrix3d::Identity(3, 3);
103 Joint joint(
SpatialVector(0., 0., 0., 1., 0., 0.),
SpatialVector(0., 0., 0., 0., 1., 0.),
SpatialVector(0., 0., 0., 0., 0., 1.));
117 EXPECT_TRUE(model.
comFrame->getTransformFromParent().r.isApprox(com, 1.e-10));
118 EXPECT_TRUE(model.
comFrame->getTransformFromParent().E.isApprox(RobotDynamics::Math::Matrix3d::Identity(), 1.e-10));
121 EXPECT_TRUE(model.
comFrame->getTransformFromParent().r.isApprox(p_com.
vec(), 1.e-10));
122 EXPECT_TRUE(model.
comFrame->getTransformFromParent().E.isApprox(RobotDynamics::Math::Matrix3d::Identity(), 1.e-10));
125 EXPECT_TRUE(model.
comFrame->getTransformFromParent().r.isApprox(pcom_2.
vec(), 1.e-10));
126 EXPECT_TRUE(model.
comFrame->getTransformFromParent().E.isApprox(RobotDynamics::Math::Matrix3d::Identity(), 1.e-10));
128 EXPECT_EQ(123., mass);
129 EXPECT_EQ(model.
mass, 123.);
138 EXPECT_TRUE(model.
comFrame->getTransformFromParent().r.isApprox(com, 1.e-10));
139 EXPECT_TRUE(model.
comFrame->getTransformFromParent().E.isApprox(RobotDynamics::Math::Matrix3d::Identity(), 1.e-10));
142 EXPECT_TRUE(model.
comFrame->getTransformFromParent().r.isApprox(p_com.
vec(), 1.e-10));
143 EXPECT_TRUE(model.
comFrame->getTransformFromParent().E.isApprox(RobotDynamics::Math::Matrix3d::Identity(), 1.e-10));
146 EXPECT_TRUE(model.
comFrame->getTransformFromParent().r.isApprox(pcom_2.
vec(), 1.e-10));
147 EXPECT_TRUE(model.
comFrame->getTransformFromParent().E.isApprox(RobotDynamics::Math::Matrix3d::Identity(), 1.e-10));
169 Matrix3d inertia = Matrix3d::Identity(3, 3);
183 EXPECT_TRUE(gravity_wrench.isApprox(
SpatialVector(0., 0., 0., 0., 0., 2. * g), 1.e-10));
185 EXPECT_TRUE(com.isApprox(
Vector3d(1., 0., 0.), 1.e-12));
188 q = VectorNd::Zero(model.
q_size);
194 EXPECT_TRUE(gravity_wrench.isApprox(
SpatialVector(0., 0., 0., 0., 0., 4. * g), 1.e-10));
196 EXPECT_NEAR(com[0], 0., 1.e-12);
197 EXPECT_NEAR(com[1], 0., 1.e-12);
198 EXPECT_NEAR(com[2], 0., 1.e-12);
202 q = VectorNd::Zero(model.
q_size);
208 EXPECT_TRUE(gravity_wrench.isApprox(
SpatialVector(0., 0., 0., 0., 0., 8. * g), 1.e-10));
210 EXPECT_NEAR(com[0], 0., 1.e-12);
211 EXPECT_NEAR(com[1], 0., 1.e-12);
212 EXPECT_NEAR(com[2], 0., 1.e-12);
221 Matrix3d inertia = Matrix3d::Identity(3, 3);
235 EXPECT_TRUE(gravity_wrench.isApprox(
SpatialVector(0., 0., 0., 0., 0., mass * g), 1.e-10));
244 Matrix3d inertia = Matrix3d::Identity(3, 3);
258 EXPECT_TRUE(gravity_wrench.isApprox(
SpatialVector(0., 0., 0., 0., 0., -mass * g), 1.e-10));
267 Matrix3d inertia = Matrix3d::Identity(3, 3);
281 EXPECT_TRUE(gravity_wrench.isApprox(
SpatialVector(0., 0., 0., 0., 0., -mass * g), 1.e-10));
290 Matrix3d inertia = Matrix3d::Identity(3, 3);
304 EXPECT_TRUE(gravity_wrench.isApprox(
SpatialVector(0., 0., 0., 0., 0., -mass * g), 1.e-10));
313 Matrix3d inertia = Matrix3d::Identity(3, 3);
327 EXPECT_TRUE(gravity_wrench.isApprox(
SpatialVector(0., 0., 0., 0., 0., -mass * g), 1.e-10));
346 EXPECT_TRUE(model->comFrame->getTransformFromParent().r.isApprox(p_com.
vec(), 1.e-10));
347 EXPECT_TRUE(model->comFrame->getTransformFromParent().E.isApprox(RobotDynamics::Math::Matrix3d::Identity(), 1.e-10));
350 EXPECT_TRUE(model->comFrame->getTransformFromParent().r.isApprox(pcom_2.
vec(), 1.e-10));
351 EXPECT_TRUE(model->comFrame->getTransformFromParent().E.isApprox(RobotDynamics::Math::Matrix3d::Identity(), 1.e-10));
363 EXPECT_TRUE(model_3dof->comFrame->getTransformFromParent().r.isApprox(com, 1.e-10));
364 EXPECT_TRUE(model_3dof->comFrame->getTransformFromParent().E.isApprox(RobotDynamics::Math::Matrix3d::Identity(), 1.e-10));
367 EXPECT_TRUE(model_3dof->comFrame->getTransformFromParent().r.isApprox(p_com.
vec(), 1.e-10));
368 EXPECT_TRUE(model_3dof->comFrame->getTransformFromParent().E.isApprox(RobotDynamics::Math::Matrix3d::Identity(), 1.e-10));
371 EXPECT_TRUE(model_3dof->comFrame->getTransformFromParent().r.isApprox(pcom_2.
vec(), 1.e-10));
372 EXPECT_TRUE(model_3dof->comFrame->getTransformFromParent().E.isApprox(RobotDynamics::Math::Matrix3d::Identity(), 1.e-10));
392 double subtreeMass, wholeRobotMass;
398 EXPECT_EQ(subtreeMass, wholeRobotMass);
401 EXPECT_EQ(subtreeMass, 10.3368 + 3.1609 + 1.001);
408 unsigned int id1 = model.
addBody(0,
Xtrans(
Vector3d(0, 1, 0)),
Joint(
SpatialVector(1, 0, 0, 0, 0, 0)),
Body(2,
Vector3d(0, 1, 0),
Vector3d(1, 1, 1)));
409 model.
addBody(id1,
Xtrans(
Vector3d(0, 1, 0)),
Joint(
SpatialVector(1, 0, 0, 0, 0, 0)),
Body(3,
Vector3d(0, 1, 0),
Vector3d(1, 1, 1)));
411 double wholeRobotMass;
433 double wholeRobotMass;
436 MatrixNd J_com(3, model_emulated->qdot_size);
454 Matrix3d inertia = Matrix3d::Zero(3, 3);
460 Joint joint(
SpatialVector(1., 0., 0., 0., 0., 0.),
SpatialVector(0., 1., 0., 0., 0., 0.),
SpatialVector(0., 0., 1., 0., 0., 0.));
477 EXPECT_EQ(
Vector3d(1.1, 0., 0.), angular_momentum);
483 EXPECT_EQ(
Vector3d(0., 2.2, 0.), angular_momentum);
489 EXPECT_EQ(
Vector3d(0., 0., 3.3), angular_momentum);
501 EXPECT_EQ(
Vector3d(0., 0., 0.), angular_momentum);
518 EXPECT_TRUE(angular_momentum[0] == 0);
519 EXPECT_TRUE(angular_momentum[1] < 0);
520 EXPECT_TRUE(angular_momentum[2] == 0.);
564 Vector3d com, com_velocity, ang_momentum;
580 Vector3d com, com_velocity, ang_momentum;
584 MatrixNd A(6, model->qdot_size), G(3, model->qdot_size);
600 Vector3d com, com_velocity, ang_momentum;
604 MatrixNd A(6, model->qdot_size), G(3, model->qdot_size);
665 Vector3d com, com_velocity, ang_momentum;
675 double h = 0.00000005;
681 Q = x_rk4.head(model.
q_size);
689 ADot_num = ((1.0 / h) * (A2 - A));
697 double h = 0.00000005;
706 Math::VectorNd x_rk4 = Math::VectorNd::Zero(model->q_size + model->qdot_size);
710 Q = x_rk4.head(model->q_size);
711 QDot = x_rk4.tail(model->qdot_size);
717 ADot_num = (1.0 / h) * (A2 - A1);
725 double h = 0.00000005;
728 ADot_num(6, model_emulated->qdot_size);
735 Math::VectorNd x_rk4 = Math::VectorNd::Zero(model_emulated->q_size + model_emulated->qdot_size);
738 q = x_rk4.head(model_emulated->q_size);
739 qdot = x_rk4.tail(model_emulated->qdot_size);
745 ADot_num = (1.0 / h) * (A2 - A1);
760 double h = 0.00000005;
781 q = x_rk4.head(model.
q_size);
788 ADot_num = (1.0 / h) * (A2 - A1);
793 int main(
int argc,
char** argv)
795 ::testing::InitGoogleTest(&argc, argv);
796 return RUN_ALL_TESTS();
static bool checkVectorNdEpsilonClose(const RobotDynamics::Math::VectorNd &v1, const RobotDynamics::Math::VectorNd &v2, const double epsilon)
void compositeRigidBodyAlgorithm(Model &model, const Math::VectorNd &Q, Math::MatrixNd &H, bool update_kinematics=true)
Computes the joint space inertia matrix by using the Composite Rigid Body Algorithm.
void calcCenterOfMassVelocity(Model &model, const Math::VectorNd &q, const Math::VectorNd &qdot, Math::Vector3d &com_vel, bool update_kinematics=true)
Computes the Center of Mass (COM) velocity in world frame.
void calcCenterOfMassJacobian(Model &model, const Math::VectorNd &q, Math::MatrixNd &jCom, bool update_kinematics=true)
Computes the matrix such that .
A FramePoint is a 3D point that is expressed in a ReferenceFrame. To change the ReferenceFrame a Fram...
Describes all properties of a single body.
int main(int argc, char **argv)
void SetQuaternion(unsigned int i, const Math::Quaternion &quat, Math::VectorNd &Q) const
Sets the quaternion for body i (only valid if body i is connected by a JointTypeSpherical joint) ...
void setAngularPart(const Vector3d &v)
void setLinearPart(const Vector3d &v)
SpatialTransform Xtrans(const Vector3d &r)
Get pure translation transform.
RobotDynamics::Math::FramePoint updateCenterOfMassFrame(Model &model, const Math::VectorNd &q, bool update_kinematics=true)
Computes the center of mass and updates the center of mass reference frame of the model...
TEST_F(RdlUtilsTests, testGetDofName)
Math::MotionVector gravity
the cartesian vector of the gravity
unsigned int appendBody(const Math::SpatialTransform &joint_frame, const Joint &joint, const Body &body, std::string body_name="")
Adds a Body to the model such that the previously added Body is the Parent.
std::string getBodyName(const RobotDynamics::Model &model, unsigned int body_id)
get body name, returns empty string if bodyid is virtual and has multiple child bodies ...
unsigned int addBody(const unsigned int parent_id, const Math::SpatialTransform &joint_frame, const Joint &joint, const Body &body, std::string body_name="")
Connects a given body to the model.
EIGEN_STRONG_INLINE Math::Vector3d vec() const
static bool checkVector3dEq(const RobotDynamics::Math::Vector3d &v1, const RobotDynamics::Math::Vector3d &v2)
unsigned int q_size
The size of the -vector. For models without spherical joints the value is the same as Model::dof_coun...
double calcSubtreeMass(Model &model, const unsigned int bodyId)
Calculates the total mass of the subtree beginning with body bodyId and traversing outwards from ther...
double calcPotentialEnergy(Model &model, const Math::VectorNd &q, bool update_kinematics=true)
Computes the potential energy of the full model.
Math::SpatialForce calcGravityWrenchOnCenterOfMass(Model &model, const Math::VectorNd &q, bool update_kinematics=true)
Computes the gravitational wrench experienced on the robots center of mass.
A FrameVector is a 3D vector with a ReferenceFrame, and all operations between FrameVectors and other...
void calcCentroidalMomentumMatrixDot(Model &model, const Math::VectorNd &q, const Math::VectorNd &qdot, Math::MatrixNd &Adot, bool update_kinematics=true)
Calculates the time derivative of the centroidal momentum matrix, i.e. the matrix computed by RobotDy...
Describes a joint relative to the predecessor body.
Quaternion that are used for singularity free joints.
void integrateRk4(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, Math::VectorNd &x, const Math::VectorNd &tau, double h, Math::SpatialForceV *f_ext=nullptr)
Using a Runge-Kutta 4th order algorithm, integrate the system dynamics one step.
void calcCentroidalMomentumMatrix(Model &model, const Math::VectorNd &q, Math::MatrixNd &A, bool update_kinematics=true)
Calculates the centroidal momentum matrix, for a model. The centroidal momentum matrix is a matrix ...
Math::SpatialVector * mJointAxes
The spatial axes of the joint.
std::string getDofName(const Math::SpatialVector &joint_dof)
get string abbreviation for dof name from spatial vector.
Contains all information about the rigid body model.
Math types such as vectors and matrices and utility functions.
static bool checkSpatialVectorsEpsilonClose(const RobotDynamics::Math::SpatialVector &v1, const RobotDynamics::Math::SpatialVector &v2, const double epsilon)
void calcCenterOfMass(Model &model, const Math::VectorNd &q, Math::Vector3d &com, bool update_kinematics=true)
Computes the Center of Mass (COM) position.
void integrateEuler(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, Math::VectorNd &x, const Math::VectorNd &tau, double h, Math::SpatialForceV *f_ext=nullptr)
Using simple Euler integration, integrate the system dynamics one step.
A SpatialForce is a spatial vector with the angular part being three moments and the linear part bein...
static bool checkVector3dEpsilonClose(const RobotDynamics::Math::Vector3d &v1, const RobotDynamics::Math::Vector3d &v2, const double epsilon)
3 DoF joint using Quaternions for joint positional variables and
double calcKineticEnergy(Model &model, const Math::VectorNd &q, const Math::VectorNd &qdot, bool update_kinematics=true)
Computes the kinetic energy of the full model.
static Quaternion intrinsicZYXAnglesToQuaternion(double yaw, double pitch, double roll)
Convert YPR angles to quaternion.
Namespace for all structures of the RobotDynamics library.
ReferenceFramePtr comFrame
unsigned int qdot_size
The size of the.