6 #include <gtest/gtest.h> 32 for (
int i = 0; i < 6; i++)
34 for (
int j = 0; j < 6; j++)
36 if (fabs(t1(i, j) - t2(i, j)) > epsilon)
48 for (
int i = 0; i < 6; i++)
50 if (fabs(v1(i) - v2(i)) > epsilon)
61 std::ifstream model_file(filename);
64 std::cerr <<
"Error opening file '" << filename <<
"'." << std::endl;
69 std::string model_xml_string;
70 model_file.seekg(0, std::ios::end);
71 model_xml_string.reserve(model_file.tellg());
72 model_file.seekg(0, std::ios::beg);
73 model_xml_string.assign((std::istreambuf_iterator<char>(model_file)), std::istreambuf_iterator<char>());
76 return model_xml_string;
83 std::string path_to_urdf =
ros::package::getPath(
"rdl_urdfreader") +
"/tests/urdf/simple_two_chain_bot.urdf";
86 std::vector<unsigned int> q_indices;
87 std::vector<std::string> joint_names, body_names;
91 EXPECT_EQ(q_indices.size(), 3);
92 EXPECT_STREQ(joint_names[0].c_str(),
"test_robot_shoulder_lift_joint");
93 EXPECT_STREQ(body_names[0].c_str(),
"test_robot_upper_arm_link");
94 EXPECT_EQ(q_indices[std::distance(joint_names.begin(), std::find(joint_names.begin(), joint_names.end(),
"test_robot_shoulder_lift_joint"))], 0);
96 EXPECT_STREQ(joint_names[1].c_str(),
"test_robot_elbow_joint");
97 EXPECT_STREQ(body_names[1].c_str(),
"test_robot_forearm_link");
98 EXPECT_EQ(q_indices[std::distance(joint_names.begin(), std::find(joint_names.begin(), joint_names.end(),
"test_robot_elbow_joint"))], 1);
100 EXPECT_STREQ(joint_names[2].c_str(),
"test_robot_shoulder_pan_joint");
101 EXPECT_STREQ(body_names[2].c_str(),
"test_robot_shoulder_link");
102 EXPECT_EQ(q_indices[std::distance(joint_names.begin(), std::find(joint_names.begin(), joint_names.end(),
"test_robot_shoulder_pan_joint"))], 2);
107 std::string file_path =
ros::package::getPath(
"rdl_urdfreader") +
"/tests/urdf/first_joint_fixed_non_trivial_xform.urdf";
116 ASSERT_EQ(model->q_size, 1);
117 ASSERT_EQ(model->qdot_size, 1);
122 EXPECT_TRUE(model->referenceFrameMap[
"j1_link"]->getInverseTransformToRoot().r.isApprox(
RobotDynamics::Math::Vector3d(0.0, 0.16, 0.8377), 1e-4));
132 EXPECT_EQ(model->mBodies[0].mMass, 4.);
135 EXPECT_EQ(model->Ib_c[0].Ixx, 0.0061063308908);
136 EXPECT_EQ(model->Ib_c[0].Iyx, 0.0);
137 EXPECT_EQ(model->Ib_c[0].Izx, 0.0);
138 EXPECT_EQ(model->Ib_c[0].Iyy, 0.0061063308908);
139 EXPECT_EQ(model->Ib_c[0].Izy, 0.0);
140 EXPECT_EQ(model->Ib_c[0].Izz, 0.01125);
142 unsigned int id = model->GetBodyId(
"test_robot_shoulder_link");
143 EXPECT_EQ(model->mBodies[
id].mMass, 7.778);
146 EXPECT_EQ(model->Ib_c[
id].Ixx, 0.0314743125769);
147 EXPECT_EQ(model->Ib_c[
id].Iyx, 0.);
148 EXPECT_EQ(model->Ib_c[
id].Izx, 0.);
149 EXPECT_EQ(model->Ib_c[
id].Iyy, 0.0314743125769);
150 EXPECT_EQ(model->Ib_c[
id].Izy, 0.);
151 EXPECT_EQ(model->Ib_c[
id].Izz, 0.021875625);
153 id = model->GetParentBodyId(model->GetBodyId(
"gripper_right_finger_link"));
154 EXPECT_EQ(model->GetBodyId(
"gripper_right_knuckle_link"), id);
157 EXPECT_EQ(model->GetBodyId(
"test_robot_shoulder_link"), model->lambda[model->GetBodyId(
"test_robot_upper_arm_link")]);
163 std::string file_path_2 =
ros::package::getPath(
"rdl_urdfreader") +
"/tests/urdf/test_robot_arm_neg_jnt_axes.urdf";
177 for (
int i = 0; i < q.size(); i++)
179 q[i] = 0.4 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
180 qd[i] = 0.5 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
181 tau[i] = 0.5 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
182 qdd[i] = 0.5 * M_PI *
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
193 for (
unsigned int i = 0; i < model->mBodies.size(); i++)
202 EXPECT_TRUE(qdd.isApprox(-qdd_neg, 1e-14));
207 EXPECT_TRUE(tau.isApprox(-tau_neg, 1e-14));
213 std::map<std::string, std::string> jointBodyMap;
217 EXPECT_STREQ(jointBodyMap[
"test_robot_elbow_joint"].c_str(),
"test_robot_forearm_link");
218 EXPECT_TRUE(jointBodyMap.find(
"test_robot_ee_fixed_joint") == jointBodyMap.end());
219 EXPECT_STREQ(jointBodyMap[
"test_robot_shoulder_pan_joint"].c_str(),
"test_robot_shoulder_link");
222 std::vector<unsigned int> q_indices;
224 EXPECT_EQ(q_indices.size(), 12);
231 std::string path_to_urdf =
ros::package::getPath(
"rdl_urdfreader") +
"/tests/urdf/floating_base_robot.urdf";
234 EXPECT_NEAR(model->mBodies[2].mMass, 4., 1e-14);
237 EXPECT_NEAR(model->Ib_c[2].Ixx, 0.1, 1e-14);
238 EXPECT_NEAR(model->Ib_c[2].Iyx, 0., 1e-14);
239 EXPECT_NEAR(model->Ib_c[2].Izx, 0., 1e-14);
240 EXPECT_NEAR(model->Ib_c[2].Iyy, 0.2, 1e-14);
241 EXPECT_NEAR(model->Ib_c[2].Izy, 0., 1e-14);
242 EXPECT_NEAR(model->Ib_c[2].Izz, 0.3, 1e-14);
251 std::string path_to_urdf =
ros::package::getPath(
"rdl_urdfreader") +
"/tests/urdf/floating_base_robot.urdf";
254 EXPECT_NEAR(model->mBodies[2].mMass, 4., 1e-14);
257 EXPECT_NEAR(model->Ib_c[2].Ixx, 0.1, 1e-14);
258 EXPECT_NEAR(model->Ib_c[2].Iyx, 0., 1e-14);
259 EXPECT_NEAR(model->Ib_c[2].Izx, 0., 1e-14);
260 EXPECT_NEAR(model->Ib_c[2].Iyy, 0.2, 1e-14);
261 EXPECT_NEAR(model->Ib_c[2].Izy, 0., 1e-14);
262 EXPECT_NEAR(model->Ib_c[2].Izz, 0.3, 1e-14);
271 std::string path_to_urdf =
ros::package::getPath(
"rdl_urdfreader") +
"/tests/urdf/floating_joint_robot.urdf";
278 std::vector<unsigned int> q_indices;
281 EXPECT_EQ(q_indices.size(), 1);
282 EXPECT_EQ(q_indices[0], 6);
288 std::string path_to_urdf =
ros::package::getPath(
"rdl_urdfreader") +
"/tests/urdf/single_body_floating_base.urdf";
292 std::vector<unsigned int> q_indices;
295 EXPECT_EQ(q_indices.size(), 0);
301 std::string path_to_urdf =
ros::package::getPath(
"rdl_urdfreader") +
"/tests/urdf/rotated_inertial.urdf";
308 EXPECT_TRUE(I1.isApprox(model->mBodies[1].mInertia, 1.e-10));
314 EXPECT_TRUE(I2.isApprox(model->mBodies[2].mInertia, 1.e-10));
320 EXPECT_TRUE(I3.isApprox(model->mBodies[3].mInertia, 1.e-10));
326 std::string path_to_urdf =
ros::package::getPath(
"rdl_urdfreader") +
"/tests/urdf/floating_base_rotated_inertial.urdf";
333 EXPECT_TRUE(I1.isApprox(model->mBodies[2].mInertia, 1.e-10));
339 EXPECT_TRUE(I2.isApprox(model->mBodies[3].mInertia, 1.e-10));
345 EXPECT_TRUE(I3.isApprox(model->mBodies[4].mInertia, 1.e-10));
348 int main(
int argc,
char** argv)
350 ::testing::InitGoogleTest(&argc, argv);
351 ::testing::FLAGS_gtest_death_test_style =
"threadsafe";
352 return RUN_ALL_TESTS();
bool checkSpatialMatrixEpsilonClose(const RobotDynamics::Math::SpatialMatrix &t1, const RobotDynamics::Math::SpatialMatrix &t2, const double epsilon)
Matrix3d Matrix3dIdentity(1., 0., 0., 0., 1., 0., 0., 0., 1)
std::shared_ptr< Model > ModelPtr
bool parseJointBodyNameMapFromFile(const char *filename, std::map< std::string, std::string > &jointBodyMap)
This will build a map of joint name to body name.
int main(int argc, char **argv)
bool parseJointAndBodyNamesFromString(const std::string &model_xml_string, std::vector< std::string > &joint_names, std::vector< std::string > &body_names)
This will build vectors of joint name and body name pairs.
TEST_F(UrdfReaderTests, q_index_two_chains)
std::shared_ptr< ReferenceFrame > ReferenceFramePtr
void updateKinematics(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &QDDot)
std::string getFileContents(const std::string &filename)
ROSLIB_DECL std::string getPath(const std::string &package_name)
bool checkSpatialVectorsEpsilonClose(const RobotDynamics::Math::SpatialVector &v1, const RobotDynamics::Math::SpatialVector &v2, const double epsilon)
bool urdfReadFromFile(const char *filename, ModelPtr model, bool floating_base, bool verbose=false)
Read urdf from file path.
void inverseDynamics(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &QDDot, Math::VectorNd &Tau, Math::SpatialForceV *f_ext=nullptr, bool update_kinematics=true)
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)
bool parseJointAndQIndex(const RobotDynamics::Model &model, const std::vector< std::string > &body_names, std::vector< unsigned int > &q_indices)
This will build a vector of joint indices in the same order as the list of joints.