5 #include <gtest/gtest.h> 57 EXPECT_EQ(model->getCommonMovableParentId(id8, id7), id6);
58 EXPECT_EQ(model->getCommonMovableParentId(id1, id4), id1);
59 EXPECT_EQ(model->getCommonMovableParentId(id7, id8), id6);
60 EXPECT_EQ(model->getCommonMovableParentId(id4, id1), id1);
61 EXPECT_EQ(model->getCommonMovableParentId(0, id8), 0);
62 EXPECT_EQ(model->getCommonMovableParentId(id4, id4), id4);
63 EXPECT_EQ(model->mass, 8.0);
68 EXPECT_EQ(model->getCommonMovableParentId(id10, id8), 0);
69 EXPECT_EQ(model->getCommonMovableParentId(id8, id10), 0);
71 EXPECT_EQ(model->mass, 10.0);
79 EXPECT_EQ(model->mass, 14.0);
81 EXPECT_EQ(model->getCommonMovableParentId(fid1, fid2), id10);
82 EXPECT_EQ(model->getCommonMovableParentId(fid2, fid1), id10);
83 EXPECT_EQ(model->getCommonMovableParentId(fid1, fid4), id10);
84 EXPECT_EQ(model->getCommonMovableParentId(fid4, fid1), id10);
85 EXPECT_EQ(model->getCommonMovableParentId(fid1, fid3), 0);
86 EXPECT_EQ(model->getCommonMovableParentId(fid1, id9), id9);
91 EXPECT_EQ(1u, model->lambda.size());
92 EXPECT_EQ(1u, model->mu.size());
93 EXPECT_EQ(0u, model->dof_count);
95 EXPECT_EQ(0u, model->q_size);
96 EXPECT_EQ(0u, model->qdot_size);
98 EXPECT_EQ(1u, model->v.size());
99 EXPECT_EQ(1u, model->a.size());
101 EXPECT_EQ(1u, model->mJoints.size());
103 EXPECT_EQ(1u, model->S.size());
105 EXPECT_EQ(1u, model->c.size());
106 EXPECT_EQ(1u, model->IA.size());
107 EXPECT_EQ(1u, model->pA.size());
108 EXPECT_EQ(1u, model->U.size());
109 EXPECT_EQ(1u, model->d.size());
110 EXPECT_EQ(1u, model->u.size());
111 EXPECT_EQ(1u, model->Ic.size());
112 EXPECT_EQ(1u, model->I.size());
114 EXPECT_EQ(1u, model->X_lambda.size());
115 EXPECT_EQ(1u, model->bodyFrames.size());
116 EXPECT_EQ(1u, model->bodyCenteredFrames.size());
117 EXPECT_EQ(0u, model->fixedBodyFrames.size());
118 EXPECT_EQ(1u, model->mBodies.size());
126 unsigned int body_id = 0;
128 body_id = model->addBody(0,
Xtrans(
Vector3d(0., 0., 0.)), joint, body);
130 EXPECT_EQ(1u, body_id);
131 EXPECT_EQ(2u, model->lambda.size());
132 EXPECT_EQ(2u, model->mu.size());
133 EXPECT_EQ(1u, model->dof_count);
135 EXPECT_EQ(2u, model->v.size());
136 EXPECT_EQ(2u, model->a.size());
138 EXPECT_EQ(2u, model->mJoints.size());
139 EXPECT_EQ(2u, model->S.size());
141 EXPECT_EQ(2u, model->c.size());
142 EXPECT_EQ(2u, model->IA.size());
143 EXPECT_EQ(2u, model->pA.size());
144 EXPECT_EQ(2u, model->U.size());
145 EXPECT_EQ(2u, model->d.size());
146 EXPECT_EQ(2u, model->u.size());
147 EXPECT_EQ(2u, model->Ic.size());
148 EXPECT_EQ(2u, model->I.size());
151 spatial_zero.setZero();
153 EXPECT_EQ(2u, model->X_lambda.size());
154 EXPECT_EQ(2u, model->bodyFrames.size());
155 EXPECT_EQ(2u, model->bodyCenteredFrames.size());
156 EXPECT_EQ(0u, model->fixedBodyFrames.size());
157 EXPECT_EQ(2u, model->mBodies.size());
167 EXPECT_EQ(3u, model->lambda.size());
168 EXPECT_EQ(3u, model->mu.size());
169 EXPECT_EQ(6u, model->dof_count);
170 EXPECT_EQ(7u, model->q_size);
171 EXPECT_EQ(6u, model->qdot_size);
173 EXPECT_EQ(3u, model->v.size());
174 EXPECT_EQ(3u, model->a.size());
176 EXPECT_EQ(3u, model->mJoints.size());
177 EXPECT_EQ(3u, model->S.size());
179 EXPECT_EQ(3u, model->c.size());
180 EXPECT_EQ(3u, model->IA.size());
181 EXPECT_EQ(3u, model->pA.size());
182 EXPECT_EQ(3u, model->U.size());
183 EXPECT_EQ(3u, model->d.size());
184 EXPECT_EQ(3u, model->u.size());
187 spatial_zero.setZero();
189 EXPECT_EQ(3u, model->X_lambda.size());
190 EXPECT_EQ(3u, model->bodyFrames.size());
191 EXPECT_EQ(3u, model->bodyCenteredFrames.size());
192 EXPECT_EQ(0u, model->fixedBodyFrames.size());
193 EXPECT_EQ(3u, model->mBodies.size());
206 EXPECT_EQ(spatial_joint_axis, joint.
mJointAxes[0]);
216 unsigned int bodyId1 = model->addBody(0,
Xtrans(
Vector3d(0., 0., 0.)), joint, body,
"mybody");
218 unsigned int fb1 = model->addBody(0,
Xtrans(
Vector3d(0., 0., 0.)), fixed, body,
"fixed");
220 EXPECT_TRUE(model->IsBodyId(bodyId1));
221 EXPECT_TRUE(model->IsBodyId(fb1));
223 EXPECT_FALSE(model->IsBodyId(bodyId1 + 1));
224 EXPECT_FALSE(model->IsBodyId(fb1 + 1));
232 model->addBody(0,
Xtrans(
Vector3d(0., 0., 0.)), joint, body,
"mybody");
234 unsigned int body_id = model->GetBodyId(
"mybody");
236 EXPECT_EQ(1u, body_id);
237 EXPECT_EQ(std::numeric_limits<unsigned int>::max(), model->GetBodyId(
"unknownbody"));
247 VectorNd Q = VectorNd::Zero(model->q_size);
251 jcalc(*model, 1, Q, QDot);
253 SpatialMatrix test_matrix(1., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0.,
260 EXPECT_EQ(test_joint_axis, model->S[1]);
265 jcalc(*model, 1, Q, QDot);
267 test_matrix.
set(0., 1., 0., 0., 0., 0., -1., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., -1., 0., 0., 0., 0., 0., 0., 0., 1.);
271 EXPECT_EQ(test_joint_axis, model->S[1]);
279 Joint(
SpatialVector(0., 0., 0., 1., 0., 0.),
SpatialVector(0., 0., 0., 0., 1., 0.),
SpatialVector(0., 0., 0., 0., 0., 1.),
280 SpatialVector(0., 0., 1., 0., 0., 0.),
SpatialVector(0., 1., 0., 0., 0., 0.),
SpatialVector(1., 0., 0., 0., 0., 0.)),
283 VectorNd q = VectorNd::Zero(model->dof_count);
284 VectorNd qdot = VectorNd::Zero(model->dof_count);
285 VectorNd qddot = VectorNd::Zero(model->dof_count);
286 VectorNd tau = VectorNd::Zero(model->dof_count);
293 FramePoint p_base_coords(model->bodyFrames[body_id], base_coords);
296 p_base_coords.
changeFrame(model->bodyFrames[body_id]);
310 p_base_coords.
changeFrame(model->bodyFrames[body_id]);
365 Joint joint_rot_zx(
SpatialVector(0., 0., 1., 0., 0., 0.),
SpatialVector(1., 0., 0., 0., 0., 0.));
399 unsigned int body_id;
410 EXPECT_EQ(model_std.
mass, 2.0);
412 Joint joint_rot_zyx(
SpatialVector(0., 0., 1., 0., 0., 0.),
SpatialVector(0., 1., 0., 0., 0., 0.),
SpatialVector(1., 0., 0., 0., 0., 0.));
421 EXPECT_EQ(model_2.
mass, 2.0);
451 unsigned int body_id;
466 Joint joint_rot_zyx_tr_x(
SpatialVector(0., 0., 1., 0., 0., 0.),
SpatialVector(0., 1., 0., 0., 0., 0.),
SpatialVector(1., 0., 0., 0., 0., 0.),
506 unsigned int body_id;
523 Joint joint_rot_zyx_tr_xy(
SpatialVector(0., 0., 1., 0., 0., 0.),
SpatialVector(0., 1., 0., 0., 0., 0.),
SpatialVector(1., 0., 0., 0., 0., 0.),
524 SpatialVector(0., 0., 0., 1., 0., 0.),
SpatialVector(0., 0., 0., 0., 1., 0.));
561 unsigned int body_id;
563 Joint joint_floating_base(
SpatialVector(0., 0., 0., 1., 0., 0.),
SpatialVector(0., 0., 0., 0., 1., 0.),
SpatialVector(0., 0., 0., 0., 0., 1.),
564 SpatialVector(0., 0., 1., 0., 0., 0.),
SpatialVector(0., 1., 0., 0., 0., 0.),
SpatialVector(1., 0., 0., 0., 0., 0.));
572 Joint joint_rot_zyx(
SpatialVector(0., 0., 1., 0., 0., 0.),
SpatialVector(0., 1., 0., 0., 0., 0.),
SpatialVector(1., 0., 0., 0., 0., 0.));
612 EXPECT_EQ(fixed_body_id, model.
GetBodyId(
"fixed_body"));
635 EXPECT_EQ(movable_body + 1, appended_body_id);
636 EXPECT_EQ(movable_body, model.
lambda[appended_body_id]);
645 double movable_mass = 1.1;
648 double fixed_mass = 1.2;
651 Vector3d fixed_displacement(0., 1., 0.);
653 Body body(movable_mass, movable_com,
Vector3d(1., 1., 1.));
654 Body fixed_body(fixed_mass, fixed_com,
Vector3d(1., 1., 1.));
665 EXPECT_EQ(movable_body + 1, appended_body_id);
666 EXPECT_EQ(movable_body, model.
lambda[appended_body_id]);
667 EXPECT_EQ(movable_mass + fixed_mass * 2., model.
mBodies[movable_body].mMass);
672 double new_mass = 3.5;
674 (1. / new_mass) * (movable_mass * movable_com + fixed_mass * (fixed_com + fixed_displacement) + fixed_mass * (fixed_com + fixed_displacement * 2.));
696 model.
addBody(0, trans_x, joint_rot_z, body);
698 unsigned int body_after_fixed = model.
appendBody(trans_x, joint_rot_z, body);
701 Q[0] = 45 * M_PI / 180.;
730 model.
addBody(0, rot_z, joint_rot_z, body);
732 unsigned int body_after_fixed = model.
appendBody(trans_x, joint_rot_z, body);
735 Q[0] = 45 * M_PI / 180.;
758 EXPECT_EQ(
string(
"fixed_body"), model.
GetBodyName(fixed_body_id));
759 EXPECT_EQ(
string(
"appended_body"), model.
GetBodyName(appended_body_id));
765 EXPECT_EQ(0u, model->GetParentBodyId(0));
766 EXPECT_EQ(0u, model->GetParentBodyId(body_a_id));
767 EXPECT_EQ(body_a_id, model->GetParentBodyId(body_b_id));
772 EXPECT_EQ(body_b_id, model->GetParentBodyId(body_fixed_id));
799 model->SetJointFrame(body_a_id, new_transform_a);
800 model->SetJointFrame(body_b_id, new_transform_b);
801 model->SetJointFrame(0, new_transform_root);
813 model->SetJointFrame(model->fixed_body_discriminator + 1, new_transform_root);
818 EXPECT_STREQ(e.
what(),
"Error: setting of parent transform not supported for fixed bodies!");
832 unsigned int body_id_fixed = model_fixed.
appendBody(
Xroty(45 * M_PI / 180), joint_fixed, body);
835 unsigned int body_id_movable = model_movable.
appendBody(
Xroty(45 * M_PI / 180), joint_rot_x, body);
856 unsigned int id = model.
addBody(0,
Xrotx(0.1), joint, body,
"body_1");
865 EXPECT_STREQ(
"Error: Body with name 'body_1' already exists!", e.
what());
876 unsigned int fbid = model.
addBody(0,
Xrotx(0.1), joint_fixed, body,
"body_1");
880 model.
addBody(fbid,
Xrotx(0.1), joint_fixed, body,
"body_1");
885 EXPECT_STREQ(
"Error: Fixed body with name 'body_1' already exists!", e.
what());
911 int main(
int argc,
char** argv)
913 ::testing::InitGoogleTest(&argc, argv);
914 return RUN_ALL_TESTS();
Joint joint_rot_z(SpatialVector(0., 0., 1., 0., 0., 0.))
static bool checkVectorNdEpsilonClose(const RobotDynamics::Math::VectorNd &v1, const RobotDynamics::Math::VectorNd &v2, const double epsilon)
File containing the FramePoint<T> object definition.
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.
SpatialTransform Xroty(const double &yrot)
Get transform with zero translation and pure rotation about y axis.
std::vector< FixedBody > mFixedBodies
All bodies that are attached to a body via a fixed joint.
std::vector< unsigned int > lambda
SpatialTransform Xtrans(const Vector3d &r)
Get pure translation transform.
Fixed joint which causes the inertial properties to be merged with.
void jcalc(Model &model, unsigned int joint_id, const Math::VectorNd &q, const Math::VectorNd &qdot)
Computes all variables for a joint model and updates the body frame as well as the body's center of m...
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::vector< ReferenceFramePtr > bodyFrames
void set(const Scalar &m00, const Scalar &m01, const Scalar &m02, const Scalar &m03, const Scalar &m04, const Scalar &m05, const Scalar &m10, const Scalar &m11, const Scalar &m12, const Scalar &m13, const Scalar &m14, const Scalar &m15, const Scalar &m20, const Scalar &m21, const Scalar &m22, const Scalar &m23, const Scalar &m24, const Scalar &m25, const Scalar &m30, const Scalar &m31, const Scalar &m32, const Scalar &m33, const Scalar &m34, const Scalar &m35, const Scalar &m40, const Scalar &m41, const Scalar &m42, const Scalar &m43, const Scalar &m44, const Scalar &m45, const Scalar &m50, const Scalar &m51, const Scalar &m52, const Scalar &m53, const Scalar &m54, const Scalar &m55)
ReferenceFramePtr worldFrame
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.
SpatialTransform Xrotz(const double &zrot)
Get transform with zero translation and pure rotation about z axis.
EIGEN_STRONG_INLINE void setIncludingFrame(const Math::Vector3d &v, ReferenceFramePtr referenceFrame)
Set both the ReferenceFrame this object is expressed in as well as the (x,y,z) coordinates of the poi...
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...
virtual void changeFrame(ReferenceFramePtr desiredFrame)
Change the ReferenceFrame this FrameObject is expressed in.
std::vector< Body > mBodies
All bodies 0 ... N_B, including the base.
virtual const char * what() const
Describes a joint relative to the predecessor body.
unsigned int GetBodyId(const char *body_name) const
Returns the id of a body that was passed to addBody()
SpatialTransform Xrotx(const double &xrot)
Get transform with zero translation and pure rotation about x axis.
void updateKinematics(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &QDDot)
Updates and computes velocities and accelerations of the bodies.
Math::SpatialVector * mJointAxes
The spatial axes of the joint.
static bool checkSpatialMatrixEpsilonClose(const RobotDynamics::Math::SpatialMatrix &t1, const RobotDynamics::Math::SpatialMatrix &t2, const double epsilon)
Contains all information about the rigid body model.
A 6-DoF joint for floating-base (or freeflyer) systems.
void updateKinematicsCustom(Model &model, const Math::VectorNd *Q, const Math::VectorNd *QDot=nullptr, const Math::VectorNd *QDDot=nullptr)
Selectively updates model internal states of body positions, velocities and/or accelerations.
TEST_F(RdlModelFixture, testCommonParentId)
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)
int main(int argc, char **argv)
unsigned int fixed_body_discriminator
Value that is used to discriminate between fixed and movable bodies.
static bool checkVector3dEpsilonClose(const RobotDynamics::Math::Vector3d &v1, const RobotDynamics::Math::Vector3d &v2, const double epsilon)
std::string GetBodyName(unsigned int body_id) const
Returns the name of a body for a given body id.
std::vector< ReferenceFramePtr > fixedBodyFrames
void forwardDynamics(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &Tau, Math::VectorNd &QDDot, Math::SpatialForceV *f_ext=nullptr, bool update_kinematics=true)
Computes forward dynamics with the Articulated Body Algorithm.
unsigned int dof_count
number of degrees of freedoms of the model
static Matrix3d toMatrix(const Quaternion &q)
Convert quaternion to rotation matrix.
Namespace for all structures of the RobotDynamics library.
static bool checkMatrix3dEpsilonClose(const RobotDynamics::Math::Matrix3d &t1, const RobotDynamics::Math::Matrix3d &t2, const double epsilon)