37 #include <gtest/gtest.h> 
   46 #include <pluginlib/class_loader.hpp> 
   48 #include <rclcpp/rclcpp.hpp> 
   69     rclcpp::NodeOptions node_options;
 
   70     node_options.automatically_declare_parameters_from_overrides(
true);
 
   71     node_ = rclcpp::Node::make_shared(
"unittest_trajectory_generator_ptp", node_options);
 
   74     rm_loader_ = std::make_unique<robot_model_loader::RobotModelLoader>(node_);
 
   75     robot_model_ = rm_loader_->getModel();
 
   76     ASSERT_TRUE(
bool(robot_model_)) << 
"Failed to load robot model";
 
   77     planning_scene_ = std::make_shared<planning_scene::PlanningScene>(robot_model_);
 
   80     ASSERT_TRUE(node_->has_parameter(
"planning_group"));
 
   81     node_->get_parameter<std::string>(
"planning_group", planning_group_);
 
   82     ASSERT_TRUE(node_->has_parameter(
"target_link"));
 
   83     node_->get_parameter<std::string>(
"target_link", target_link_);
 
   84     ASSERT_TRUE(node_->has_parameter(
"joint_position_tolerance"));
 
   85     node_->get_parameter<
double>(
"joint_position_tolerance", joint_position_tolerance_);
 
   86     ASSERT_TRUE(node_->has_parameter(
"joint_velocity_tolerance"));
 
   87     node_->get_parameter<
double>(
"joint_velocity_tolerance", joint_velocity_tolerance_);
 
   88     ASSERT_TRUE(node_->has_parameter(
"joint_acceleration_tolerance"));
 
   89     node_->get_parameter<
double>(
"joint_acceleration_tolerance", joint_acceleration_tolerance_);
 
   90     ASSERT_TRUE(node_->has_parameter(
"pose_norm_tolerance"));
 
   91     node_->get_parameter<
double>(
"pose_norm_tolerance", pose_norm_tolerance_);
 
   97     for (
const auto& jmg : robot_model_->getJointModelGroups())
 
   99       std::vector<std::string> joint_names = jmg->getActiveJointModelNames();
 
  109       for (
const auto& joint_name : joint_names)
 
  117     ptp_ = std::make_unique<TrajectoryGeneratorPTP>(robot_model_, planner_limits_, planning_group_);
 
  118     ASSERT_NE(
nullptr, ptp_);
 
  123     robot_model_.reset();
 
  138                                      joint_position_tolerance_, joint_velocity_tolerance_) &&
 
  148   std::unique_ptr<robot_model_loader::RobotModelLoader> 
rm_loader_;
 
  152   std::unique_ptr<TrajectoryGenerator> 
ptp_;
 
  167     std::shared_ptr<PtpVelocityProfileSyncFailed> pvpsf_ex{ 
new PtpVelocityProfileSyncFailed(
"") };
 
  168     EXPECT_EQ(pvpsf_ex->getErrorCode(), moveit_msgs::msg::MoveItErrorCodes::FAILURE);
 
  172     std::shared_ptr<PtpNoIkSolutionForGoalPose> pnisfgp_ex{ 
new PtpNoIkSolutionForGoalPose(
"") };
 
  173     EXPECT_EQ(pnisfgp_ex->getErrorCode(), moveit_msgs::msg::MoveItErrorCodes::NO_IK_SOLUTION);
 
  184                TrajectoryGeneratorInvalidLimitsException);
 
  202   robot_trajectory::RobotTrajectoryPtr trajectory(
 
  205   trajectory->addPrefixWayPoint(state, 0);
 
  210   EXPECT_FALSE(ptp_->generate(planning_scene_, req, res));
 
  223   auto joint_models = robot_model_->getActiveJointModels();
 
  229   for (
const auto& joint_model : joint_models)
 
  231     ASSERT_TRUE(
joint_limits.addLimit(joint_model->getName(), joint_limit))
 
  232         << 
"Failed to add the limits for joint " << joint_model->getName();
 
  237                TrajectoryGeneratorInvalidLimitsException);
 
  248   const auto& joint_models = robot_model_->getActiveJointModels();
 
  253   for (
const auto& joint_model : joint_models)
 
  255     ASSERT_TRUE(
joint_limits.addLimit(joint_model->getName(), joint_limit))
 
  256         << 
"Failed to add the limits for joint " << joint_model->getName();
 
  261                TrajectoryGeneratorInvalidLimitsException);
 
  280   const auto& joint_models = robot_model_->getActiveJointModels();
 
  281   ASSERT_TRUE(joint_models.size());
 
  293   for (
const auto& joint_model : joint_models)
 
  295     ASSERT_TRUE(insufficient_joint_limits.
addLimit(joint_model->getName(), insufficient_limit))
 
  296         << 
"Failed to add the limits for joint " << joint_model->getName();
 
  299   insufficient_planner_limits.
setJointLimits(insufficient_joint_limits);
 
  303         std::unique_ptr<TrajectoryGeneratorPTP> ptp_error(
 
  306       TrajectoryGeneratorInvalidLimitsException);
 
  314   sufficient_limit.max_position = 2.356;
 
  315   sufficient_limit.min_position = -2.356;
 
  316   sufficient_limit.has_velocity_limits = 
true;
 
  317   sufficient_limit.max_velocity = 1;
 
  318   sufficient_limit.has_acceleration_limits = 
true;
 
  319   sufficient_limit.max_acceleration = 0.5;
 
  320   sufficient_limit.has_deceleration_limits = 
true;
 
  321   sufficient_limit.max_deceleration = -1;
 
  325   for (
const auto& jmg : robot_model_->getJointModelGroups())
 
  327     const auto& joint_names{ jmg->getActiveJointModelNames() };
 
  328     ASSERT_FALSE(joint_names.empty());
 
  329     ASSERT_TRUE(sufficient_joint_limits.
addLimit(joint_names.front(), sufficient_limit))
 
  330         << 
"Failed to add the limits for joint " << joint_names.front();
 
  332     for (
auto it = std::next(joint_names.begin()); it != joint_names.end(); ++it)
 
  334       ASSERT_TRUE(sufficient_joint_limits.
addLimit((*it), insufficient_limit))
 
  335           << 
"Failed to add the limits for joint " << (*it);
 
  339   sufficient_planner_limits.
setJointLimits(sufficient_joint_limits);
 
  342     std::unique_ptr<TrajectoryGeneratorPTP> ptp_no_error(
 
  360   geometry_msgs::msg::PoseStamped pose;
 
  361   pose.pose.position.x = 0.1;
 
  362   pose.pose.position.y = 0.2;
 
  363   pose.pose.position.z = 0.65;
 
  364   pose.pose.orientation.w = 1.0;
 
  365   pose.pose.orientation.x = 0.0;
 
  366   pose.pose.orientation.y = 0.0;
 
  367   pose.pose.orientation.z = 0.0;
 
  368   std::vector<double> tolerance_pose(3, 0.01);
 
  369   std::vector<double> tolerance_angle(3, 0.01);
 
  370   moveit_msgs::msg::Constraints pose_goal =
 
  372   req.goal_constraints.push_back(pose_goal);
 
  377   ASSERT_TRUE(ptp_->generate(planning_scene_, req, res));
 
  378   EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::SUCCESS);
 
  380   moveit_msgs::msg::MotionPlanResponse res_msg;
 
  382   if (!res_msg.trajectory.joint_trajectory.points.empty())
 
  384     EXPECT_TRUE(checkTrajectory(res_msg.trajectory.joint_trajectory, req, planner_limits_.getJointLimitContainer()));
 
  388     FAIL() << 
"Received empty trajectory.";
 
  392   EXPECT_TRUE(
testutils::isGoalReached(robot_model_, res_msg.trajectory.joint_trajectory, req, pose_norm_tolerance_));
 
  409   geometry_msgs::msg::PoseStamped pose;
 
  410   pose.pose.position.x = 0.1;
 
  411   pose.pose.position.y = 0.2;
 
  412   pose.pose.position.z = 0.65;
 
  413   pose.pose.orientation.w = 1.0;
 
  414   pose.pose.orientation.x = 0.0;
 
  415   pose.pose.orientation.y = 0.0;
 
  416   pose.pose.orientation.z = 0.0;
 
  417   std::vector<double> tolerance_pose(3, 0.01);
 
  418   std::vector<double> tolerance_angle(3, 0.01);
 
  419   moveit_msgs::msg::Constraints pose_goal =
 
  421   req.goal_constraints.push_back(pose_goal);
 
  424   req_no_position_constaint_link_name.goal_constraints.front().position_constraints.front().link_name = 
"";
 
  425   ASSERT_FALSE(ptp_->generate(planning_scene_, req_no_position_constaint_link_name, res));
 
  426   EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::INVALID_GOAL_CONSTRAINTS);
 
  429   req_no_orientation_constaint_link_name.goal_constraints.front().orientation_constraints.front().link_name = 
"";
 
  430   ASSERT_FALSE(ptp_->generate(planning_scene_, req_no_orientation_constaint_link_name, res));
 
  431   EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::INVALID_GOAL_CONSTRAINTS);
 
  443   geometry_msgs::msg::PoseStamped pose;
 
  444   pose.pose.position.x = 0.1;
 
  445   pose.pose.position.y = 0.2;
 
  446   pose.pose.position.z = 2.5;
 
  447   pose.pose.orientation.w = 1.0;
 
  448   pose.pose.orientation.x = 0.0;
 
  449   pose.pose.orientation.y = 0.0;
 
  450   pose.pose.orientation.z = 0.0;
 
  451   std::vector<double> tolerance_pose(3, 0.01);
 
  452   std::vector<double> tolerance_angle(3, 0.01);
 
  453   moveit_msgs::msg::Constraints pose_goal =
 
  455   req.goal_constraints.push_back(pose_goal);
 
  457   ASSERT_FALSE(ptp_->generate(planning_scene_, req, res));
 
  458   EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::NO_IK_SOLUTION);
 
  472   ASSERT_TRUE(robot_model_->getJointModelGroup(planning_group_)->getActiveJointModelNames().size())
 
  473       << 
"No link exists in the planning group.";
 
  475   moveit_msgs::msg::Constraints gc;
 
  476   moveit_msgs::msg::JointConstraint jc;
 
  477   jc.joint_name = robot_model_->getJointModelGroup(planning_group_)->getActiveJointModelNames().front();
 
  479   gc.joint_constraints.push_back(jc);
 
  480   req.goal_constraints.push_back(gc);
 
  483   ASSERT_TRUE(ptp_->generate(planning_scene_, req, res));
 
  484   EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::SUCCESS);
 
  486   moveit_msgs::msg::MotionPlanResponse res_msg;
 
  488   EXPECT_EQ(1u, res_msg.trajectory.joint_trajectory.points.size());
 
  528   joint_limits.addLimit(
"prbt_gripper_finger_left_joint", joint_limit);
 
  534   ptp_ = std::make_unique<TrajectoryGeneratorPTP>(robot_model_, planner_limits, planning_group_);
 
  539   req.start_state.joint_state.position[2] = 0.1;
 
  540   moveit_msgs::msg::Constraints gc;
 
  541   moveit_msgs::msg::JointConstraint jc;
 
  542   jc.joint_name = 
"prbt_joint_1";
 
  544   gc.joint_constraints.push_back(jc);
 
  545   jc.joint_name = 
"prbt_joint_3";
 
  547   gc.joint_constraints.push_back(jc);
 
  548   jc.joint_name = 
"prbt_joint_6";
 
  550   gc.joint_constraints.push_back(jc);
 
  551   req.goal_constraints.push_back(gc);
 
  552   req.max_velocity_scaling_factor = 0.5;
 
  553   req.max_acceleration_scaling_factor = 1.0 / 3.0;
 
  555   ASSERT_TRUE(ptp_->generate(planning_scene_, req, res));
 
  556   EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::SUCCESS);
 
  558   moveit_msgs::msg::MotionPlanResponse res_msg;
 
  560   EXPECT_TRUE(checkTrajectory(res_msg.trajectory.joint_trajectory, req, planner_limits_.getJointLimitContainer()));
 
  564               joint_acceleration_tolerance_);
 
  570   EXPECT_NEAR(0.125, res_msg.trajectory.joint_trajectory.points[index].positions[0], joint_position_tolerance_);
 
  571   EXPECT_NEAR(0.25, res_msg.trajectory.joint_trajectory.points[index].velocities[0], joint_velocity_tolerance_);
 
  572   EXPECT_NEAR(0.25, res_msg.trajectory.joint_trajectory.points[index].accelerations[0], joint_acceleration_tolerance_);
 
  574   EXPECT_NEAR(1.0 / 6.0 + 0.1, res_msg.trajectory.joint_trajectory.points[index].positions[2],
 
  575               joint_position_tolerance_);
 
  576   EXPECT_NEAR(1.0 / 3.0, res_msg.trajectory.joint_trajectory.points[index].velocities[2], joint_velocity_tolerance_);
 
  577   EXPECT_NEAR(1.0 / 3.0, res_msg.trajectory.joint_trajectory.points[index].accelerations[2],
 
  578               joint_acceleration_tolerance_);
 
  580   EXPECT_NEAR(0.25, res_msg.trajectory.joint_trajectory.points[index].positions[5], joint_position_tolerance_);
 
  581   EXPECT_NEAR(0.5, res_msg.trajectory.joint_trajectory.points[index].velocities[5], joint_velocity_tolerance_);
 
  582   EXPECT_NEAR(0.5, res_msg.trajectory.joint_trajectory.points[index].accelerations[5], joint_acceleration_tolerance_);
 
  584   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].positions[4], joint_position_tolerance_);
 
  585   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].velocities[4], joint_velocity_tolerance_);
 
  586   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].accelerations[4], joint_acceleration_tolerance_);
 
  591   EXPECT_NEAR(0.5, res_msg.trajectory.joint_trajectory.points[index].positions[0], joint_position_tolerance_);
 
  592   EXPECT_NEAR(0.5, res_msg.trajectory.joint_trajectory.points[index].velocities[0], joint_velocity_tolerance_);
 
  594   EXPECT_NEAR(2.0 / 3.0 + 0.1, res_msg.trajectory.joint_trajectory.points[index].positions[2],
 
  595               joint_position_tolerance_);
 
  596   EXPECT_NEAR(2.0 / 3.0, res_msg.trajectory.joint_trajectory.points[index].velocities[2], joint_velocity_tolerance_);
 
  598   EXPECT_NEAR(1.0, res_msg.trajectory.joint_trajectory.points[index].positions[5], joint_position_tolerance_);
 
  599   EXPECT_NEAR(1.0, res_msg.trajectory.joint_trajectory.points[index].velocities[5], joint_velocity_tolerance_);
 
  601   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].positions[1], joint_position_tolerance_);
 
  602   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].velocities[1], joint_velocity_tolerance_);
 
  603   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].accelerations[1], joint_acceleration_tolerance_);
 
  608   EXPECT_NEAR(1, res_msg.trajectory.joint_trajectory.points[index].positions[0], joint_position_tolerance_);
 
  609   EXPECT_NEAR(0.5, res_msg.trajectory.joint_trajectory.points[index].velocities[0], joint_velocity_tolerance_);
 
  610   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].accelerations[0], joint_acceleration_tolerance_);
 
  612   EXPECT_NEAR(4.0 / 3.0 + 0.1, res_msg.trajectory.joint_trajectory.points[index].positions[2],
 
  613               joint_position_tolerance_);
 
  614   EXPECT_NEAR(2.0 / 3.0, res_msg.trajectory.joint_trajectory.points[index].velocities[2], joint_velocity_tolerance_);
 
  615   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].accelerations[2], joint_acceleration_tolerance_);
 
  617   EXPECT_NEAR(2.0, res_msg.trajectory.joint_trajectory.points[index].positions[5], joint_position_tolerance_);
 
  618   EXPECT_NEAR(1.0, res_msg.trajectory.joint_trajectory.points[index].velocities[5], joint_velocity_tolerance_);
 
  619   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].accelerations[5], joint_acceleration_tolerance_);
 
  621   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].positions[3], joint_position_tolerance_);
 
  622   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].velocities[3], joint_velocity_tolerance_);
 
  623   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].accelerations[3], joint_acceleration_tolerance_);
 
  628   EXPECT_NEAR(2.875 / 2.0, res_msg.trajectory.joint_trajectory.points[index].positions[0], joint_position_tolerance_);
 
  629   EXPECT_NEAR(0.25, res_msg.trajectory.joint_trajectory.points[index].velocities[0], joint_velocity_tolerance_);
 
  630   EXPECT_NEAR(-0.5, res_msg.trajectory.joint_trajectory.points[index].accelerations[0], joint_acceleration_tolerance_);
 
  632   EXPECT_NEAR(5.75 / 3.0 + 0.1, res_msg.trajectory.joint_trajectory.points[index].positions[2],
 
  633               joint_position_tolerance_);
 
  634   EXPECT_NEAR(1.0 / 3.0, res_msg.trajectory.joint_trajectory.points[index].velocities[2], joint_velocity_tolerance_);
 
  635   EXPECT_NEAR(-2.0 / 3.0, res_msg.trajectory.joint_trajectory.points[index].accelerations[2],
 
  636               joint_acceleration_tolerance_);
 
  638   EXPECT_NEAR(2.875, res_msg.trajectory.joint_trajectory.points[index].positions[5], joint_position_tolerance_);
 
  639   EXPECT_NEAR(0.5, res_msg.trajectory.joint_trajectory.points[index].velocities[5], joint_velocity_tolerance_);
 
  640   EXPECT_NEAR(-1.0, res_msg.trajectory.joint_trajectory.points[index].accelerations[5], joint_acceleration_tolerance_);
 
  645   EXPECT_NEAR(1.5, res_msg.trajectory.joint_trajectory.points[index].positions[0], joint_position_tolerance_);
 
  646   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].velocities[0], joint_velocity_tolerance_);
 
  648   EXPECT_NEAR(2.1, res_msg.trajectory.joint_trajectory.points[index].positions[2], joint_position_tolerance_);
 
  649   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].velocities[2], joint_velocity_tolerance_);
 
  651   EXPECT_NEAR(3.0, res_msg.trajectory.joint_trajectory.points[index].positions[5], joint_position_tolerance_);
 
  652   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].velocities[5], joint_velocity_tolerance_);
 
  664   req.start_state.joint_state.position[2] = 0.1;
 
  667   req.start_state.joint_state.velocity = std::vector<double>(req.start_state.joint_state.position.size(), 1e-16);
 
  669   moveit_msgs::msg::Constraints gc;
 
  670   moveit_msgs::msg::JointConstraint jc;
 
  671   jc.joint_name = 
"prbt_joint_1";
 
  673   gc.joint_constraints.push_back(jc);
 
  674   jc.joint_name = 
"prbt_joint_3";
 
  676   gc.joint_constraints.push_back(jc);
 
  677   jc.joint_name = 
"prbt_joint_6";
 
  679   gc.joint_constraints.push_back(jc);
 
  680   req.goal_constraints.push_back(gc);
 
  682   ASSERT_TRUE(ptp_->generate(planning_scene_, req, res));
 
  683   EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::SUCCESS);
 
  685   moveit_msgs::msg::MotionPlanResponse res_msg;
 
  687   EXPECT_TRUE(checkTrajectory(res_msg.trajectory.joint_trajectory, req, planner_limits_.getJointLimitContainer()));
 
  691               joint_acceleration_tolerance_);
 
  697   EXPECT_NEAR(0.125, res_msg.trajectory.joint_trajectory.points[index].positions[0], joint_position_tolerance_);
 
  698   EXPECT_NEAR(0.25, res_msg.trajectory.joint_trajectory.points[index].velocities[0], joint_velocity_tolerance_);
 
  699   EXPECT_NEAR(0.25, res_msg.trajectory.joint_trajectory.points[index].accelerations[0], joint_acceleration_tolerance_);
 
  701   EXPECT_NEAR(1.0 / 6.0 + 0.1, res_msg.trajectory.joint_trajectory.points[index].positions[2],
 
  702               joint_position_tolerance_);
 
  703   EXPECT_NEAR(1.0 / 3.0, res_msg.trajectory.joint_trajectory.points[index].velocities[2], joint_velocity_tolerance_);
 
  704   EXPECT_NEAR(1.0 / 3.0, res_msg.trajectory.joint_trajectory.points[index].accelerations[2],
 
  705               joint_acceleration_tolerance_);
 
  707   EXPECT_NEAR(0.25, res_msg.trajectory.joint_trajectory.points[index].positions[5], joint_position_tolerance_);
 
  708   EXPECT_NEAR(0.5, res_msg.trajectory.joint_trajectory.points[index].velocities[5], joint_velocity_tolerance_);
 
  709   EXPECT_NEAR(0.5, res_msg.trajectory.joint_trajectory.points[index].accelerations[5], joint_acceleration_tolerance_);
 
  711   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].positions[4], joint_position_tolerance_);
 
  712   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].velocities[4], joint_velocity_tolerance_);
 
  713   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].accelerations[4], joint_acceleration_tolerance_);
 
  718   EXPECT_NEAR(0.5, res_msg.trajectory.joint_trajectory.points[index].positions[0], joint_position_tolerance_);
 
  719   EXPECT_NEAR(0.5, res_msg.trajectory.joint_trajectory.points[index].velocities[0], joint_velocity_tolerance_);
 
  721   EXPECT_NEAR(2.0 / 3.0 + 0.1, res_msg.trajectory.joint_trajectory.points[index].positions[2],
 
  722               joint_position_tolerance_);
 
  723   EXPECT_NEAR(2.0 / 3.0, res_msg.trajectory.joint_trajectory.points[index].velocities[2], joint_velocity_tolerance_);
 
  725   EXPECT_NEAR(1.0, res_msg.trajectory.joint_trajectory.points[index].positions[5], joint_position_tolerance_);
 
  726   EXPECT_NEAR(1.0, res_msg.trajectory.joint_trajectory.points[index].velocities[5], joint_velocity_tolerance_);
 
  728   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].positions[1], joint_position_tolerance_);
 
  729   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].velocities[1], joint_velocity_tolerance_);
 
  730   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].accelerations[1], joint_acceleration_tolerance_);
 
  735   EXPECT_NEAR(1, res_msg.trajectory.joint_trajectory.points[index].positions[0], joint_position_tolerance_);
 
  736   EXPECT_NEAR(0.5, res_msg.trajectory.joint_trajectory.points[index].velocities[0], joint_velocity_tolerance_);
 
  737   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].accelerations[0], joint_acceleration_tolerance_);
 
  739   EXPECT_NEAR(4.0 / 3.0 + 0.1, res_msg.trajectory.joint_trajectory.points[index].positions[2],
 
  740               joint_position_tolerance_);
 
  741   EXPECT_NEAR(2.0 / 3.0, res_msg.trajectory.joint_trajectory.points[index].velocities[2], joint_velocity_tolerance_);
 
  742   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].accelerations[2], joint_acceleration_tolerance_);
 
  744   EXPECT_NEAR(2.0, res_msg.trajectory.joint_trajectory.points[index].positions[5], joint_position_tolerance_);
 
  745   EXPECT_NEAR(1.0, res_msg.trajectory.joint_trajectory.points[index].velocities[5], joint_velocity_tolerance_);
 
  746   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].accelerations[5], joint_acceleration_tolerance_);
 
  748   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].positions[3], joint_position_tolerance_);
 
  749   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].velocities[3], joint_velocity_tolerance_);
 
  750   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].accelerations[3], joint_acceleration_tolerance_);
 
  755   EXPECT_NEAR(2.875 / 2.0, res_msg.trajectory.joint_trajectory.points[index].positions[0], joint_position_tolerance_);
 
  756   EXPECT_NEAR(0.25, res_msg.trajectory.joint_trajectory.points[index].velocities[0], joint_velocity_tolerance_);
 
  757   EXPECT_NEAR(-0.5, res_msg.trajectory.joint_trajectory.points[index].accelerations[0], joint_acceleration_tolerance_);
 
  759   EXPECT_NEAR(5.75 / 3.0 + 0.1, res_msg.trajectory.joint_trajectory.points[index].positions[2],
 
  760               joint_position_tolerance_);
 
  761   EXPECT_NEAR(1.0 / 3.0, res_msg.trajectory.joint_trajectory.points[index].velocities[2], joint_velocity_tolerance_);
 
  762   EXPECT_NEAR(-2.0 / 3.0, res_msg.trajectory.joint_trajectory.points[index].accelerations[2],
 
  763               joint_acceleration_tolerance_);
 
  765   EXPECT_NEAR(2.875, res_msg.trajectory.joint_trajectory.points[index].positions[5], joint_position_tolerance_);
 
  766   EXPECT_NEAR(0.5, res_msg.trajectory.joint_trajectory.points[index].velocities[5], joint_velocity_tolerance_);
 
  767   EXPECT_NEAR(-1.0, res_msg.trajectory.joint_trajectory.points[index].accelerations[5], joint_acceleration_tolerance_);
 
  772   EXPECT_NEAR(1.5, res_msg.trajectory.joint_trajectory.points[index].positions[0], joint_position_tolerance_);
 
  773   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].velocities[0], joint_velocity_tolerance_);
 
  775   EXPECT_NEAR(2.1, res_msg.trajectory.joint_trajectory.points[index].positions[2], joint_position_tolerance_);
 
  776   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].velocities[2], joint_velocity_tolerance_);
 
  778   EXPECT_NEAR(3.0, res_msg.trajectory.joint_trajectory.points[index].positions[5], joint_position_tolerance_);
 
  779   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].velocities[5], joint_velocity_tolerance_);
 
  782   EXPECT_TRUE(std::all_of(res_msg.trajectory.joint_trajectory.points.back().velocities.cbegin(),
 
  783                           res_msg.trajectory.joint_trajectory.points.back().velocities.cend(),
 
  784                           [
this](
double v) { return std::fabs(v) < this->joint_velocity_tolerance_; }));
 
  787   EXPECT_TRUE(std::all_of(res_msg.trajectory.joint_trajectory.points.back().accelerations.cbegin(),
 
  788                           res_msg.trajectory.joint_trajectory.points.back().accelerations.cend(),
 
  789                           [
this](
double v) { return std::fabs(v) < this->joint_acceleration_tolerance_; }));
 
  801   req.start_state.joint_state.position[4] = 0.3;
 
  802   req.start_state.joint_state.position[2] = 0.11;
 
  804   moveit_msgs::msg::Constraints gc;
 
  805   moveit_msgs::msg::JointConstraint jc;
 
  807   jc.joint_name = 
"prbt_joint_1";
 
  809   gc.joint_constraints.push_back(jc);
 
  810   jc.joint_name = 
"prbt_joint_2";
 
  812   gc.joint_constraints.push_back(jc);
 
  813   jc.joint_name = 
"prbt_joint_3";
 
  815   gc.joint_constraints.push_back(jc);
 
  816   jc.joint_name = 
"prbt_joint_4";
 
  818   gc.joint_constraints.push_back(jc);
 
  819   jc.joint_name = 
"prbt_joint_6";
 
  821   gc.joint_constraints.push_back(jc);
 
  822   req.goal_constraints.push_back(gc);
 
  824   ASSERT_TRUE(ptp_->generate(planning_scene_, req, res));
 
  825   EXPECT_EQ(res.
error_code_.val, moveit_msgs::msg::MoveItErrorCodes::SUCCESS);
 
  827   moveit_msgs::msg::MotionPlanResponse res_msg;
 
  829   EXPECT_TRUE(checkTrajectory(res_msg.trajectory.joint_trajectory, req, planner_limits_.getJointLimitContainer()));
 
  833               joint_position_tolerance_);
 
  837   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[0].positions[0], joint_position_tolerance_);
 
  838   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[0].velocities[0], joint_velocity_tolerance_);
 
  840   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[0].positions[1], joint_position_tolerance_);
 
  841   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[0].velocities[1], joint_velocity_tolerance_);
 
  843   EXPECT_NEAR(0.11, res_msg.trajectory.joint_trajectory.points[0].positions[2], joint_position_tolerance_);
 
  844   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[0].velocities[2], joint_velocity_tolerance_);
 
  846   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[0].positions[3], joint_position_tolerance_);
 
  847   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[0].velocities[3], joint_velocity_tolerance_);
 
  849   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[0].positions[5], joint_position_tolerance_);
 
  850   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[0].velocities[5], joint_velocity_tolerance_);
 
  856   EXPECT_NEAR(0.125, res_msg.trajectory.joint_trajectory.points[index].positions[0], joint_position_tolerance_);
 
  857   EXPECT_NEAR(0.25, res_msg.trajectory.joint_trajectory.points[index].velocities[0], joint_velocity_tolerance_);
 
  858   EXPECT_NEAR(0.25, res_msg.trajectory.joint_trajectory.points[index].accelerations[0], joint_acceleration_tolerance_);
 
  860   EXPECT_NEAR(-0.125, res_msg.trajectory.joint_trajectory.points[index].positions[1], joint_position_tolerance_);
 
  861   EXPECT_NEAR(-0.25, res_msg.trajectory.joint_trajectory.points[index].velocities[1], joint_velocity_tolerance_);
 
  862   EXPECT_NEAR(-0.25, res_msg.trajectory.joint_trajectory.points[index].accelerations[1], joint_acceleration_tolerance_);
 
  864   EXPECT_NEAR(1.0 / 6.0 + 0.11, res_msg.trajectory.joint_trajectory.points[index].positions[2],
 
  865               joint_position_tolerance_);
 
  866   EXPECT_NEAR(1.0 / 3.0, res_msg.trajectory.joint_trajectory.points[index].velocities[2], joint_velocity_tolerance_);
 
  867   EXPECT_NEAR(1.0 / 3.0, res_msg.trajectory.joint_trajectory.points[index].accelerations[2],
 
  868               joint_acceleration_tolerance_);
 
  870   EXPECT_NEAR(-1.0 / 6.0, res_msg.trajectory.joint_trajectory.points[index].positions[3], joint_position_tolerance_);
 
  871   EXPECT_NEAR(-1.0 / 3.0, res_msg.trajectory.joint_trajectory.points[index].velocities[3], joint_velocity_tolerance_);
 
  872   EXPECT_NEAR(-1.0 / 3.0, res_msg.trajectory.joint_trajectory.points[index].accelerations[3],
 
  873               joint_acceleration_tolerance_);
 
  875   EXPECT_NEAR(0.25, res_msg.trajectory.joint_trajectory.points[index].positions[5], joint_position_tolerance_);
 
  876   EXPECT_NEAR(0.5, res_msg.trajectory.joint_trajectory.points[index].velocities[5], joint_velocity_tolerance_);
 
  877   EXPECT_NEAR(0.5, res_msg.trajectory.joint_trajectory.points[index].accelerations[5], joint_acceleration_tolerance_);
 
  882   EXPECT_NEAR(0.5, res_msg.trajectory.joint_trajectory.points[index].positions[0], joint_position_tolerance_);
 
  883   EXPECT_NEAR(0.5, res_msg.trajectory.joint_trajectory.points[index].velocities[0], joint_velocity_tolerance_);
 
  885   EXPECT_NEAR(-0.5, res_msg.trajectory.joint_trajectory.points[index].positions[1], joint_position_tolerance_);
 
  886   EXPECT_NEAR(-0.5, res_msg.trajectory.joint_trajectory.points[index].velocities[1], joint_velocity_tolerance_);
 
  888   EXPECT_NEAR(2.0 / 3.0 + 0.11, res_msg.trajectory.joint_trajectory.points[index].positions[2],
 
  889               joint_position_tolerance_);
 
  890   EXPECT_NEAR(2.0 / 3.0, res_msg.trajectory.joint_trajectory.points[index].velocities[2], joint_velocity_tolerance_);
 
  892   EXPECT_NEAR(-2.0 / 3.0, res_msg.trajectory.joint_trajectory.points[index].positions[3], joint_position_tolerance_);
 
  893   EXPECT_NEAR(-2.0 / 3.0, res_msg.trajectory.joint_trajectory.points[index].velocities[3], joint_velocity_tolerance_);
 
  895   EXPECT_NEAR(1.0, res_msg.trajectory.joint_trajectory.points[index].positions[5], joint_position_tolerance_);
 
  896   EXPECT_NEAR(1.0, res_msg.trajectory.joint_trajectory.points[index].velocities[5], joint_velocity_tolerance_);
 
  901   EXPECT_NEAR(1, res_msg.trajectory.joint_trajectory.points[index].positions[0], joint_position_tolerance_);
 
  902   EXPECT_NEAR(0.5, res_msg.trajectory.joint_trajectory.points[index].velocities[0], joint_velocity_tolerance_);
 
  903   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].accelerations[0], joint_acceleration_tolerance_);
 
  905   EXPECT_NEAR(-1, res_msg.trajectory.joint_trajectory.points[index].positions[1], joint_position_tolerance_);
 
  906   EXPECT_NEAR(-0.5, res_msg.trajectory.joint_trajectory.points[index].velocities[1], joint_velocity_tolerance_);
 
  907   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].accelerations[1], joint_acceleration_tolerance_);
 
  909   EXPECT_NEAR(4.0 / 3.0 + 0.11, res_msg.trajectory.joint_trajectory.points[index].positions[2],
 
  910               joint_position_tolerance_);
 
  911   EXPECT_NEAR(2.0 / 3.0, res_msg.trajectory.joint_trajectory.points[index].velocities[2], joint_velocity_tolerance_);
 
  912   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].accelerations[2], joint_acceleration_tolerance_);
 
  914   EXPECT_NEAR(-4.0 / 3.0, res_msg.trajectory.joint_trajectory.points[index].positions[3], joint_position_tolerance_);
 
  915   EXPECT_NEAR(-2.0 / 3.0, res_msg.trajectory.joint_trajectory.points[index].velocities[3], joint_velocity_tolerance_);
 
  916   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].accelerations[3], joint_acceleration_tolerance_);
 
  918   EXPECT_NEAR(2.0, res_msg.trajectory.joint_trajectory.points[index].positions[5], joint_position_tolerance_);
 
  919   EXPECT_NEAR(1.0, res_msg.trajectory.joint_trajectory.points[index].velocities[5], joint_velocity_tolerance_);
 
  920   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].accelerations[5], joint_acceleration_tolerance_);
 
  925   EXPECT_NEAR(2.875 / 2.0, res_msg.trajectory.joint_trajectory.points[index].positions[0], joint_position_tolerance_);
 
  926   EXPECT_NEAR(0.25, res_msg.trajectory.joint_trajectory.points[index].velocities[0], joint_velocity_tolerance_);
 
  927   EXPECT_NEAR(-0.5, res_msg.trajectory.joint_trajectory.points[index].accelerations[0], joint_acceleration_tolerance_);
 
  929   EXPECT_NEAR(-2.875 / 2.0, res_msg.trajectory.joint_trajectory.points[index].positions[1], joint_position_tolerance_);
 
  930   EXPECT_NEAR(-0.25, res_msg.trajectory.joint_trajectory.points[index].velocities[1], joint_velocity_tolerance_);
 
  931   EXPECT_NEAR(0.5, res_msg.trajectory.joint_trajectory.points[index].accelerations[1], joint_acceleration_tolerance_);
 
  933   EXPECT_NEAR(5.75 / 3.0 + 0.11, res_msg.trajectory.joint_trajectory.points[index].positions[2],
 
  934               joint_position_tolerance_);
 
  935   EXPECT_NEAR(1.0 / 3.0, res_msg.trajectory.joint_trajectory.points[index].velocities[2], joint_velocity_tolerance_);
 
  936   EXPECT_NEAR(-2.0 / 3.0, res_msg.trajectory.joint_trajectory.points[index].accelerations[2],
 
  937               joint_acceleration_tolerance_);
 
  939   EXPECT_NEAR(-5.75 / 3.0, res_msg.trajectory.joint_trajectory.points[index].positions[3], joint_position_tolerance_);
 
  940   EXPECT_NEAR(-1.0 / 3.0, res_msg.trajectory.joint_trajectory.points[index].velocities[3], joint_velocity_tolerance_);
 
  941   EXPECT_NEAR(2.0 / 3.0, res_msg.trajectory.joint_trajectory.points[index].accelerations[3],
 
  942               joint_acceleration_tolerance_);
 
  944   EXPECT_NEAR(2.875, res_msg.trajectory.joint_trajectory.points[index].positions[5], joint_position_tolerance_);
 
  945   EXPECT_NEAR(0.5, res_msg.trajectory.joint_trajectory.points[index].velocities[5], joint_velocity_tolerance_);
 
  946   EXPECT_NEAR(-1.0, res_msg.trajectory.joint_trajectory.points[index].accelerations[5], joint_acceleration_tolerance_);
 
  951   EXPECT_NEAR(1.5, res_msg.trajectory.joint_trajectory.points[index].positions[0], joint_position_tolerance_);
 
  952   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].velocities[0], joint_velocity_tolerance_);
 
  954   EXPECT_NEAR(-1.5, res_msg.trajectory.joint_trajectory.points[index].positions[1], joint_position_tolerance_);
 
  955   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].velocities[1], joint_velocity_tolerance_);
 
  957   EXPECT_NEAR(2.11, res_msg.trajectory.joint_trajectory.points[index].positions[2], joint_position_tolerance_);
 
  958   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].velocities[2], joint_velocity_tolerance_);
 
  960   EXPECT_NEAR(-2.0, res_msg.trajectory.joint_trajectory.points[index].positions[3], joint_position_tolerance_);
 
  961   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].velocities[3], joint_velocity_tolerance_);
 
  963   EXPECT_NEAR(3.0, res_msg.trajectory.joint_trajectory.points[index].positions[5], joint_position_tolerance_);
 
  964   EXPECT_NEAR(0.0, res_msg.trajectory.joint_trajectory.points[index].velocities[5], joint_velocity_tolerance_);
 
  967   EXPECT_NEAR(3.0, res_msg.trajectory.joint_trajectory.points[index].positions[5], joint_position_tolerance_);
 
  970   EXPECT_TRUE(std::all_of(res_msg.trajectory.joint_trajectory.points.back().velocities.cbegin(),
 
  971                           res_msg.trajectory.joint_trajectory.points.back().velocities.cend(),
 
  972                           [
this](
double v) { return std::fabs(v) < this->joint_velocity_tolerance_; }));
 
  975   EXPECT_TRUE(std::all_of(res_msg.trajectory.joint_trajectory.points.back().accelerations.cbegin(),
 
  976                           res_msg.trajectory.joint_trajectory.points.back().accelerations.cend(),
 
  977                           [
this](
double v) { return std::fabs(v) < this->joint_acceleration_tolerance_; }));
 
  980 int main(
int argc, 
char** argv)
 
  982   rclcpp::init(argc, argv);
 
  983   testing::InitGoogleTest(&argc, argv);
 
  984   return RUN_ALL_TESTS();
 
moveit::core::RobotModelConstPtr robot_model_
 
std::unique_ptr< robot_model_loader::RobotModelLoader > rm_loader_
 
LimitsContainer planner_limits_
 
rclcpp::Node::SharedPtr node_
 
bool checkTrajectory(const trajectory_msgs::msg::JointTrajectory &trajectory, const planning_interface::MotionPlanRequest &req, const JointLimitsContainer &joint_limits)
check the resulted joint trajectory
 
std::string planning_group_
 
planning_scene::PlanningSceneConstPtr planning_scene_
 
double joint_acceleration_tolerance_
 
std::unique_ptr< TrajectoryGenerator > ptp_
 
void SetUp() override
Create test fixture for ptp trajectory generator.
 
Representation of a robot's state. This includes position, velocity, acceleration and effort.
 
Container for JointLimits, essentially a map with convenience functions. Adds the ability to as for l...
 
bool addLimit(const std::string &joint_name, JointLimit joint_limit)
Add a limit.
 
This class combines CartesianLimit and JointLimits into on single class.
 
void setJointLimits(JointLimitsContainer &joint_limits)
Set joint limits.
 
This class implements a point-to-point trajectory generator based on VelocityProfileATrap.
 
Maintain a sequence of waypoints and the time durations between these waypoints.
 
moveit_msgs::msg::Constraints constructGoalConstraints(const moveit::core::RobotState &state, const moveit::core::JointModelGroup *jmg, double tolerance_below, double tolerance_above)
Generates a constraint message intended to be used as a goal constraint for a joint group....
 
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.
 
bool isVelocityBounded(const trajectory_msgs::msg::JointTrajectory &trajectory, const pilz_industrial_motion_planner::JointLimitsContainer &joint_limits)
is Velocity Bounded
 
void createDummyRequest(const moveit::core::RobotModelConstPtr &robot_model, const std::string &planning_group, planning_interface::MotionPlanRequest &req)
create a dummy motion plan request with zero start state No goal constraint is given.
 
int getWayPointIndex(const robot_trajectory::RobotTrajectoryPtr &trajectory, const double time_from_start)
get the waypoint index from time from start
 
bool isAccelerationBounded(const trajectory_msgs::msg::JointTrajectory &trajectory, const pilz_industrial_motion_planner::JointLimitsContainer &joint_limits)
is Acceleration Bounded
 
bool isTrajectoryConsistent(const trajectory_msgs::msg::JointTrajectory &trajectory)
check if the sizes of the joint position/veloicty/acceleration are correct
 
bool isPositionBounded(const trajectory_msgs::msg::JointTrajectory &trajectory, const pilz_industrial_motion_planner::JointLimitsContainer &joint_limits)
is Position Bounded
 
void checkRobotModel(const moveit::core::RobotModelConstPtr &robot_model, const std::string &group_name, const std::string &link_name)
 
bool has_acceleration_limits
 
Extends joint_limits_interface::JointLimits with a deceleration parameter.
 
bool has_deceleration_limits
 
double max_deceleration
maximum deceleration MUST(!) be negative
 
robot_trajectory::RobotTrajectoryPtr trajectory_
 
void getMessage(moveit_msgs::msg::MotionPlanResponse &msg) const
 
moveit_msgs::msg::MoveItErrorCodes error_code_
 
const std::string PARAM_PLANNING_GROUP_NAME("planning_group")
 
const std::string JOINT_POSITION_TOLERANCE("joint_position_tolerance")
 
int main(int argc, char **argv)
 
const std::string PARAM_TARGET_LINK_NAME("target_link")
 
const std::string JOINT_ACCELERATION_TOLERANCE("joint_acceleration_tolerance")
 
const std::string POSE_TRANSFORM_MATRIX_NORM_TOLERANCE("pose_norm_tolerance")
 
const std::string JOINT_VELOCITY_TOLERANCE("joint_velocity_tolerance")