43 #include <kdl/path_line.hpp> 
   44 #include <kdl/trajectory_segment.hpp> 
   45 #include <kdl/utilities/error.h> 
   47 #if __has_include(<tf2/convert.hpp>) 
   48 #include <tf2/convert.hpp> 
   50 #include <tf2/convert.h> 
   52 #include <rclcpp/logger.hpp> 
   53 #include <rclcpp/logging.hpp> 
   54 #include <tf2_eigen/tf2_eigen.hpp> 
   55 #include <tf2_eigen_kdl/tf2_eigen_kdl.hpp> 
   56 #include <tf2_geometry_msgs/tf2_geometry_msgs.hpp> 
   60 static const rclcpp::Logger LOGGER =
 
   61     rclcpp::get_logger(
"moveit.pilz_industrial_motion_planner.trajectory_generator_lin");
 
   68     RCLCPP_ERROR(LOGGER, 
"Cartesian limits not set for LIN trajectory generator.");
 
   69     throw TrajectoryGeneratorInvalidLimitsException(
"Cartesian limits are not fully set for LIN trajectory generator.");
 
   73 void TrajectoryGeneratorLIN::extractMotionPlanInfo(
const planning_scene::PlanningSceneConstPtr& 
scene,
 
   77   RCLCPP_DEBUG(LOGGER, 
"Extract necessary information from motion plan request.");
 
   83   if (!req.goal_constraints.front().joint_constraints.empty())
 
   87     if (req.goal_constraints.front().joint_constraints.size() !=
 
   88         robot_model_->getJointModelGroup(req.group_name)->getActiveJointModelNames().size())
 
   90       std::ostringstream os;
 
   91       os << 
"Number of joints in goal does not match number of joints of group " 
   92             "(Number joints goal: " 
   93          << req.goal_constraints.front().joint_constraints.size() << 
" | Number of joints of group: " 
   94          << 
robot_model_->getJointModelGroup(req.group_name)->getActiveJointModelNames().size() << 
")";
 
   95       throw JointNumberMismatch(os.str());
 
   98     for (
const auto& joint_item : req.goal_constraints.front().joint_constraints)
 
  110     info.
link_name = req.goal_constraints.front().position_constraints.front().link_name;
 
  111     if (req.goal_constraints.front().position_constraints.front().header.frame_id.empty() ||
 
  112         req.goal_constraints.front().orientation_constraints.front().header.frame_id.empty())
 
  114       RCLCPP_WARN(LOGGER, 
"Frame id is not set in position/orientation constraints of " 
  115                           "goal. Use model frame as default");
 
  120       frame_id = req.goal_constraints.front().position_constraints.front().header.frame_id;
 
  128     std::map<std::string, double> ik_solution;
 
  132       std::ostringstream os;
 
  133       os << 
"Failed to compute inverse kinematics for link: " << info.
link_name << 
" of goal pose";
 
  134       throw LinInverseForGoalIncalculable(os.str());
 
  143 void TrajectoryGeneratorLIN::plan(
const planning_scene::PlanningSceneConstPtr& 
scene,
 
  145                                   const double& sampling_time, trajectory_msgs::msg::JointTrajectory& joint_trajectory)
 
  148   std::unique_ptr<KDL::Path> path(setPathLIN(plan_info.start_pose, plan_info.goal_pose));
 
  151   std::unique_ptr<KDL::VelocityProfile> vp(
 
  158   KDL::Trajectory_Segment cart_trajectory(path.get(), vp.get(), 
false);
 
  160   moveit_msgs::msg::MoveItErrorCodes error_code;
 
  164                                plan_info.link_name, plan_info.start_joint_position, sampling_time, joint_trajectory,
 
  167     std::ostringstream os;
 
  168     os << 
"Failed to generate valid joint trajectory from the Cartesian path";
 
  169     throw LinTrajectoryConversionFailure(os.str(), error_code.val);
 
  173 std::unique_ptr<KDL::Path> TrajectoryGeneratorLIN::setPathLIN(
const Eigen::Affine3d& start_pose,
 
  174                                                               const Eigen::Affine3d& goal_pose)
 const 
  176   RCLCPP_DEBUG(LOGGER, 
"Set Cartesian path for LIN command.");
 
  178   KDL::Frame kdl_start_pose, kdl_goal_pose;
 
  179   tf2::transformEigenToKDL(start_pose, kdl_start_pose);
 
  180   tf2::transformEigenToKDL(goal_pose, kdl_goal_pose);
 
  183   KDL::RotationalInterpolation* rot_interpo = 
new KDL::RotationalInterpolation_SingleAxis();
 
  185   return std::unique_ptr<KDL::Path>(
 
  186       std::make_unique<KDL::Path_Line>(kdl_start_pose, kdl_goal_pose, rot_interpo, eqradius, 
true));
 
Representation of a robot's state. This includes position, velocity, acceleration and effort.
 
double getMaxRotationalVelocity() const
Return the maximal rotational velocity [rad/s], 0 if nothing was set.
 
double getMaxTranslationalVelocity() const
Return the maximal translational velocity [m/s], 0 if nothing was set.
 
This class combines CartesianLimit and JointLimits into on single class.
 
bool hasFullCartesianLimits() const
Return if this LimitsContainer has defined cartesian limits.
 
const JointLimitsContainer & getJointLimitContainer() const
Obtain the Joint Limits from the container.
 
const CartesianLimit & getCartesianLimits() const
Return the cartesian limits.
 
TrajectoryGeneratorLIN(const moveit::core::RobotModelConstPtr &robot_model, const pilz_industrial_motion_planner::LimitsContainer &planner_limits, const std::string &group_name)
Constructor of LIN Trajectory Generator.
 
This class is used to extract needed information from motion plan request.
 
std::map< std::string, double > goal_joint_position
 
Eigen::Isometry3d start_pose
 
Eigen::Isometry3d goal_pose
 
std::map< std::string, double > start_joint_position
 
Base class of trajectory generators.
 
const moveit::core::RobotModelConstPtr robot_model_
 
std::unique_ptr< KDL::VelocityProfile > cartesianTrapVelocityProfile(const double &max_velocity_scaling_factor, const double &max_acceleration_scaling_factor, const std::unique_ptr< KDL::Path > &path) const
build cartesian velocity profile for the path
 
const pilz_industrial_motion_planner::LimitsContainer planner_limits_
 
bool computeLinkFK(moveit::core::RobotState &robot_state, const std::string &link_name, const std::map< std::string, double > &joint_state, Eigen::Isometry3d &pose)
compute the pose of a link at a given robot state
 
bool generateJointTrajectory(const planning_scene::PlanningSceneConstPtr &scene, const JointLimitsContainer &joint_limits, const KDL::Trajectory &trajectory, const std::string &group_name, const std::string &link_name, const std::map< std::string, double > &initial_joint_position, const double &sampling_time, trajectory_msgs::msg::JointTrajectory &joint_trajectory, moveit_msgs::msg::MoveItErrorCodes &error_code, bool check_self_collision=false)
Generate joint trajectory from a KDL Cartesian trajectory.
 
bool computePoseIK(const planning_scene::PlanningSceneConstPtr &scene, const std::string &group_name, const std::string &link_name, const Eigen::Isometry3d &pose, const std::string &frame_id, const std::map< std::string, double > &seed, std::map< std::string, double > &solution, bool check_self_collision=true, const double timeout=0.0)
compute the inverse kinematics of a given pose, also check robot self collision
 
moveit_msgs::msg::MotionPlanRequest MotionPlanRequest
 
Eigen::Isometry3d getConstraintPose(const geometry_msgs::msg::Point &position, const geometry_msgs::msg::Quaternion &orientation, const geometry_msgs::msg::Vector3 &offset)
Adapt goal pose, defined by position+orientation, to consider offset.