1 #include <gtest/gtest.h> 30 for (
int i = 0; i < q.rows(); i++)
32 q[i] = 0.4 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
35 for (
int i = 0; i < qdot.rows(); i++)
37 qdot[i] = 0.5 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
38 tau[i] = 0.5 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
39 qddot[i] = 0.5 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
76 body_a_id = model->addBody(0,
Xtrans(
Vector3d(0., 0., 0.)), joint_a, body_a,
"body_a");
81 body_b_id = model->addBody(body_a_id,
Xtrans(
Vector3d(1., 0., 0.)), joint_b, body_b,
"body_b");
86 body_c_id = model->addBody(body_b_id,
Xtrans(
Vector3d(0., 1., 0.)), joint_c, body_c,
"body_c");
91 body_d_id = model->addBody(body_c_id,
Xtrans(
Vector3d(0., 0., -1.)), joint_d, body_d,
"body_d");
93 Q = VectorNd::Constant((
size_t)model->dof_count, 0.);
94 QDot = VectorNd::Constant((
size_t)model->dof_count, 0.);
95 QDDot = VectorNd::Constant((
size_t)model->dof_count, 0.);
96 Tau = VectorNd::Constant((
size_t)model->dof_count, 0.);
101 for (
int i = 0; i <
Q.size(); i++)
103 Q[i] = 0.4 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
104 QDot[i] = 0.5 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
105 Tau[i] = 0.5 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
106 QDDot[i] = 0.5 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
118 unsigned int body_a_id, body_b_id, body_c_id,
body_d_id;
153 joint_rotzyx =
Joint(
SpatialVector(0., 0., 1., 0., 0., 0.),
SpatialVector(0., 1., 0., 0., 0., 0.),
SpatialVector(1., 0., 0., 0., 0., 0.));
154 base_id = model->addBody(0,
Xtrans(
Vector3d(0., 0., 0.)), joint_rotzyx, base);
158 child_id = model->addBody(base_id,
Xtrans(
Vector3d(1., 0., 0.)), joint_rotzyx, child);
160 Q = VectorNd::Constant(model->mBodies.size() - 1, 0.);
161 QDot = VectorNd::Constant(model->mBodies.size() - 1, 0.);
162 QDDot = VectorNd::Constant(model->mBodies.size() - 1, 0.);
163 Tau = VectorNd::Constant(model->mBodies.size() - 1, 0.);
236 q = RobotDynamics::Math::VectorNd::Zero(model->q_size);
237 qdot = RobotDynamics::Math::VectorNd::Zero(model->qdot_size);
238 qddot = RobotDynamics::Math::VectorNd::Zero(model->qdot_size);
239 tau = RobotDynamics::Math::VectorNd::Zero(model->qdot_size);
245 for (std::pair<std::string, RobotDynamics::ReferenceFramePtr> pair : model->referenceFrameMap)
253 for (
unsigned int i = 0; i < model->v.size(); ++i)
312 q = RobotDynamics::Math::VectorNd::Zero(model->q_size);
313 qdot = RobotDynamics::Math::VectorNd::Zero(model->qdot_size);
314 qddot = RobotDynamics::Math::VectorNd::Zero(model->qdot_size);
315 tau = RobotDynamics::Math::VectorNd::Zero(model->qdot_size);
321 for (std::pair<std::string, RobotDynamics::ReferenceFramePtr> pair : model->referenceFrameMap)
329 for (
unsigned int i = 0; i < model->v.size(); ++i)
338 for (std::pair<std::string, RobotDynamics::ReferenceFramePtr> pair : model->referenceFrameMap)
346 for (
unsigned int i = 0; i < model->v.size(); ++i)
355 for (std::pair<std::string, RobotDynamics::ReferenceFramePtr> pair : model->referenceFrameMap)
363 for (
unsigned int i = 0; i < model->v.size(); ++i)
373 FramePoint p_a(model->bodyFrames[1], 0., 0., 0.);
374 FramePoint p_b(model->bodyFrames[2], 0., 0., 0.);
375 FramePoint p_c(model->bodyFrames[3], 0., 0., 0.);
376 FramePoint p_d(model->bodyFrames[4], 0., 0., 0.);
393 FramePoint p_a(model->bodyFrames[1], 0., 0., 0.);
394 FramePoint p_b(model->bodyFrames[2], 0., 0., 0.);
395 FramePoint p_c(model->bodyFrames[3], 0., 0., 0.);
396 FramePoint p_d(model->bodyFrames[4], 0., 0., 0.);
413 FramePoint p_a(model->bodyFrames[1], 0., 0., 0.);
414 FramePoint p_b(model->bodyFrames[2], 0., 0., 0.);
415 FramePoint p_c(model->bodyFrames[3], 0., 0., 0.);
416 FramePoint p_d(model->bodyFrames[4], 0., 0., 0.);
433 FramePoint p_a(model->bodyFrames[1], 0., 0., 0.);
434 FramePoint p_b(model->bodyFrames[2], 0., 0., 0.);
435 FramePoint p_c(model->bodyFrames[3], 0., 0., 0.);
436 FramePoint p_d(model->bodyFrames[4], 0., 0., 0.);
455 FramePoint p_a(model->bodyFrames[1], 0., 0., 0.);
456 FramePoint p_b(model->bodyFrames[2], 0., 0., 0.);
457 FramePoint p_c(model->bodyFrames[3], 0., 0., 0.);
458 FramePoint p_d(model->bodyFrames[4], 0., 0., 0.);
473 FramePoint p_c(model->bodyFrames[3], 0., 1., 0.);
484 FramePoint p_c(model->bodyFrames[3], 0., 0., 0.);
549 MatrixNd G3d(3, model->qdot_size), G3dCheck(3, model->qdot_size);
553 calcPointJacobian(*model,
Q, body_b_id, body_c_frame->getTransformFromParent().r, G3dCheck);
574 fb_frame = model->getReferenceFrame(
"fb2");
592 MatrixNd G(6, model->qdot_size), GCheck(6, model->qdot_size);
620 EXPECT_TRUE(v.getLinearPart().isApprox(p.linear(),
TEST_PREC));
621 EXPECT_TRUE(v.getAngularPart().isApprox(p.angular(),
TEST_PREC));
626 fb_frame = model->getReferenceFrame(
"fb2");
636 EXPECT_TRUE(v.getLinearPart().isApprox(p.linear(),
TEST_PREC));
637 EXPECT_TRUE(v.getAngularPart().isApprox(p.angular(),
TEST_PREC));
708 MatrixNd G3d(3, model->qdot_size), G3dCheck(3, model->qdot_size);
733 fb_frame = model->getReferenceFrame(
"fb2");
773 MatrixNd GDot(6, model->qdot_size), G(6, model->qdot_size), GDot2(6, model->qdot_size), G2(6, model->qdot_size);
795 model->gravity.setZero();
835 model->gravity.setZero();
857 MatrixNd GDot(6, model->qdot_size), G(6, model->qdot_size), GDot2(6, model->qdot_size), G2(6, model->qdot_size);
904 MatrixNd G(6, model->qdot_size), GDot(6, model->qdot_size);
928 MatrixNd G(6, model->qdot_size), GDot(6, model->qdot_size), G2(6, model->qdot_size), GDot2(6, model->qdot_size);
951 ReferenceFramePtr body_fixed_frame = model->fixedBodyFrames[body_fixed_id - model->fixed_body_discriminator];
988 unsigned int body_trunk_id = model_3dof->GetBodyId(
"middletrunk");
989 unsigned int body_hand_r_id = model_3dof->GetBodyId(
"hand_r");
990 unsigned int body_hand_l_id = model_3dof->GetBodyId(
"hand_l");
998 MatrixNd G(6, model_3dof->qdot_size);
1010 unsigned int body_trunk_id = model_emulated->GetBodyId(
"middletrunk");
1011 unsigned int body_hand_r_id = model_emulated->GetBodyId(
"hand_r");
1012 unsigned int body_hand_l_id = model_emulated->GetBodyId(
"hand_l");
1014 ReferenceFramePtr body_hand_r_frame = model_emulated->bodyFrames[body_hand_r_id];
1015 ReferenceFramePtr body_hand_l_frame = model_emulated->bodyFrames[body_hand_l_id];
1019 MatrixNd GDot(6, model_emulated->qdot_size);
1035 unsigned int body_trunk_id = model_emulated->GetBodyId(
"middletrunk");
1036 unsigned int body_hand_r_id = model_emulated->GetBodyId(
"hand_r");
1037 unsigned int body_hand_l_id = model_emulated->GetBodyId(
"hand_l");
1039 ReferenceFramePtr body_hand_r_frame = model_emulated->bodyFrames[body_hand_r_id];
1040 ReferenceFramePtr body_hand_l_frame = model_emulated->bodyFrames[body_hand_l_id];
1044 MatrixNd GDot(6, model_emulated->qdot_size), G(6, model_emulated->qdot_size), GDot2(6, model_emulated->qdot_size), G2(6, model_emulated->qdot_size);
1064 unsigned int body_trunk_id = model_3dof->GetBodyId(
"middletrunk");
1065 unsigned int body_hand_r_id = model_3dof->GetBodyId(
"hand_r");
1066 unsigned int body_hand_l_id = model_3dof->GetBodyId(
"hand_l");
1073 MatrixNd GDot(6, model_3dof->qdot_size), G(6, model_3dof->qdot_size);
1091 unsigned int body_trunk_id = model_3dof->GetBodyId(
"middletrunk");
1092 unsigned int body_hand_r_id = model_3dof->GetBodyId(
"hand_r");
1093 unsigned int body_hand_l_id = model_3dof->GetBodyId(
"hand_l");
1100 MatrixNd GDot(6, model_3dof->qdot_size), G(6, model_3dof->qdot_size), GDot2(6, model_3dof->qdot_size), G2(6, model_3dof->qdot_size);
1120 unsigned int body_trunk_id = model_3dof->GetBodyId(
"uppertrunk");
1121 unsigned int body_hand_r_id = model_3dof->GetBodyId(
"hand_r");
1122 unsigned int body_hand_l_id = model_3dof->GetBodyId(
"hand_l");
1123 ReferenceFramePtr body_trunk_frame = model_3dof->fixedBodyFrames[body_trunk_id - model_3dof->fixed_body_discriminator];
1129 MatrixNd GDot(6, model_3dof->qdot_size), G(6, model_3dof->qdot_size);
1162 unsigned int body_trunk_id = model_3dof->GetBodyId(
"uppertrunk");
1163 unsigned int body_hand_r_id = model_3dof->GetBodyId(
"hand_r");
1164 unsigned int body_hand_l_id = model_3dof->GetBodyId(
"hand_l");
1165 ReferenceFramePtr body_trunk_frame = model_3dof->fixedBodyFrames[body_trunk_id - model_3dof->fixed_body_discriminator];
1171 MatrixNd GDot(6, model_3dof->qdot_size), G(6, model_3dof->qdot_size), GDot2(6, model_3dof->qdot_size), G2(6, model_3dof->qdot_size);
1216 Joint(
SpatialVector(0., 0., 0., 1., 0., 0.),
SpatialVector(0., 0., 0., 0., 1., 0.),
SpatialVector(0., 0., 0., 0., 0., 1.),
1217 SpatialVector(0., 0., 1., 0., 0., 0.),
SpatialVector(0., 1., 0., 0., 0., 0.),
SpatialVector(1., 0., 0., 0., 0., 0.)),
1230 Vector3d point_position(1.1, 1.2, 2.1);
1249 point_velocity_ref =
calcPointVelocity(model, Q, QDot, base_body_id, point_position);
1255 point_velocity = G *
QDot;
1260 point_position =
Vector3d(0.2, -0.1, 0.8);
1262 point_velocity_ref =
calcPointVelocity(model, Q, QDot, fixed_body1_id, point_position);
1268 point_velocity = G *
QDot;
1273 point_position =
Vector3d(1.2, -1.1, 1.8);
1275 point_velocity_ref =
calcPointVelocity(model, Q, QDot, fixed_body2_id, point_position);
1281 point_velocity = G *
QDot;
1289 std::vector<unsigned int> body_ids;
1290 std::vector<Vector3d> body_points;
1291 std::vector<Vector3d> target_pos;
1297 VectorNd Qres = VectorNd::Zero((
size_t)model->dof_count);
1299 unsigned int body_id = body_d_id;
1303 body_ids.push_back(body_d_id);
1304 body_points.push_back(body_point);
1305 target_pos.push_back(target);
1308 EXPECT_EQ(
true, res);
1312 FramePoint p(model->bodyFrames[body_id], body_point);
1320 std::vector<unsigned int> body_ids;
1321 std::vector<Vector3d> body_points;
1322 std::vector<Vector3d> target_pos;
1328 VectorNd Qres = VectorNd::Zero((
size_t)model->dof_count);
1330 unsigned int body_id = child_id;
1334 body_ids.push_back(body_id);
1335 body_points.push_back(body_point);
1336 target_pos.push_back(target);
1338 bool res =
inverseKinematics(*model,
Q, body_ids, body_points, target_pos, Qres, 1.0e-8, 0.9, 1000);
1340 EXPECT_EQ(
true, res);
1344 FramePoint p(model->bodyFrames[body_id], body_point);
1352 std::vector<unsigned int> body_ids;
1353 std::vector<Vector3d> body_points;
1354 std::vector<Vector3d> target_pos;
1360 VectorNd Qres = VectorNd::Zero((
size_t)model->dof_count);
1362 unsigned int body_id = child_id;
1366 body_ids.push_back(body_id);
1367 body_points.push_back(body_point);
1368 target_pos.push_back(target);
1370 body_ids.push_back(base_id);
1371 body_points.push_back(
Vector3d(0.6, 1.0, 0.));
1372 target_pos.push_back(
Vector3d(0.5, 1.1, 0.));
1374 bool res =
inverseKinematics(*model,
Q, body_ids, body_points, target_pos, Qres, 1.0e-3, 0.9, 200);
1375 EXPECT_EQ(
true, res);
1379 FramePoint p(model->bodyFrames[body_ids[0]], body_points[0]);
1532 Vector3d point_position(1., 0., 0.);
1547 unsigned int foot_r_id = model->GetBodyId(
"foot_r");
1548 MatrixNd G(MatrixNd::Zero(6, model->dof_count));
1570 unsigned int uppertrunk_id = model->GetBodyId(
"uppertrunk");
1571 MatrixNd G(MatrixNd::Zero(6, model->dof_count));
1576 unsigned int fixed_body_id = uppertrunk_id - model->fixed_body_discriminator;
1577 unsigned int movable_parent = model->mFixedBodies[fixed_body_id].mMovableParent;
1582 SpatialVector v_fixed_body = model->mFixedBodies[fixed_body_id].mParentTransform.apply(model->v[movable_parent]);
1589 unsigned int foot_r_id = model->GetBodyId(
"foot_r");
1591 Vector3d point_local(1.1, 2.2, 3.3);
1597 MatrixNd G(MatrixNd::Zero(6, model->dof_count));
1611 unsigned int foot_r_id = model->GetBodyId(
"foot_r");
1613 Vector3d point_local(1.1, 2.2, 3.3);
1620 MatrixNd G(MatrixNd::Zero(6, model->dof_count));
1623 ReferenceFramePtr expressedInFrame = model->getReferenceFrame(
"right_sole_frame");
1633 baseFrame = model->getReferenceFrame(
"pelvis");
1634 relFrame = model->getReferenceFrame(
"foot_r");
1635 expressedInFrame = model->getReferenceFrame(
"right_sole_frame");
1646 baseFrame = model->getReferenceFrame(
"right_sole_frame");
1647 relFrame = model->getReferenceFrame(
"foot_r");
1648 expressedInFrame = model->getReferenceFrame(
"pelvis");
1663 unsigned int foot_r_id = model->GetBodyId(
"foot_r");
1664 Vector3d point_local(1.1, 2.2, 3.3);
1672 FramePoint p(model->bodyFrames[foot_r_id], point_local);
1677 SpatialVector v_foot_0_ref = X_foot.apply(model->bodyFrames[foot_r_id]->getTransformToRoot().apply(model->v[foot_r_id]));
1687 unsigned int foot_r_id = model->GetBodyId(
"foot_r");
1725 fb_frame = model->getReferenceFrame(
"fb2");
1737 unsigned int foot_r_id = model->GetBodyId(
"foot_r");
1738 Vector3d point_local(1.1, 2.2, 3.3);
1742 unsigned int fixed_body_id = model->addBody(foot_r_id,
Xtrans(point_local),
Joint(
JointTypeFixed), nullBody,
"right_sole_frame");
1747 MatrixNd G(MatrixNd::Zero(6, model->dof_count));
1759 unsigned int body_id = (rand() % (model->mBodies.size() - 2)) + 1;
1760 Vector3d point_local(1.1, 2.2, 3.3);
1762 MatrixNd G(6, model->qdot_size), GDot(6, model->qdot_size);
1772 body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
1778 a_exp = G * qddot + GDot * qdot;
1784 body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
1785 unsigned int fb_id = model_3dof->addBody(body_id,
Xtrans(
Vector3d(-0.01, 0.02, 0.01)) *
Xrotx(0.5), fj, fb);
1791 a_exp = G * qddot + GDot * qdot;
1800 unsigned int body_id = (rand() % (model->mBodies.size() - 2)) + 1;
1804 MatrixNd G(6, model->qdot_size), GDot(6, model->qdot_size);
1815 body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
1816 body_frame = model_3dof->bodyFrames[body_id];
1822 a_exp = G * qddot + GDot * qdot;
1828 body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
1829 unsigned int fb_id = model_3dof->addBody(body_id,
Xtrans(
Vector3d(-0.01, 0.02, 0.01)) *
Xrotx(0.5), fj, fb,
"fixed_body");
1835 body_frame = model_3dof->referenceFrameMap[
"fixed_body"];
1839 a_exp = G * qddot + GDot * qdot;
1848 unsigned int body_id = (rand() % (model->mBodies.size() - 2)) + 1;
1849 unsigned int relative_body_id = (rand() % (model->mBodies.size() - 2)) + 1;
1850 unsigned int expressed_in_body_id = (rand() % (model->mBodies.size() - 2)) + 1;
1852 MatrixNd G(6, model->qdot_size), GDot(6, model->qdot_size);
1877 body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
1878 relative_body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
1879 expressed_in_body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
1881 body_frame = model_3dof->bodyFrames[body_id];
1882 relative_frame = model_3dof->bodyFrames[relative_body_id];
1883 expressedInFrame = model_3dof->bodyFrames[expressed_in_body_id];
1885 a =
calcPointAcceleration6D(*model_3dof, q, qdot, qddot, body_frame, relative_frame, expressedInFrame,
false);
1886 a_body =
calcPointAcceleration6D(*model_3dof, q, qdot, qddot, body_frame, model_3dof->worldFrame, model_3dof->worldFrame,
false);
1887 a_rel =
calcPointAcceleration6D(*model_3dof, q, qdot, qddot, relative_frame, model_3dof->worldFrame, model_3dof->worldFrame,
false);
1894 G = MatrixNd::Zero(6, model_3dof->qdot_size);
1895 GDot = MatrixNd::Zero(6, model_3dof->qdot_size);
1901 a_calc = G * qddot + GDot * qdot;
1908 body_id = (rand() % (model->mBodies.size() - 2)) + 1;
1909 relative_body_id = (rand() % (model->mBodies.size() - 2)) + 1;
1910 expressed_in_body_id = (rand() % (model->mBodies.size() - 2)) + 1;
1912 unsigned int fb_id = model->addBody(body_id,
Xtrans(
Vector3d(-0.01, 0.02, 0.01)) *
Xrotx(0.5), fj, fb,
"fixed_body");
1919 body_frame = model->referenceFrameMap[
"fixed_body"];
1920 relative_frame = model->bodyFrames[relative_body_id];
1921 expressedInFrame = model->bodyFrames[expressed_in_body_id];
1929 a_calc = G * qddot + GDot * qdot;
1939 unsigned int body_id = (rand() % (model->mBodies.size() - 2)) + 1;
1940 unsigned int relative_body_id = (rand() % (model->mBodies.size() - 2)) + 1;
1941 unsigned int expressed_in_body_id = (rand() % (model->mBodies.size() - 2)) + 1;
1943 MatrixNd G(6, model->qdot_size), GDot(6, model->qdot_size), G2(6, model->qdot_size), GDot2(6, model->qdot_size);
1960 body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
1961 relative_body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
1962 expressed_in_body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
1964 body_frame = model_3dof->bodyFrames[body_id];
1965 relative_frame = model_3dof->bodyFrames[relative_body_id];
1966 expressedInFrame = model_3dof->bodyFrames[expressed_in_body_id];
1968 G = MatrixNd::Zero(6, model_3dof->qdot_size);
1969 GDot = MatrixNd::Zero(6, model_3dof->qdot_size);
1970 G2 = MatrixNd::Zero(6, model_3dof->qdot_size);
1971 GDot2 = MatrixNd::Zero(6, model_3dof->qdot_size);
1982 body_id = (rand() % (model->mBodies.size() - 2)) + 1;
1983 relative_body_id = (rand() % (model->mBodies.size() - 2)) + 1;
1984 expressed_in_body_id = (rand() % (model->mBodies.size() - 2)) + 1;
1986 unsigned int fb_id = model->addBody(body_id,
Xtrans(
Vector3d(-0.01, 0.02, 0.01)) *
Xrotx(0.5), fj, fb,
"fixed_body");
1994 body_frame = model->referenceFrameMap[
"fixed_body"];
1995 relative_frame = model->bodyFrames[relative_body_id];
1996 expressedInFrame = model->bodyFrames[expressed_in_body_id];
2010 unsigned int body_id = (rand() % (model->mBodies.size() - 2)) + 1;
2012 MatrixNd G(6, model->qdot_size), GDot(6, model->qdot_size);
2018 body_id = (rand() % (model->mBodies.size() - 2)) + 1;
2020 unsigned int fb_id_1 = model->addBody(body_id,
Xtrans(
Vector3d(-0.01, 0.02, 0.01)) *
Xrotx(0.5), fj, fb,
"fixed_body_1");
2021 body_id = (rand() % (model->mBodies.size() - 2)) + 1;
2022 unsigned int fb_id_2 = model->addBody(body_id,
Xtrans(
Vector3d(-0.01, 0.02, 0.01)) *
Xrotx(0.5), fj, fb,
"fixed_body_2");
2023 body_id = (rand() % (model->mBodies.size() - 2)) + 1;
2024 unsigned int fb_id_3 = model->addBody(body_id,
Xtrans(
Vector3d(-0.01, 0.02, 0.01)) *
Xrotx(0.5), fj, fb,
"fixed_body_3");
2047 a_fb_1_frames -= a_fb_2_frames;
2050 SpatialTransform X = model->worldFrame->getTransformToDesiredFrame(fb_3_frame);
2064 unsigned int body_id = (rand() % (model->mBodies.size() - 2)) + 1;
2068 body_id = (rand() % (model->mBodies.size() - 2)) + 1;
2076 body_id = (rand() % (model->mBodies.size() - 2)) + 1;
2079 a_beep =
calcPointAcceleration6D(*model, q, qdot, qddot, body_frame, relative_frame, expressedInFrame,
false);
2080 SpatialTransform X_rot = model->worldFrame->getTransformToDesiredFrame(expressedInFrame);
2096 unsigned int body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
2100 body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
2107 body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
2110 a_beep =
calcPointAcceleration6D(*model_3dof, q, qdot, qddot, body_frame, relative_frame, expressedInFrame,
false);
2111 SpatialTransform X_rot = model_3dof->worldFrame->getTransformToDesiredFrame(expressedInFrame);
2126 unsigned int body_id = (rand() % (model->mBodies.size() - 2)) + 1;
2127 Vector3d point_local(1.1, 2.2, 3.3);
2129 MatrixNd G(3, model->qdot_size), GDot(3, model->qdot_size);
2135 Vector3d a_exp = G * qddot + GDot * qdot;
2138 body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
2144 a_exp = G * qddot + GDot * qdot;
2149 body_id = (rand() % (model_3dof->mBodies.size() - 2)) + 1;
2150 unsigned int fb_id = model_3dof->addBody(body_id,
Xtrans(
Vector3d(-0.01, 0.02, 0.01)) *
Xrotx(0.5), fj, fb);
2156 a_exp = G * qddot + GDot * qdot;
2163 unsigned int foot_r_id = model->GetBodyId(
"foot_r");
2164 Vector3d point_local(1.1, 2.2, 3.3);
2177 FramePoint p(model->bodyFrames[foot_r_id], point_local);
2178 p.changeFrame(ReferenceFrame::getWorldFrame());
2181 SpatialVector rdot(0., 0., 0., v_foot_0[0], v_foot_0[1], v_foot_0[2]);
2184 SpatialVector a_foot_0_ref = X_foot.apply(model->bodyFrames[foot_r_id]->getTransformToRoot().apply(model->a[foot_r_id]) -
2185 crossm(rdot, model->bodyFrames[foot_r_id]->getTransformToRoot().apply(model->v[foot_r_id])));
2194 unsigned int foot_r_id = model->GetBodyId(
"foot_r");
2198 Vector3d point_local(1.1, 2.2, 3.3);
2211 FramePoint p(model->fixedBodyFrames[fb_id - model->fixed_body_discriminator], point_local);
2212 p.changeFrame(ReferenceFrame::getWorldFrame());
2215 SpatialVector rdot(0., 0., 0., v_foot_0[0], v_foot_0[1], v_foot_0[2]);
2219 X_foot.apply(model->fixedBodyFrames[fb_id - model->fixed_body_discriminator]->getTransformToRoot().apply(model->a[foot_r_id]) -
2220 crossm(rdot, model->fixedBodyFrames[fb_id - model->fixed_body_discriminator]->getTransformToRoot().apply(model->v[foot_r_id])));
2248 EXPECT_STREQ(m.
getBaseFrame()->getName().c_str(),
"world");
2252 EXPECT_STREQ(m_frame.
getBaseFrame()->getName().c_str(),
"world");
2262 EXPECT_STREQ(m.
getBaseFrame()->getName().c_str(),
"world");
2266 EXPECT_STREQ(m_frame.
getBaseFrame()->getName().c_str(),
"world");
2276 EXPECT_STREQ(m.
getBaseFrame()->getName().c_str(),
"b2");
2280 EXPECT_STREQ(m_frame.
getBaseFrame()->getName().c_str(),
"b2");
2294 for (
unsigned int i = 0; i < QDot.size(); i++)
2296 Q[i] = 0.4 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
2297 QDot[i] = 0.5 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
2335 EXPECT_STREQ(m.
getBaseFrame()->getName().c_str(),
"fb2");
2338 EXPECT_STREQ(m_frame.
getBaseFrame()->getName().c_str(),
"fb2");
2346 EXPECT_STREQ(m.
getBaseFrame()->getName().c_str(),
"fb1");
2371 unsigned int parent_id = 0;
2386 for (
int i = 0; i < model.
qdot_size; i++)
2388 Q[i] = 0.4 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
2389 QDot[i] = 0.5 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
2390 QDDot[i] = 0.5 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
2428 unsigned int parent_id = 0;
2443 for (
int i = 0; i < model.
qdot_size; i++)
2445 Q[i] = 0.4 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
2446 QDot[i] = 0.5 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
2447 QDDot[i] = 0.5 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
2489 Math::MatrixNd GDot(6, model_emulated->qdot_size), G(6, model_emulated->qdot_size);
2493 int id = rand() %
static_cast<int>(model->mBodies.size() - 1);
2501 id = rand() %
static_cast<int>(model_3dof->mBodies.size() - 1);
2511 a_exp = GDot * qdot + G * qddot;
2518 ::testing::InitGoogleTest(&argc, argv);
2519 return RUN_ALL_TESTS();
Joint joint_rot_z(SpatialVector(0., 0., 1., 0., 0., 0.))
File containing the FramePoint<T> object definition.
void calcPointJacobian(Model &model, const Math::VectorNd &Q, unsigned int body_id, const Math::Vector3d &point_position, Math::MatrixNd &G, bool update_kinematics=true)
Computes the 3D point jacobian for a point on a body.
ReferenceFramePtr getReferenceFrame() const
Get a pointer to the reference frame this FrameObject is expressed in.
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.
void calcRelativeBodySpatialJacobianAndJacobianDot(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, Math::MatrixNd &G, Math::MatrixNd &GDot, ReferenceFramePtr baseFrame, ReferenceFramePtr relativeFrame, ReferenceFramePtr expressedInFrame=nullptr, bool update_kinematics=true)
Computes both the body spatial jacobian and its time derivative. This function will be a bit more eff...
std::shared_ptr< Model > ModelPtr
FrameVector linear() const
Get copy of linear component.
std::vector< FixedBody > mFixedBodies
All bodies that are attached to a body via a fixed joint.
Math::SpatialMotion calcSpatialVelocity(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, ReferenceFramePtr body_frame, ReferenceFramePtr relative_body_frame, ReferenceFramePtr expressedInFrame=nullptr, const bool update_kinematics=true)
Compute the spatial velocity of any frame with respect to any other frame, expressed in an arbirtary ...
void setAngularPart(const Vector3d &v)
Set the angular vector.
void calcRelativeBodySpatialJacobian(Model &model, const Math::VectorNd &Q, Math::MatrixNd &G, ReferenceFramePtr baseFrame, ReferenceFramePtr relativeFrame, ReferenceFramePtr expressedInFrame=nullptr, bool update_kinematics=true)
Computes the jacobian of a frame with being the "base" frame, being the "relative" frame...
RdlKinematicsSingleChainFixture6DoF()
SpatialTransform Xtrans(const Vector3d &r)
Get pure translation transform.
Fixed joint which causes the inertial properties to be merged with.
void calcPointJacobianDot(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, unsigned int body_id, const Math::Vector3d &point_position, Math::MatrixNd &G, bool update_kinematics=true)
Computes the time derivative of the linear components the a point jacobian on a body.
bool checkModelZeroVectorsAndMatrices(RobotDynamics::Model &model)
FrameVector angular() const
Get copy of angular component.
void calcRelativePointJacobian6D(Model &model, const Math::VectorNd &Q, Math::MatrixNd &G, ReferenceFramePtr baseFrame, ReferenceFramePtr relativeFrame, ReferenceFramePtr expressedInFrame=RobotDynamics::ReferenceFrame::getWorldFrame(), bool update_kinematics=true)
Compute the 6D jacobian of the origin of a reference frame relative to the origin of another referenc...
Math::FrameVector calcPointAcceleration(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &QDDot, unsigned int body_id, const Math::Vector3d &point_position, bool update_kinematics=true)
Computes the linear acceleration of a point on a body.
void calcRelativePointJacobianAndJacobianDot6D(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, Math::MatrixNd &G, Math::MatrixNd &GDot, ReferenceFramePtr baseFrame, ReferenceFramePtr relativeFrame, ReferenceFramePtr expressedInFrame=RobotDynamics::ReferenceFrame::getWorldFrame(), bool update_kinematics=true)
Compute the point Jacobian of the origin of baseFrame, relative to the origin of relativeFrame, expressed in expressedInFrame. Also compute that point Jacobians time derivative.
Math::MotionVector gravity
the cartesian vector of the gravity
Vector3d transform_copy(const RobotDynamics::Math::SpatialTransform &X) const
int main(int argc, char **argv)
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.
Math::SpatialAcceleration calcSpatialAcceleration(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &QDDot, const unsigned int body_id, const unsigned int relative_body_id, ReferenceFramePtr expressedInFrame=nullptr, const bool update_kinematics=true)
Compute the spatial acceleration of any body with respect to any other body and express the result in...
std::vector< ReferenceFramePtr > bodyFrames
ReferenceFramePtr worldFrame
RdlKinematicsSingleChainFixture()
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.
void calcPointJacobian6D(Model &model, const Math::VectorNd &Q, Math::MatrixNd &G, ReferenceFramePtr frame, bool update_kinematics=true)
Compute the 6D point jacobian of the origin of a reference frame If a position of a point is computed...
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
std::shared_ptr< ReferenceFrame > ReferenceFramePtr
Math::FrameVector calcPointVelocity(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, unsigned int body_id, const Math::Vector3d &point_position, bool update_kinematics=true)
Computes the velocity of a point on a body.
RobotDynamics::Math::VectorNd tau
void calcRelativePointJacobianDot6D(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, Math::MatrixNd &G, ReferenceFramePtr baseFrame, ReferenceFramePtr relativeFrame, ReferenceFramePtr expressedInFrame=RobotDynamics::ReferenceFrame::getWorldFrame(), bool update_kinematics=true)
Compute the time derivative of the 6D jacobian of the origin of a reference frame relative to the ori...
virtual void changeFrame(ReferenceFramePtr desiredFrame)
Change the ReferenceFrame this FrameObject is expressed in.
void calcPointJacobianDot6D(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, RobotDynamics::ReferenceFramePtr frame, Math::MatrixNd &G, bool update_kinematics=true)
Computes the time derivative of a point jacobian of a point on a body.
A FrameVector is a 3D vector with a ReferenceFrame, and all operations between FrameVectors and other...
A SpatialMotion vector is a MotionVector with a RobotDynamics::ReferenceFrame it is expressed in...
void changeFrame(ReferenceFramePtr referenceFrame)
Change the frame of the two 3d vectors. Equivalent to the following math expression ...
Describes a joint relative to the predecessor body.
void calcBodySpatialJacobianDot(Model &model, const Math::VectorNd &Q, const Math::VectorNd QDot, unsigned int body_id, Math::MatrixNd &G, const bool update_kinematics=true)
Computes the time derivative of the spatial jacobian for a body. The result will be returned via the ...
void updateKinematicsParallel(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &QDDot)
Updates and computes velocities and accelerations of the bodies.
ReferenceFramePtr getBaseFrame() const
Get a SpatialMotions SpatialMotion::baseFrame.
SpatialTransform Xrotx(const double &xrot)
Get transform with zero translation and pure rotation about x axis.
static bool checkMatrixNdEpsilonClose(const RobotDynamics::Math::MatrixNd &t1, const RobotDynamics::Math::MatrixNd &t2, const double epsilon)
void calcBodySpatialJacobian(Model &model, const Math::VectorNd &Q, unsigned int body_id, Math::MatrixNd &G, bool update_kinematics=true)
Computes the spatial jacobian for a body. The result will be returned via the G argument and represen...
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::SpatialAccelerationV a
The spatial velocity of the bodies.
EIGEN_STRONG_INLINE Vector3d getAngularPart() const
bool inverseKinematics(Model &model, const Math::VectorNd &Qinit, const std::vector< unsigned int > &body_id, const std::vector< Math::Vector3d > &body_point, const std::vector< Math::Vector3d > &target_pos, Math::VectorNd &Qres, double step_tol=1.0e-12, double lambda=0.01, unsigned int max_iter=50)
Computes the inverse kinematics iteratively using a damped Levenberg-Marquardt method (also known as ...
Contains all information about the rigid body model.
void calcRelativeBodySpatialJacobianDot(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, Math::MatrixNd &G, ReferenceFramePtr baseFrame, ReferenceFramePtr relativeFrame, ReferenceFramePtr expressedInFrame=nullptr, bool update_kinematics=true)
Computes the rate of change of the jacobian, , with being the "base" frame, being the relative" fra...
void setLinearPart(const Vector3d &v)
Set the linear vector.
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.
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)
TEST_F(RdlKinematicsFixture, parallelKinematics)
unsigned int fixed_body_discriminator
Value that is used to discriminate between fixed and movable bodies.
SpatialAcceleration. For clarity, the ReferenceFrames are stated as follows. A spatial acceleration i...
A FrameVector is a pair of 3D vector with a ReferenceFrame.
static bool checkVector3dEpsilonClose(const RobotDynamics::Math::Vector3d &v1, const RobotDynamics::Math::Vector3d &v2, const double epsilon)
Math::FrameVectorPair calcPointAcceleration6D(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &QDDot, unsigned int body_id, const Math::Vector3d &point_position, bool update_kinematics=true)
Computes linear and angular acceleration of a point on a body.
Math::FrameVectorPair calcPointVelocity6D(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, unsigned int body_id, const Math::Vector3d &point_position, bool update_kinematics=true)
Computes angular and linear velocity of a point that is fixed on a body.
EIGEN_STRONG_INLINE Vector3d getLinearPart() const
std::vector< ReferenceFramePtr > fixedBodyFrames
SpatialMatrix crossm(const SpatialVector &v)
Get the spatial motion cross matrix.
MotionVector transform_copy(const SpatialTransform &X) const
Copies, transforms, and returns a MotionVector. Performs .
void updateKinematicsCustomParallel(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 and spaw...
unsigned int dof_count
number of degrees of freedoms of the model
static bool checkFrameVectorPairEpsilonClose(const RobotDynamics::Math::FrameVectorPair &v1, const RobotDynamics::Math::FrameVectorPair &v2, const double epsilon)
void setReferenceFrame(ReferenceFramePtr referenceFrame)
Set the reference frame.
void setBodyFrame(ReferenceFramePtr referenceFrame)
Sets the body frame of a spatial motion.
Namespace for all structures of the RobotDynamics library.
static bool checkMatrix3dEpsilonClose(const RobotDynamics::Math::Matrix3d &t1, const RobotDynamics::Math::Matrix3d &t2, const double epsilon)
unsigned int qdot_size
The size of the.