37 #include <gtest/gtest.h>
43 #include <tf2_eigen/tf2_eigen.hpp>
44 #include <tf2_geometry_msgs/tf2_geometry_msgs.hpp>
52 #include <rclcpp/rclcpp.hpp>
57 static const std::string PARAM_NAMESPACE_LIMITS =
"robot_description_planning";
68 rclcpp::NodeOptions node_options;
69 node_options.automatically_declare_parameters_from_overrides(
true);
70 node_ = rclcpp::Node::make_shared(
"unittest_trajectory_generator_circ", node_options);
73 rm_loader_ = std::make_unique<robot_model_loader::RobotModelLoader>(node_);
74 robot_model_ = rm_loader_->getModel();
75 ASSERT_TRUE(
bool(robot_model_)) <<
"Failed to load robot model";
76 planning_scene_ = std::make_shared<planning_scene::PlanningScene>(robot_model_);
79 ASSERT_TRUE(node_->has_parameter(
"testdata_file_name"));
80 node_->get_parameter<std::string>(
"testdata_file_name", test_data_file_name_);
81 ASSERT_TRUE(node_->has_parameter(
"planning_group"));
82 node_->get_parameter<std::string>(
"planning_group", planning_group_);
83 ASSERT_TRUE(node_->has_parameter(
"target_link"));
84 node_->get_parameter<std::string>(
"target_link", target_link_);
85 ASSERT_TRUE(node_->has_parameter(
"cartesian_position_tolerance"));
86 node_->get_parameter<
double>(
"cartesian_position_tolerance", cartesian_position_tolerance_);
87 ASSERT_TRUE(node_->has_parameter(
"angular_acc_tolerance"));
88 node_->get_parameter<
double>(
"angular_acc_tolerance", angular_acc_tolerance_);
89 ASSERT_TRUE(node_->has_parameter(
"rot_axis_norm_tolerance"));
90 node_->get_parameter<
double>(
"rot_axis_norm_tolerance", rot_axis_norm_tolerance_);
91 ASSERT_TRUE(node_->has_parameter(
"acceleration_tolerance"));
92 node_->get_parameter<
double>(
"acceleration_tolerance", acceleration_tolerance_);
93 ASSERT_TRUE(node_->has_parameter(
"other_tolerance"));
94 node_->get_parameter<
double>(
"other_tolerance", other_tolerance_);
100 tdp_ = std::make_unique<pilz_industrial_motion_planner_testutils::XmlTestdataLoader>(test_data_file_name_);
101 ASSERT_NE(
nullptr, tdp_) <<
"Failed to load test data by provider.";
103 tdp_->setRobotModel(robot_model_);
108 node_, PARAM_NAMESPACE_LIMITS, robot_model_->getActiveJointModels());
118 planner_limits_.setCartesianLimits(cart_limits);
121 circ_ = std::make_unique<TrajectoryGeneratorCIRC>(robot_model_, planner_limits_, planning_group_);
122 ASSERT_NE(
nullptr, circ_) <<
"failed to create CIRC trajectory generator";
128 moveit_msgs::msg::MotionPlanResponse res_msg;
131 res_msg.trajectory.joint_trajectory, req, other_tolerance_));
136 EXPECT_EQ(req.path_constraints.position_constraints.size(), 1u);
137 EXPECT_EQ(req.path_constraints.position_constraints.at(0).constraint_region.primitive_poses.size(), 1u);
141 getCircCenter(req, res, circ_center);
143 for (std::size_t i = 0; i < res.
trajectory_->getWayPointCount(); ++i)
145 Eigen::Affine3d waypoint_pose = res.
trajectory_->getWayPointPtr(i)->getFrameTransform(target_link_);
147 (res.
trajectory_->getFirstWayPointPtr()->getFrameTransform(target_link_).translation() - circ_center).norm(),
148 (circ_center - waypoint_pose.translation()).norm(), cartesian_position_tolerance_);
154 rot_axis_norm_tolerance_));
156 for (
size_t idx = 0; idx < res.
trajectory_->getLastWayPointPtr()->getVariableCount(); ++idx)
158 EXPECT_NEAR(0.0, res.
trajectory_->getLastWayPointPtr()->getVariableVelocity(idx), other_tolerance_);
159 EXPECT_NEAR(0.0, res.
trajectory_->getLastWayPointPtr()->getVariableAcceleration(idx), other_tolerance_);
165 robot_model_.reset();
171 if (req.path_constraints.name ==
"center")
173 tf2::fromMsg(req.path_constraints.position_constraints.at(0).constraint_region.primitive_poses.at(0).position,
176 else if (req.path_constraints.name ==
"interim")
179 tf2::fromMsg(req.path_constraints.position_constraints.at(0).constraint_region.primitive_poses.at(0).position,
190 ASSERT_GT(
w.norm(), 1e-8) <<
"Circle center not well defined for given start, interim and goal.";
192 circ_center = start + (u * t.dot(t) * u.dot(v) - t * u.dot(u) * t.dot(v)) * 0.5 / pow(
w.norm(), 2);
200 std::unique_ptr<robot_model_loader::RobotModelLoader>
rm_loader_;
203 std::unique_ptr<TrajectoryGeneratorCIRC>
circ_;
205 std::unique_ptr<pilz_industrial_motion_planner_testutils::TestdataLoader>
tdp_;
222 std::shared_ptr<CircleNoPlane> cnp_ex{
new CircleNoPlane(
"") };
223 EXPECT_EQ(cnp_ex->getErrorCode(), moveit_msgs::msg::MoveItErrorCodes::INVALID_MOTION_PLAN);
227 std::shared_ptr<CircleToSmall> cts_ex{
new CircleToSmall(
"") };
228 EXPECT_EQ(cts_ex->getErrorCode(), moveit_msgs::msg::MoveItErrorCodes::INVALID_MOTION_PLAN);
232 std::shared_ptr<CenterPointDifferentRadius> cpdr_ex{
new CenterPointDifferentRadius(
"") };
233 EXPECT_EQ(cpdr_ex->getErrorCode(), moveit_msgs::msg::MoveItErrorCodes::INVALID_MOTION_PLAN);
237 std::shared_ptr<CircTrajectoryConversionFailure> ctcf_ex{
new CircTrajectoryConversionFailure(
"") };
238 EXPECT_EQ(ctcf_ex->getErrorCode(), moveit_msgs::msg::MoveItErrorCodes::INVALID_MOTION_PLAN);
242 std::shared_ptr<UnknownPathConstraintName> upcn_ex{
new UnknownPathConstraintName(
"") };
243 EXPECT_EQ(upcn_ex->getErrorCode(), moveit_msgs::msg::MoveItErrorCodes::INVALID_MOTION_PLAN);
247 std::shared_ptr<NoPositionConstraints> npc_ex{
new NoPositionConstraints(
"") };
248 EXPECT_EQ(npc_ex->getErrorCode(), moveit_msgs::msg::MoveItErrorCodes::INVALID_MOTION_PLAN);
252 std::shared_ptr<NoPrimitivePose> npp_ex{
new NoPrimitivePose(
"") };
253 EXPECT_EQ(npp_ex->getErrorCode(), moveit_msgs::msg::MoveItErrorCodes::INVALID_MOTION_PLAN);
257 std::shared_ptr<UnknownLinkNameOfAuxiliaryPoint> ulnoap_ex{
new UnknownLinkNameOfAuxiliaryPoint(
"") };
258 EXPECT_EQ(ulnoap_ex->getErrorCode(), moveit_msgs::msg::MoveItErrorCodes::INVALID_LINK_NAME);
262 std::shared_ptr<NumberOfConstraintsMismatch> nocm_ex{
new NumberOfConstraintsMismatch(
"") };
263 EXPECT_EQ(nocm_ex->getErrorCode(), moveit_msgs::msg::MoveItErrorCodes::INVALID_GOAL_CONSTRAINTS);
267 std::shared_ptr<CircInverseForGoalIncalculable> cifgi_ex{
new CircInverseForGoalIncalculable(
"") };
268 EXPECT_EQ(cifgi_ex->getErrorCode(), moveit_msgs::msg::MoveItErrorCodes::NO_IK_SOLUTION);
279 TrajectoryGeneratorInvalidLimitsException);
290 req.start_state.joint_state.velocity.push_back(1.0);
292 EXPECT_FALSE(circ_->generate(planning_scene_, req, res));
293 EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::INVALID_ROBOT_STATE);
294 req.start_state.joint_state.velocity.clear();
299 auto circ{ tdp_->getCircCartCenterCart(
"circ1_center_2") };
302 EXPECT_TRUE(circ_->generate(planning_scene_, circ.toRequest(), res));
303 EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::SUCCESS);
311 auto circ{ tdp_->getCircCartCenterCart(
"circ1_center_2") };
313 circ.setVelocityScale(1.0);
315 EXPECT_FALSE(circ_->generate(planning_scene_, circ.toRequest(), res));
316 EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::PLANNING_FAILED);
324 auto circ{ tdp_->getCircCartCenterCart(
"circ1_center_2") };
326 circ.setAccelerationScale(1.0);
328 EXPECT_FALSE(circ_->generate(planning_scene_, circ.toRequest(), res));
329 EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::PLANNING_FAILED);
339 auto circ{ tdp_->getCircCartCenterCart(
"circ1_center_2") };
340 circ.getAuxiliaryConfiguration().getConfiguration().setPose(circ.getStartConfiguration().getPose());
341 circ.getAuxiliaryConfiguration().getConfiguration().getPose().position.x += 1e-8;
342 circ.getAuxiliaryConfiguration().getConfiguration().getPose().position.y += 1e-8;
343 circ.getAuxiliaryConfiguration().getConfiguration().getPose().position.z += 1e-8;
344 circ.getGoalConfiguration().setPose(circ.getStartConfiguration().getPose());
345 circ.getGoalConfiguration().getPose().position.x -= 1e-8;
346 circ.getGoalConfiguration().getPose().position.y -= 1e-8;
347 circ.getGoalConfiguration().getPose().position.z -= 1e-8;
350 EXPECT_FALSE(circ_->generate(planning_scene_, circ.toRequest(), res));
351 EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::INVALID_MOTION_PLAN);
362 auto circ{ tdp_->getCircCartInterimCart(
"circ3_interim") };
363 circ.getAuxiliaryConfiguration().getConfiguration().setPose(circ.getStartConfiguration().getPose());
364 circ.getAuxiliaryConfiguration().getConfiguration().getPose().position.x += 1e-8;
365 circ.getAuxiliaryConfiguration().getConfiguration().getPose().position.y += 1e-8;
366 circ.getAuxiliaryConfiguration().getConfiguration().getPose().position.z += 1e-8;
367 circ.getGoalConfiguration().setPose(circ.getStartConfiguration().getPose());
368 circ.getGoalConfiguration().getPose().position.x -= 1e-8;
369 circ.getGoalConfiguration().getPose().position.y -= 1e-8;
370 circ.getGoalConfiguration().getPose().position.z -= 1e-8;
373 EXPECT_FALSE(circ_->generate(planning_scene_, circ.toRequest(), res));
374 EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::INVALID_MOTION_PLAN);
382 auto circ{ tdp_->getCircCartCenterCart(
"circ1_center_2") };
386 req.path_constraints.position_constraints.clear();
389 EXPECT_FALSE(circ_->generate(planning_scene_, req, res));
390 EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::INVALID_MOTION_PLAN);
398 auto circ{ tdp_->getCircCartCenterCart(
"circ1_center_2") };
402 req.path_constraints.name =
"";
405 EXPECT_FALSE(circ_->generate(planning_scene_, req, res));
406 EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::INVALID_MOTION_PLAN);
415 auto circ{ tdp_->getCircJointInterimCart(
"circ3_interim") };
419 req.path_constraints.position_constraints.front().link_name =
"INVALID";
422 EXPECT_FALSE(circ_->generate(planning_scene_, req, res));
423 EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::INVALID_LINK_NAME);
431 auto circ{ tdp_->getCircCartCenterCart(
"circ1_center_2") };
432 circ.getAuxiliaryConfiguration().getConfiguration().setPose(circ.getStartConfiguration().getPose());
433 circ.getAuxiliaryConfiguration().getConfiguration().getPose().position.y += 1;
436 EXPECT_FALSE(circ_->generate(planning_scene_, circ.toRequest(), res));
437 EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::INVALID_MOTION_PLAN);
447 auto circ{ tdp_->getCircCartCenterCart(
"circ1_center_2") };
448 circ.getAuxiliaryConfiguration().getConfiguration().setPose(circ.getStartConfiguration().getPose());
449 circ.getGoalConfiguration().setPose(circ.getStartConfiguration().getPose());
452 circ.getStartConfiguration().getPose().position.x -= 0.1;
453 circ.getGoalConfiguration().getPose().position.x += 0.1;
456 EXPECT_FALSE(circ_->generate(planning_scene_, circ.toRequest(), res));
457 EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::INVALID_MOTION_PLAN);
468 auto circ{ tdp_->getCircCartInterimCart(
"circ3_interim") };
469 circ.getAuxiliaryConfiguration().getConfiguration().setPose(circ.getStartConfiguration().getPose());
470 circ.getGoalConfiguration().setPose(circ.getStartConfiguration().getPose());
473 circ.getStartConfiguration().getPose().position.x -= 0.1;
474 circ.getGoalConfiguration().getPose().position.x += 0.1;
477 EXPECT_FALSE(circ_->generate(planning_scene_, circ.toRequest(), res));
478 EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::INVALID_MOTION_PLAN);
492 auto circ{ tdp_->getCircCartInterimCart(
"circ3_interim") };
495 ASSERT_TRUE(circ_->generate(planning_scene_, circ.toRequest(), res));
496 EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::SUCCESS);
511 auto circ{ tdp_->getCircCartInterimCart(
"circ3_interim") };
515 circ.getAuxiliaryConfiguration().getConfiguration().setPose(circ.getStartConfiguration().getPose());
516 circ.getGoalConfiguration().setPose(circ.getStartConfiguration().getPose());
518 circ.getStartConfiguration().getPose().position.x -= 0.2;
519 circ.getAuxiliaryConfiguration().getConfiguration().getPose().position.x += 0.2;
520 circ.getGoalConfiguration().getPose().position.y -= 0.2;
522 circ.setAccelerationScale(0.05);
523 circ.setVelocityScale(0.05);
528 EXPECT_TRUE(circ_->generate(planning_scene_, req, res));
529 EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::SUCCESS);
530 checkCircResult(req, res);
544 auto circ{ tdp_->getCircCartInterimCart(
"circ3_interim") };
548 circ.getAuxiliaryConfiguration().getConfiguration().setPose(circ.getStartConfiguration().getPose());
549 circ.getGoalConfiguration().setPose(circ.getStartConfiguration().getPose());
551 circ.getStartConfiguration().getPose().position.x -= 0.2;
552 circ.getAuxiliaryConfiguration().getConfiguration().getPose().position.x += 0.14142136;
553 circ.getAuxiliaryConfiguration().getConfiguration().getPose().position.y -= 0.14142136;
554 circ.getGoalConfiguration().getPose().position.y -= 0.2;
556 circ.setAccelerationScale(0.05);
557 circ.setVelocityScale(0.05);
562 EXPECT_TRUE(circ_->generate(planning_scene_, req, res));
563 EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::SUCCESS);
564 checkCircResult(req, res);
572 auto circ{ tdp_->getCircJointCenterCart(
"circ1_center_2") };
576 ASSERT_TRUE(circ_->generate(planning_scene_, req, res));
577 EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::SUCCESS);
578 checkCircResult(req, res);
588 auto circ{ tdp_->getCircCartCenterCart(
"circ1_center_2") };
593 ASSERT_EQ(req.path_constraints.position_constraints.back().constraint_region.primitive_poses.size(), 1u);
596 geometry_msgs::msg::Pose center_position;
597 center_position.position.x = 0.0;
598 center_position.position.y = 0.0;
599 center_position.position.z = 0.65;
600 req.path_constraints.position_constraints.back().constraint_region.primitive_poses.push_back(center_position);
603 ASSERT_FALSE(circ_->generate(planning_scene_, req, res));
604 EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::INVALID_MOTION_PLAN);
615 auto circ{ tdp_->getCircJointCenterCart(
"circ1_center_2") };
620 moveit_msgs::msg::JointConstraint joint_constraint;
621 joint_constraint.joint_name = req.goal_constraints.front().joint_constraints.front().joint_name;
622 req.goal_constraints.front().joint_constraints.push_back(joint_constraint);
625 EXPECT_FALSE(circ_->generate(planning_scene_, req, res));
626 EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::INVALID_GOAL_CONSTRAINTS);
634 auto circ{ tdp_->getCircCartCenterCart(
"circ1_center_2") };
639 ASSERT_TRUE(circ_->generate(planning_scene_, req, res));
640 EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::SUCCESS);
641 checkCircResult(req, res);
649 auto circ{ tdp_->getCircCartCenterCart(
"circ1_center_2") };
653 req.goal_constraints.front().position_constraints.front().header.frame_id = robot_model_->getModelFrame();
656 ASSERT_TRUE(circ_->generate(planning_scene_, req, res));
657 EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::SUCCESS);
658 checkCircResult(req, res);
666 auto circ{ tdp_->getCircCartCenterCart(
"circ1_center_2") };
669 req.goal_constraints.front().orientation_constraints.front().header.frame_id = robot_model_->getModelFrame();
672 ASSERT_TRUE(circ_->generate(planning_scene_, req, res));
673 EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::SUCCESS);
674 checkCircResult(req, res);
682 auto circ{ tdp_->getCircCartCenterCart(
"circ1_center_2") };
687 req.goal_constraints.front().position_constraints.front().header.frame_id = robot_model_->getModelFrame();
688 req.goal_constraints.front().orientation_constraints.front().header.frame_id = robot_model_->getModelFrame();
691 ASSERT_TRUE(circ_->generate(planning_scene_, req, res));
692 EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::SUCCESS);
693 checkCircResult(req, res);
701 auto circ{ tdp_->getCircJointInterimCart(
"circ3_interim") };
706 ASSERT_TRUE(circ_->generate(planning_scene_, req, res));
707 EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::SUCCESS);
708 checkCircResult(req, res);
719 auto circ{ tdp_->getCircJointInterimCart(
"circ3_interim") };
724 req.start_state.joint_state.velocity = std::vector<double>(req.start_state.joint_state.position.size(), 1e-16);
727 ASSERT_TRUE(circ_->generate(planning_scene_, req, res));
728 EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::SUCCESS);
729 checkCircResult(req, res);
737 auto circ{ tdp_->getCircJointInterimCart(
"circ3_interim") };
741 ASSERT_TRUE(circ_->generate(planning_scene_, req, res));
742 EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::SUCCESS);
743 checkCircResult(req, res);
746 int main(
int argc,
char** argv)
748 rclcpp::init(argc, argv);
749 testing::InitGoogleTest(&argc, argv);
750 return RUN_ALL_TESTS();
void SetUp() override
Create test scenario for circ trajectory generator.
std::unique_ptr< TrajectoryGeneratorCIRC > circ_
std::unique_ptr< pilz_industrial_motion_planner_testutils::TestdataLoader > tdp_
void getCircCenter(const planning_interface::MotionPlanRequest &req, const planning_interface::MotionPlanResponse &res, Eigen::Vector3d &circ_center)
double acceleration_tolerance_
LimitsContainer planner_limits_
moveit::core::RobotModelConstPtr robot_model_
void checkCircResult(const planning_interface::MotionPlanRequest &req, const planning_interface::MotionPlanResponse &res)
std::string planning_group_
planning_scene::PlanningSceneConstPtr planning_scene_
std::unique_ptr< robot_model_loader::RobotModelLoader > rm_loader_
rclcpp::Node::SharedPtr node_
Set of cartesian limits, has values for velocity, acceleration and deceleration of both the translati...
void setMaxRotationalVelocity(double max_rot_vel)
Set the maximum rotational velocity.
void setMaxTranslationalVelocity(double max_trans_vel)
Set the maximal translational velocity.
void setMaxTranslationalAcceleration(double max_trans_acc)
Set the maximum translational acceleration.
void setMaxTranslationalDeceleration(double max_trans_dec)
Set the maximum translational deceleration.
static JointLimitsContainer getAggregatedLimits(const rclcpp::Node::SharedPtr &node, const std::string ¶m_namespace, const std::vector< const moveit::core::JointModel * > &joint_models)
Aggregates(combines) the joint limits from joint model and node parameters. The rules for the combina...
Container for JointLimits, essentially a map with convenience functions. Adds the ability to as for l...
This class combines CartesianLimit and JointLimits into on single class.
This class implements a trajectory generator of arcs in Cartesian space. The arc is specified by a st...
Vec3fX< details::Vec3Data< double > > Vector3d
TEST_F(GetSolverTipFrameIntegrationTest, TestHasSolverManipulator)
Check if hasSolver() can be called successfully for the manipulator group.
moveit_msgs::msg::MotionPlanRequest MotionPlanRequest
bool isGoalReached(const trajectory_msgs::msg::JointTrajectory &trajectory, const std::vector< moveit_msgs::msg::JointConstraint > &goal, const double joint_position_tolerance, const double joint_velocity_tolerance=1.0e-6)
check if the goal given in joint space is reached Only the last point in the trajectory is veryfied.
::testing::AssertionResult checkCartesianTranslationalPath(const robot_trajectory::RobotTrajectoryConstPtr &trajectory, const std::string &link_name, const double acc_tol=DEFAULT_ACCELERATION_EQUALITY_TOLERANCE)
Check that the translational path of a given trajectory has a trapezoid velocity profile.
bool checkJointTrajectory(const trajectory_msgs::msg::JointTrajectory &trajectory, const pilz_industrial_motion_planner::JointLimitsContainer &joint_limits)
check joint trajectory of consistency, position, velocity and acceleration limits
void checkRobotModel(const moveit::core::RobotModelConstPtr &robot_model, const std::string &group_name, const std::string &link_name)
::testing::AssertionResult checkCartesianRotationalPath(const robot_trajectory::RobotTrajectoryConstPtr &trajectory, const std::string &link_name, const double rot_axis_tol=DEFAULT_ROTATION_AXIS_EQUALITY_TOLERANCE, const double acc_tol=DEFAULT_ACCELERATION_EQUALITY_TOLERANCE)
Check that the rotational path of a given trajectory is a quaternion slerp.
robot_trajectory::RobotTrajectoryPtr trajectory_
void getMessage(moveit_msgs::msg::MotionPlanResponse &msg) const
moveit_msgs::msg::MoveItErrorCodes error_code_
int main(int argc, char **argv)