3 #include <gtest/gtest.h> 23 for (
int i = 0; i <
Q.size(); i++)
25 Q[i] = 0.4 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
26 QDot[i] = 0.5 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
27 Tau[i] = 0.5 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
28 QDDot[i] = 0.5 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
70 body_a_id = model->addBody(0,
Xtrans(
Vector3d(0., 0., 0.)), joint_a, body_a,
"body_a");
76 body_b_id = model->addBody(1,
Xtrans(
Vector3d(0., 0., -1.)), joint_b, body_b,
"body_b");
82 body_c_id = model->addBody(2,
Xtrans(
Vector3d(0., 0., -2.)), joint_c, body_c,
"body_c");
89 fixed_body_c_id = model->addBody(body_c_id, X_fixed_c, fixed_joint, fixed_body,
"fixed_body_c");
90 fixed_body_c_2_id = model->addBody(fixed_body_c_id, X_fixed_c2, fixed_joint, fixed_body,
"fixed_body_c_2");
105 unsigned int body_a_id, body_b_id, body_c_id,
ref_body_id, fixed_body_c_id, fixed_body_c_2_id;
176 body_a_id = model->addBody(0,
Xtrans(
Vector3d(0., 0., 0.)), joint_a, body_a,
"body_a");
184 body_b_id = model->addBody(body_a_id, X, joint_b, body_b,
"body_b");
192 body_c_id = model->addBody(2, X, joint_c, body_c,
"body_c");
197 body_d_id = model->addBody(0,
Xtrans(
Vector3d(0., 0., 0.)), joint_d, body_d,
"body_d");
205 body_e_id = model->addBody(body_d_id, X, joint_e, body_e,
"body_e");
213 body_f_id = model->addBody(body_e_id, X, joint_f, body_f,
"body_f");
215 Q = VectorNd::Constant((
size_t)model->dof_count, 0.);
216 QDot = VectorNd::Constant((
size_t)model->dof_count, 0.);
217 QDDot = VectorNd::Constant((
size_t)model->dof_count, 0.);
218 Tau = VectorNd::Constant((
size_t)model->dof_count, 0.);
228 unsigned int body_a_id, body_b_id, body_c_id, body_d_id, body_e_id,
body_f_id;
243 srand(time(
nullptr));
273 root_body_id = model->appendBody(X, root_joint, root_body,
"floating_body");
281 body_1_id = model->addBody(root_body_id, X, joint_1, body_1,
"body_1");
289 body_2_id = model->addBody(root_body_id, X, joint_2, body_2,
"body_2");
291 Q = VectorNd::Constant((
size_t)model->dof_count + 1, 0.);
292 QDot = VectorNd::Constant((
size_t)model->dof_count, 0.);
293 QDDot = VectorNd::Constant((
size_t)model->dof_count, 0.);
294 Tau = VectorNd::Constant((
size_t)model->dof_count, 0.);
299 for (
int i = 0; i <
Q.size(); i++)
301 Q[i] = 0.4 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
303 for (
int i = 0; i <
QDot.size(); i++)
305 QDot[i] = 0.1 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
306 Tau[i] = 0.5 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
307 QDDot[i] = 0.5 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
311 q = model->GetQuaternion(root_body_id,
Q);
313 model->SetQuaternion(root_body_id, q,
Q);
356 body_a_id = model->addBody(0,
Xtrans(
Vector3d(0., 0., 0.)), joint_a, body_a,
"body_a");
361 body_b_id = model->addBody(1,
Xtrans(
Vector3d(1., 0., 0.)), joint_b, body_b,
"body_b");
366 body_c_id = model->addBody(2,
Xtrans(
Vector3d(0., 1., 0.)), joint_c, body_c,
"body_c");
368 Q = VectorNd::Constant((
size_t)model->dof_count, 0.);
369 QDot = VectorNd::Constant((
size_t)model->dof_count, 0.);
370 QDDot = VectorNd::Constant((
size_t)model->dof_count, 0.);
371 Tau = VectorNd::Constant((
size_t)model->dof_count, 0.);
373 point_position = Vector3d::Zero(3);
374 point_acceleration = Vector3d::Zero(3);
429 base_rot_z_id = model->addBody(0,
Xtrans(
Vector3d(0., 0., 0.)), joint_base_rot_z, base_rot_z);
433 base_rot_y_id = model->appendBody(
Xtrans(
Vector3d(0., 0., 0.)), joint_base_rot_y, base_rot_y);
437 base_rot_x_id = model->addBody(base_rot_y_id,
Xtrans(
Vector3d(0., 0., 0.)), joint_base_rot_x, base_rot_x);
442 child_rot_z_id = model->addBody(base_rot_x_id,
Xtrans(
Vector3d(1., 0., 0.)), joint_child_rot_z, child_rot_z);
446 child_rot_y_id = model->addBody(child_rot_z_id,
Xtrans(
Vector3d(0., 0., 0.)), joint_child_rot_y, child_rot_y);
450 child_rot_x_id = model->addBody(child_rot_y_id,
Xtrans(
Vector3d(0., 0., 0.)), joint_child_rot_x, child_rot_x);
452 Q = VectorNd::Constant(model->mBodies.size() - 1, 0.);
453 QDot = VectorNd::Constant(model->mBodies.size() - 1, 0.);
454 QDDot = VectorNd::Constant(model->mBodies.size() - 1, 0.);
455 Tau = VectorNd::Constant(model->mBodies.size() - 1, 0.);
457 contact_body_id = child_rot_x_id;
458 contact_point =
Vector3d(0.5, 0.5, 0.);
459 contact_normal =
Vector3d(0., 1., 0.);
469 unsigned int base_rot_z_id, base_rot_y_id, base_rot_x_id,
child_rot_z_id, child_rot_y_id, child_rot_x_id, base_body_id;
516 Joint(
SpatialVector(0., 0., 0., 1., 0., 0.),
SpatialVector(0., 0., 0., 0., 1., 0.),
SpatialVector(0., 0., 0., 0., 0., 1.),
517 SpatialVector(0., 0., 1., 0., 0., 0.),
SpatialVector(0., 1., 0., 0., 0., 0.),
SpatialVector(1., 0., 0., 0., 0., 0.)),
523 child_rot_z_id = model->addBody(base_rot_x_id,
Xtrans(
Vector3d(1., 0., 0.)), joint_child_rot_z, child_rot_z);
527 child_rot_y_id = model->addBody(child_rot_z_id,
Xtrans(
Vector3d(0., 0., 0.)), joint_child_rot_y, child_rot_y);
531 child_rot_x_id = model->addBody(child_rot_y_id,
Xtrans(
Vector3d(0., 0., 0.)), joint_child_rot_x, child_rot_x);
536 child_2_rot_z_id = model->addBody(child_rot_x_id,
Xtrans(
Vector3d(1., 0., 0.)), joint_child_2_rot_z, child_2_rot_z);
540 child_2_rot_y_id = model->addBody(child_2_rot_z_id,
Xtrans(
Vector3d(0., 0., 0.)), joint_child_2_rot_y, child_2_rot_y);
544 child_2_rot_x_id = model->addBody(child_2_rot_y_id,
Xtrans(
Vector3d(0., 0., 0.)), joint_child_2_rot_x, child_2_rot_x);
546 Q = VectorNd::Constant(model->dof_count, 0.);
547 QDot = VectorNd::Constant(model->dof_count, 0.);
548 QDDot = VectorNd::Constant(model->dof_count, 0.);
549 Tau = VectorNd::Constant(model->dof_count, 0.);
559 unsigned int base_rot_z_id, base_rot_y_id, base_rot_x_id,
child_rot_z_id, child_rot_y_id, child_rot_x_id, child_2_rot_z_id, child_2_rot_y_id, child_2_rot_x_id,
565 joint_child_2_rot_y, joint_child_2_rot_x;
592 Q = RobotDynamics::Math::VectorNd::Zero(model->dof_count);
593 QDot = RobotDynamics::Math::VectorNd::Zero(model->dof_count);
594 QDDot = RobotDynamics::Math::VectorNd::Zero(model->dof_count);
595 Tau = RobotDynamics::Math::VectorNd::Zero(model->dof_count);
634 body_a_id = model->addBody(0,
Xtrans(
Vector3d(0., 0., 0.)), joint_a, body_a);
639 body_b_id = model->addBody(1,
Xtrans(
Vector3d(1., 0., 0.)), joint_b, body_b);
644 body_c_id = model->addBody(2,
Xtrans(
Vector3d(0., 1., 0.)), joint_c, body_c);
646 Q = VectorNd::Constant((
size_t)model->dof_count, 0.);
647 QDot = VectorNd::Constant((
size_t)model->dof_count, 0.);
648 QDDot = VectorNd::Constant((
size_t)model->dof_count, 0.);
650 point_position = Vector3d::Zero(3);
651 point_acceleration = Vector3d::Zero(3);
687 model_movable =
new Model;
704 body_a_id = model_movable->addBody(0,
Xtrans(
Vector3d(0., 0., 0.)), joint_a, body_a);
709 body_b_id = model_movable->addBody(body_a_id,
Xtrans(
Vector3d(1., 0., 0.)), joint_b, body_b);
714 body_c_id = model_movable->addBody(body_b_id,
Xtrans(
Vector3d(0., 1., 0.)), joint_c, body_c);
716 Q = VectorNd::Constant((
size_t)model_movable->dof_count, 0.);
717 QDot = VectorNd::Constant((
size_t)model_movable->dof_count, 0.);
718 QDDot = VectorNd::Constant((
size_t)model_movable->dof_count, 0.);
719 Tau = VectorNd::Constant((
size_t)model_movable->dof_count, 0.);
720 C_movable = VectorNd::Zero((
size_t)model_movable->dof_count);
721 H_movable = MatrixNd::Zero((
size_t)model_movable->dof_count, (
size_t)model_movable->dof_count);
724 model_fixed =
new Model;
728 body_b_fixed_id = model_fixed->addBody(body_a_fixed_id,
Xtrans(
Vector3d(1., 0., 0.)), joint_fixed, body_b,
"body_b");
729 body_c_fixed_id = model_fixed->addBody(body_b_fixed_id,
Xtrans(
Vector3d(0., 1., 0.)), joint_c, body_c,
"body_c");
731 Q_fixed = VectorNd::Constant((
size_t)model_fixed->dof_count, 0.);
732 QDot_fixed = VectorNd::Constant((
size_t)model_fixed->dof_count, 0.);
733 QDDot_fixed = VectorNd::Constant((
size_t)model_fixed->dof_count, 0.);
734 Tau_fixed = VectorNd::Constant((
size_t)model_fixed->dof_count, 0.);
735 C_fixed = VectorNd::Zero((
size_t)model_fixed->dof_count);
736 H_fixed = MatrixNd::Zero((
size_t)model_fixed->dof_count, (
size_t)model_fixed->dof_count);
738 point_position = Vector3d::Zero(3);
739 point_acceleration = Vector3d::Zero(3);
746 delete model_movable;
752 assert(q_fixed.size() == model_fixed->dof_count);
756 q_movable[0] = q_fixed[0];
758 q_movable[2] = q_fixed[1];
765 assert(H_movable.rows() == model_movable->dof_count);
766 assert(H_movable.cols() == model_movable->dof_count);
769 H(0, 0) = H_movable(0, 0);
770 H(0, 1) = H_movable(0, 2);
771 H(1, 0) = H_movable(2, 0);
772 H(1, 1) = H_movable(2, 2);
820 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.));
830 body_a_id = model->addBody(0, fixture_transform_a, joint_rot_z, body_a);
831 body_b_id = model->appendBody(fixture_transform_b, joint_rot_zyx, body_b);
832 body_fixed_id = model->appendBody(fixture_transform_fixed,
Joint(
JointTypeFixed), body_fixed);
852 for (
int i = 0; i <
Q.size(); i++)
854 Q[i] = 0.4 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
855 QDot[i] = 0.5 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
856 Tau[i] = 0.5 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
857 QDDot[i] = 0.5 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
879 srand(time(
nullptr));
904 Joint joint_zyx =
Joint(
SpatialVector(0., 0., 1., 0., 0., 0.),
SpatialVector(0., 1., 0., 0., 0., 0.),
SpatialVector(1., 0., 0., 0., 0., 0.));
906 right_upper_arm = model->appendBody(
Xtrans(
Vector3d(0., 0., -0.3)), joint_zyx, body_upper,
"RightUpper");
908 left_upper_arm = model->addBody(0,
Xtrans(
Vector3d(0., 0., 0.3)), joint_zyx, body_upper,
"LeftUpper");
911 q = VectorNd::Constant((
size_t)model->dof_count, 0.);
912 qdot = VectorNd::Constant((
size_t)model->dof_count, 0.);
913 qddot = VectorNd::Constant((
size_t)model->dof_count, 0.);
914 tau = VectorNd::Constant((
size_t)model->dof_count, 0.);
919 for (
int i = 0; i < q.size(); i++)
921 q[i] = 0.4 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
922 qdot[i] = 0.5 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
923 tau[i] = 0.5 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
924 qddot[i] = 0.5 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
973 Joint(
SpatialVector(0., 0., 0., 1., 0., 0.),
SpatialVector(0., 0., 0., 0., 1., 0.),
SpatialVector(0., 0., 0., 0., 0., 1.),
974 SpatialVector(0., 0., 1., 0., 0., 0.),
SpatialVector(0., 1., 0., 0., 0., 0.),
SpatialVector(1., 0., 0., 0., 0., 0.)),
979 joint_rotzyx =
Joint(
SpatialVector(0., 0., 1., 0., 0., 0.),
SpatialVector(0., 1., 0., 0., 0., 0.),
SpatialVector(1., 0., 0., 0., 0., 0.));
980 child_id = model->addBody(base_id,
Xtrans(
Vector3d(1., 0., 0.)), joint_rotzyx, child);
984 child_2_id = model->addBody(child_id,
Xtrans(
Vector3d(1., 0., 0.)), joint_rotzyx, child_2);
986 Q = VectorNd::Constant(model->dof_count, 0.);
987 QDot = VectorNd::Constant(model->dof_count, 0.);
988 QDDot = VectorNd::Constant(model->dof_count, 0.);
989 Tau = VectorNd::Constant(model->dof_count, 0.);
991 contact_body_id = child_id;
992 contact_point =
Vector3d(0.5, 0.5, 0.);
993 contact_normal =
Vector3d(0., 1., 0.);
Joint joint_rot_z(SpatialVector(0., 0., 1., 0., 0., 0.))
RobotDynamics::Model * model
RobotDynamics::Joint joint_f
RobotDynamics::Joint joint_c
RobotDynamics::Math::VectorNd Tau
RobotDynamics::Math::VectorNd QDDot
Math::FrameVector point_accel
RobotDynamics::Math::VectorNd QDot
RobotDynamics::Joint root_joint
RobotDynamics::Math::VectorNd Q
Describes all properties of a single body.
RobotDynamics::Math::VectorNd Q_fixed
RobotDynamics::Math::VectorNd Tau
unsigned int body_c_fixed_id
RobotDynamics::Math::VectorNd Tau
RobotDynamics::Math::Vector3d contact_normal
RobotDynamics::Math::MatrixNd CreateReducedInertiaMatrix(const RobotDynamics::Math::MatrixNd &H_movable)
RobotDynamics::Math::VectorNd Q
RobotDynamics::Math::VectorNd Tau
RobotDynamics::Math::Vector3d contact_point
FixedBaseTwoChain6DoF3D()
RobotDynamics::Math::VectorNd Q
RobotDynamics::Math::VectorNd Tau
RobotDynamics::Math::VectorNd QDDot
RobotDynamics::Model * model
FloatingBaseWith2SingleDofJoints()
Matrix3d Matrix3dIdentity
RobotDynamics::Math::Vector3d contact_normal
RobotDynamics::Math::VectorNd QDDot
unsigned int body_fixed_id
Fixture that contains two models of which one has one joint fixed.
RobotDynamics::Math::VectorNd qdot
RobotDynamics::Math::VectorNd QDDot_fixed
RobotDynamics::Math::VectorNd QDDot
RobotDynamics::Math::VectorNd QDot
RobotDynamics::Math::MatrixNd H_fixed
RobotDynamics::Math::SpatialTransform fixture_transform_a
RobotDynamics::Math::VectorNd QDot
RobotDynamics::Joint joint_c
RobotDynamics::Math::VectorNd Q
RobotDynamics::Math::VectorNd QDDot
SpatialTransform Xtrans(const Vector3d &r)
Get pure translation transform.
RobotDynamics::Model * model
Fixed joint which causes the inertial properties to be merged with.
unsigned int root_body_id
RobotDynamics::Math::VectorNd QDot
RobotDynamics::Math::VectorNd Tau_fixed
RobotDynamics::Math::VectorNd QDDot
RobotDynamics::Model * model
RobotDynamics::ConstraintSet constraint_set
RobotDynamics::Math::VectorNd CreateDofVectorFromReducedVector(const RobotDynamics::Math::VectorNd &q_fixed)
Math::MotionVector gravity
the cartesian vector of the gravity
RobotDynamics::Body body_c
RobotDynamics::Math::VectorNd Q
RobotDynamics::Math::MatrixNd H_movable
RobotDynamics::Math::VectorNd QDot
RobotDynamics::Math::VectorNd QDot
RobotDynamics::Model * model
RobotDynamics::Model * model
RobotDynamics::Math::VectorNd Q
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.
RobotDynamics::Math::VectorNd QDDot
RobotDynamics::Math::VectorNd QDDot
RobotDynamics::Math::VectorNd QDot
RobotDynamics::Body child_2
unsigned int child_rot_z_id
SpatialTransform Xrotz(const double &zrot)
Get transform with zero translation and pure rotation about z axis.
RobotDynamics::Math::SpatialTransform fixture_transform_fixed
RobotDynamics::Body root_body
unsigned int child_rot_z_id
Structure that contains both constraint information and workspace memory.
RobotDynamics::Math::VectorNd QDot
RobotDynamics::Math::VectorNd QDDot
A FrameVector is a 3D vector with a ReferenceFrame, and all operations between FrameVectors and other...
RobotDynamics::Math::VectorNd C_fixed
RobotDynamics::Math::VectorNd QDDot
RobotDynamics::ConstraintSet constraint_set
RobotDynamics::Body child_rot_z
RobotDynamics::Math::VectorNd Q
RobotDynamics::Model * model_fixed
RobotDynamics::Math::VectorNd QDot_fixed
Describes a joint relative to the predecessor body.
Quaternion that are used for singularity free joints.
RobotDynamics::Math::Vector3d point_position
RobotDynamics::Math::VectorNd Tau
RobotDynamics::Math::VectorNd Tau
SpatialTransform Xrotx(const double &xrot)
Get transform with zero translation and pure rotation about x axis.
RobotDynamics::Math::Vector3d contact_point
RobotDynamics::Joint joint_c
RobotDynamics::Body fixed_body
RobotDynamics::Math::VectorNd Tau
RobotDynamics::Math::VectorNd QDot
RobotDynamics::Math::VectorNd Q
RobotDynamics::Model * model
RobotDynamics::Body body_c
Contains all information about the rigid body model.
RobotDynamics::Joint joint_child_rot_z
A 6-DoF joint for floating-base (or freeflyer) systems.
Math types such as vectors and matrices and utility functions.
RobotDynamics::Model * model
RobotDynamics::Math::VectorNd C_movable
FixedBase6DoF12DoFFloatingBase()
SpatialTransform X_fixed_c2
RobotDynamics::Math::VectorNd QDDot
RobotDynamics::Math::VectorNd q
RobotDynamics::Model * model
RobotDynamics::Math::Vector3d point_position
RobotDynamics::Math::VectorNd Tau
RobotDynamics::Joint joint_child_rot_z
RobotDynamics::Body child_rot_z
RobotDynamics::Model * model
RobotDynamics::Joint joint_c
RobotDynamics::Joint joint_rotzyx
RobotDynamics::Math::VectorNd Q
RobotDynamics::Math::VectorNd Tau
RobotDynamics::Math::Vector3d point_position
RobotDynamics::Math::VectorNd tau
RobotDynamics::Math::VectorNd Q
RobotDynamics::Model * model
RobotDynamics::Math::SpatialTransform fixture_transform_b
RobotDynamics::Math::VectorNd qddot
RobotDynamics::Math::VectorNd QDot
RobotDynamics::Body body_f
unsigned int contact_body_id
RobotDynamics::Math::VectorNd QDot
RobotDynamics::Model * model_movable
RobotDynamics::Body body_c
Namespace for all structures of the RobotDynamics library.
unsigned int contact_body_id
RobotDynamics::Math::VectorNd Q
unsigned int right_upper_arm