51 builder.
addChain(
"a->b",
"continuous");
52 builder.
addChain(
"b->c",
"prismatic");
54 robot_model_ = builder.
build();
64 static std::size_t generateTestTraj(std::vector<std::shared_ptr<RobotState>>& traj,
65 const RobotModelConstPtr& robot_model_);
69 const RobotModelConstPtr& robot_model_)
78 for (std::size_t traj_ix = 0; traj_ix < 3; ++traj_ix)
80 traj.push_back(std::make_shared<RobotState>(*
robot_state));
91 traj.push_back(std::make_shared<RobotState>(*
robot_state));
96 traj.push_back(std::make_shared<RobotState>(*
robot_state));
101 traj.push_back(std::make_shared<RobotState>(*
robot_state));
104 traj.push_back(std::make_shared<RobotState>(*
robot_state));
111 std::vector<std::shared_ptr<RobotState>> traj;
114 const std::size_t expected_full_traj_len = 7;
117 std::size_t full_traj_len = generateTestTraj(traj, robot_model_);
120 EXPECT_EQ(full_traj_len, expected_full_traj_len);
125 const JointModelGroup* joint_model_group = robot_model_->getJointModelGroup(
"group");
126 std::vector<std::shared_ptr<RobotState>> traj;
129 const std::size_t expected_revolute_jump_traj_len = 4;
130 const std::size_t expected_prismatic_jump_traj_len = 5;
133 std::size_t full_traj_len = generateTestTraj(traj, robot_model_);
134 const double expected_revolute_jump_fraction = (double)expected_revolute_jump_traj_len / (
double)full_traj_len;
135 const double expected_prismatic_jump_fraction = (double)expected_prismatic_jump_traj_len / (
double)full_traj_len;
142 EXPECT_EQ(expected_revolute_jump_traj_len, traj.size());
143 EXPECT_NEAR(expected_revolute_jump_fraction, fraction, 0.01);
146 generateTestTraj(traj, robot_model_);
148 EXPECT_EQ(expected_revolute_jump_traj_len, traj.size());
149 EXPECT_NEAR(expected_revolute_jump_fraction, fraction, 0.01);
152 generateTestTraj(traj, robot_model_);
154 EXPECT_EQ(expected_revolute_jump_traj_len, traj.size());
155 EXPECT_NEAR(expected_revolute_jump_fraction, fraction, 0.01);
158 generateTestTraj(traj, robot_model_);
160 EXPECT_EQ(expected_prismatic_jump_traj_len, traj.size());
161 EXPECT_NEAR(expected_prismatic_jump_fraction, fraction, 0.01);
164 generateTestTraj(traj, robot_model_);
172 const JointModelGroup* joint_model_group = robot_model_->getJointModelGroup(
"group");
173 std::vector<std::shared_ptr<RobotState>> traj;
176 const std::size_t expected_relative_jump_traj_len = 4;
179 std::size_t full_traj_len = generateTestTraj(traj, robot_model_);
180 const double expected_relative_jump_fraction = (double)expected_relative_jump_traj_len / (
double)full_traj_len;
187 EXPECT_EQ(expected_relative_jump_traj_len, traj.size());
188 EXPECT_NEAR(expected_relative_jump_fraction, fraction, 0.01);
191 generateTestTraj(traj, robot_model_);
193 EXPECT_EQ(expected_relative_jump_traj_len, traj.size());
194 EXPECT_NEAR(expected_relative_jump_fraction, fraction, 0.01);
197 generateTestTraj(traj, robot_model_);
204 #ifndef INSTANTIATE_TEST_SUITE_P
208 #define _STATIC static
217 jmg_ = robot_model_->getJointModelGroup(
"panda_arm");
218 link_ = robot_model_->getLinkModel(
"panda_link8");
225 robot_model_.reset();
233 start_state_ = std::make_shared<RobotState>(robot_model_);
234 ASSERT_TRUE(start_state_->setToDefaultValues(jmg_,
"ready"));
235 start_pose_ = start_state_->getGlobalLinkTransform(link_);
254 bool global,
const Eigen::Isometry3d& offset = Eigen::Isometry3d::Identity())
270 std::vector<std::shared_ptr<RobotState>>
result_;
281 ASSERT_DOUBLE_EQ(computeCartesianPath(result_, translation,
true), 0.2);
283 EXPECT_EIGEN_EQ(result_.front()->getGlobalLinkTransform(link_), start_pose_);
285 EXPECT_EIGEN_NEAR(result_.back()->getGlobalLinkTransform(link_).linear(), start_pose_.linear(), prec_);
287 start_pose_.translation() + translation, prec_);
292 ASSERT_DOUBLE_EQ(computeCartesianPath(result_, translation,
false), 0.2);
294 EXPECT_EIGEN_EQ(result_.front()->getGlobalLinkTransform(link_), start_pose_);
296 EXPECT_EIGEN_NEAR(result_.back()->getGlobalLinkTransform(link_).linear(), start_pose_.linear(), prec_);
297 EXPECT_EIGEN_NEAR(result_.back()->getGlobalLinkTransform(link_).translation(), start_pose_ * translation, prec_);
302 Eigen::Isometry3d goal = start_pose_;
303 goal.translation().x() += 0.2;
305 ASSERT_DOUBLE_EQ(computeCartesianPath(result_, goal,
true), 1.0);
307 EXPECT_EIGEN_EQ(result_.front()->getGlobalLinkTransform(link_), start_pose_);
309 EXPECT_EIGEN_NEAR(result_.back()->getGlobalLinkTransform(link_).linear(), start_pose_.linear(), prec_);
310 EXPECT_EIGEN_NEAR(result_.back()->getGlobalLinkTransform(link_).translation(), goal.translation(), prec_);
314 Eigen::Isometry3d offset(Eigen::Translation3d(0.2, 0, 0));
315 ASSERT_DOUBLE_EQ(computeCartesianPath(result_, offset,
false), 1.0);
317 EXPECT_EIGEN_EQ(result_.front()->getGlobalLinkTransform(link_), start_pose_);
319 EXPECT_EIGEN_NEAR(result_.back()->getGlobalLinkTransform(link_).linear(), start_pose_.linear(), prec_);
320 EXPECT_EIGEN_NEAR(result_.back()->getGlobalLinkTransform(link_).translation(), start_pose_ * offset.translation(),
327 Eigen::Isometry3d rot(Eigen::AngleAxisd(
M_PI / 4, Eigen::Vector3d::UnitX()));
328 Eigen::Isometry3d goal = start_pose_ * rot;
330 ASSERT_DOUBLE_EQ(computeCartesianPath(result_, rot,
false), 1.0);
332 EXPECT_EIGEN_EQ(result_.front()->getGlobalLinkTransform(link_), start_pose_);
334 EXPECT_EIGEN_NEAR(result_.back()->getGlobalLinkTransform(link_).translation(), start_pose_.translation(), prec_);
340 Eigen::Isometry3d rot(Eigen::AngleAxisd(
M_PI / 4, Eigen::Vector3d::UnitX()));
341 Eigen::Isometry3d goal = start_pose_ * rot;
343 ASSERT_DOUBLE_EQ(computeCartesianPath(result_, goal,
true), 1.0);
345 EXPECT_EIGEN_NEAR(result_.front()->getGlobalLinkTransform(link_), start_pose_, prec_);
347 EXPECT_EIGEN_NEAR(result_.back()->getGlobalLinkTransform(link_).translation(), start_pose_.translation(), prec_);
353 Eigen::Isometry3d offset = Eigen::Translation3d(0, 0, 0.2) * Eigen::AngleAxisd(-
M_PI / 4, Eigen::Vector3d::UnitZ());
355 Eigen::Isometry3d rot(Eigen::AngleAxisd(
M_PI / 4, Eigen::Vector3d::UnitX()));
356 Eigen::Isometry3d goal = start_pose_ * offset * rot;
358 ASSERT_DOUBLE_EQ(computeCartesianPath(result_, goal,
true, offset), 1.0);
360 EXPECT_EIGEN_NEAR(result_.front()->getGlobalLinkTransform(link_), start_pose_, prec_);
363 for (
const auto& waypoint : result_)
364 EXPECT_EIGEN_NEAR((waypoint->getGlobalLinkTransform(link_) * offset).translation(),
365 (start_pose_ * offset).translation(), prec_);
367 EXPECT_EIGEN_NEAR(result_.back()->getGlobalLinkTransform(link_) * offset, goal, prec_);
370 int main(
int argc,
char** argv)
372 testing::InitGoogleTest(&argc, argv);
373 ros::init(argc, argv,
"test_cartesian_interpolator");
374 return RUN_ALL_TESTS();