30 #include <kdl/path_line.hpp> 31 #include <kdl/utilities/error.h> 32 #include <kdl/trajectory_segment.hpp> 42 ROS_ERROR(
"Cartesian limits not set for LIN trajectory generator.");
43 throw TrajectoryGeneratorInvalidLimitsException(
"Cartesian limits are not fully set for LIN trajectory generator.");
49 ROS_DEBUG(
"Extract necessary information from motion plan request.");
55 if(!req.goal_constraints.front().joint_constraints.empty())
57 info.
link_name =
robot_model_->getJointModelGroup(req.group_name)->getSolverInstance()->getTipFrame();
59 if(req.goal_constraints.front().joint_constraints.size() !=
60 robot_model_->getJointModelGroup(req.group_name)->getActiveJointModelNames().size())
62 std::ostringstream os;
63 os <<
"Number of joints in goal does not match number of joints of group (Number joints goal: " 64 << req.goal_constraints.front().joint_constraints.size() <<
" | Number of joints of group: " 65 <<
robot_model_->getJointModelGroup(req.group_name)->getActiveJointModelNames().size() <<
")";
66 throw JointNumberMismatch(os.str());
69 for(
const auto &joint_item : req.goal_constraints.front().joint_constraints)
80 info.
link_name = req.goal_constraints.front().position_constraints.front().link_name;
81 if(req.goal_constraints.front().position_constraints.front().header.frame_id.empty() ||
82 req.goal_constraints.front().orientation_constraints.front().header.frame_id.empty())
84 ROS_WARN(
"Frame id is not set in position/orientation constraints of goal. Use model frame as default");
89 frame_id = req.goal_constraints.front().position_constraints.front().header.frame_id;
91 geometry_msgs::Pose goal_pose_msg;
92 goal_pose_msg.position = req.goal_constraints.front().position_constraints.front()
93 .constraint_region.primitive_poses.front().position;
94 goal_pose_msg.orientation = req.goal_constraints.front().orientation_constraints.front().orientation;
99 assert(req.start_state.joint_state.name.size() == req.start_state.joint_state.position.size());
100 for(
const auto& joint_name :
robot_model_->getJointModelGroup(req.group_name)->getActiveJointModelNames())
102 auto it {std::find(req.start_state.joint_state.name.cbegin(), req.start_state.joint_state.name.cend(), joint_name)};
103 if (it == req.start_state.joint_state.name.cend())
105 std::ostringstream os;
106 os <<
"Could not find joint \"" << joint_name <<
"\" of group \"" << req.group_name <<
"\" in start state of request";
107 throw LinJointMissingInStartState(os.str());
109 size_t index = it - req.start_state.joint_state.name.cbegin();
117 std::map<std::string, double> ik_solution;
126 std::ostringstream os;
127 os <<
"Failed to compute inverse kinematics for link: " << info.
link_name <<
" of goal pose";
128 throw LinInverseForGoalIncalculable(os.str());
134 const double& sampling_time,
135 trajectory_msgs::JointTrajectory& joint_trajectory)
141 std::unique_ptr<KDL::VelocityProfile> vp(
cartesianTrapVelocityProfile(req.max_velocity_scaling_factor, req.max_acceleration_scaling_factor, path));
148 moveit_msgs::MoveItErrorCodes error_code;
160 std::ostringstream os;
161 os <<
"Failed to generate valid joint trajectory from the Cartesian path";
162 throw LinTrajectoryConversionFailure(os.str(), error_code.val);
167 const Eigen::Affine3d& goal_pose)
const 169 ROS_DEBUG(
"Set Cartesian path for LIN command.");
178 return std::unique_ptr<KDL::Path>(
new KDL::Path_Line(kdl_start_pose,
std::map< std::string, double > start_joint_position
TrajectoryGeneratorLIN(const robot_model::RobotModelConstPtr &robot_model, const pilz::LimitsContainer &planner_limits)
Constructor of LIN Trajectory Generator.
std::map< std::string, double > goal_joint_position
Base class of trajectory generators.
bool computePoseIK(const robot_model::RobotModelConstPtr &robot_model, const std::string &group_name, const std::string &link_name, const Eigen::Affine3d &pose, const std::string &frame_id, const std::map< std::string, double > &seed, std::map< std::string, double > &solution, bool check_self_collision=true, int max_attempt=10, const double timeout=0.1)
compute the inverse kinematics of a given pose, also check robot self collision
double getMaxTranslationalVelocity() const
Return the maximal translational velocity [m/s], 0 if nothing was set.
void poseMsgToEigen(const geometry_msgs::Pose &m, Eigen::Affine3d &e)
Eigen::Affine3d goal_pose
const CartesianLimit & getCartesianLimits() const
Return the cartesian limits.
Eigen::Affine3d start_pose
void transformEigenToKDL(const Eigen::Affine3d &e, KDL::Frame &k)
const robot_model::RobotModelConstPtr robot_model_
virtual void plan(const planning_interface::MotionPlanRequest &req, const MotionPlanInfo &plan_info, const double &sampling_time, trajectory_msgs::JointTrajectory &joint_trajectory) override
std::unique_ptr< KDL::Path > setPathLIN(const Eigen::Affine3d &start_pose, const Eigen::Affine3d &goal_pose) const
construct a KDL::Path object for a Cartesian straight line
const pilz::LimitsContainer planner_limits_
bool computeLinkFK(const robot_model::RobotModelConstPtr &robot_model, const std::string &link_name, const std::map< std::string, double > &joint_state, Eigen::Affine3d &pose)
compute the pose of a link at give robot state
const JointLimitsContainer & getJointLimitContainer() const
Obtain the Joint Limits from the container.
double getMaxRotationalVelocity() const
Return the maximal rotational velocity [rad/s], 0 if nothing was set.
This class combines CartesianLimit and JointLimits into on single class.
moveit_msgs::MotionPlanRequest MotionPlanRequest
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
This class is used to extract needed information from motion plan request.
void normalizeQuaternion(geometry_msgs::Quaternion &quat)
bool generateJointTrajectory(const robot_model::RobotModelConstPtr &robot_model, 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::JointTrajectory &joint_trajectory, moveit_msgs::MoveItErrorCodes &error_code, bool check_self_collision=false)
Generate joint trajectory from a KDL Cartesian trajectory.
virtual void extractMotionPlanInfo(const planning_interface::MotionPlanRequest &req, MotionPlanInfo &info) const finaloverride
Extract needed information from a motion plan request in order to simplify further usages...
bool hasFullCartesianLimits() const
Return if this LimitsContainer has defined cartesian limits.