35 throw TrajectoryGeneratorInvalidLimitsException(
"joint limit not set");
41 for(
const auto& jmg : robot_model->getJointModelGroups())
45 if(!most_strict_limit.has_velocity_limits)
48 throw TrajectoryGeneratorInvalidLimitsException(
"velocity limit not set for group " + jmg->getName());
50 if(!most_strict_limit.has_acceleration_limits)
53 throw TrajectoryGeneratorInvalidLimitsException(
"acceleration limit not set for group " + jmg->getName());
58 throw TrajectoryGeneratorInvalidLimitsException(
"deceleration limit not set for group " + jmg->getName());
61 most_strict_limits_.insert(std::pair<std::string, pilz_extensions::JointLimit>(jmg->getName(), most_strict_limit));
64 ROS_INFO(
"Initialized Point-to-Point Trajectory Generator.");
68 const std::map<std::string, double>& goal_pos,
69 trajectory_msgs::JointTrajectory &joint_trajectory,
70 const std::string &group_name,
71 const double &velocity_scaling_factor,
72 const double &acceleration_scaling_factor,
73 const double &sampling_time)
76 for(
const auto& item : goal_pos)
78 joint_trajectory.joint_names.push_back(item.first);
82 bool goal_reached =
true;
83 for(
auto const& goal: goal_pos)
85 if(fabs(start_pos.at(goal.first) - goal.second) >=
MIN_MOVEMENT )
93 ROS_INFO_STREAM(
"Goal already reached, set one goal point explicitly.");
94 if(joint_trajectory.points.empty())
96 trajectory_msgs::JointTrajectoryPoint point;
98 for(
const std::string & joint_name : joint_trajectory.joint_names)
100 point.positions.push_back(start_pos.at(joint_name));
101 point.velocities.push_back(0);
102 point.accelerations.push_back(0);
104 joint_trajectory.points.push_back(point);
110 std::string leading_axis = joint_trajectory.joint_names.front();
111 double max_duration = -1.0;
113 std::map<std::string, VelocityProfile_ATrap> velocity_profile;
114 for(
const auto& joint_name : joint_trajectory.joint_names)
117 velocity_profile.insert(std::make_pair(
124 velocity_profile.at(joint_name).SetProfile(start_pos.at(joint_name), goal_pos.at(joint_name));
125 if(velocity_profile.at(joint_name).Duration() > max_duration)
127 max_duration = velocity_profile.at(joint_name).Duration();
128 leading_axis = joint_name;
135 double acc_time = velocity_profile.at(leading_axis).FirstPhaseDuration();
136 double const_time = velocity_profile.at(leading_axis).SecondPhaseDuration();
137 double dec_time = velocity_profile.at(leading_axis).ThirdPhaseDuration();
139 for(
const auto& joint_name : joint_trajectory.joint_names)
141 if(joint_name != leading_axis)
146 if (!velocity_profile.at(joint_name).setProfileAllDurations(start_pos.at(joint_name), goal_pos.at(joint_name),
147 acc_time,const_time,dec_time))
150 std::stringstream error_str;
151 error_str <<
"TrajectoryGeneratorPTP::planPTP(): Can not synchronize velocity profile of axis " << joint_name
152 <<
" with leading axis " << leading_axis;
153 throw PtpVelocityProfileSyncFailed(error_str.str());
160 std::vector<double> time_samples;
161 for(
double t_sample=0.0; t_sample<max_duration; t_sample+=sampling_time)
163 time_samples.push_back(t_sample);
166 time_samples.push_back(max_duration);
169 for(
double time_stamp : time_samples)
171 trajectory_msgs::JointTrajectoryPoint point;
173 for(std::string & joint_name : joint_trajectory.joint_names)
175 point.positions.push_back(velocity_profile.at(joint_name).Pos(time_stamp));
176 point.velocities.push_back(velocity_profile.at(joint_name).Vel(time_stamp));
177 point.accelerations.push_back(velocity_profile.at(joint_name).Acc(time_stamp));
179 joint_trajectory.points.push_back(point);
183 std::fill(joint_trajectory.points.back().velocities.begin(),
184 joint_trajectory.points.back().velocities.end(),
186 std::fill(joint_trajectory.points.back().accelerations.begin(),
187 joint_trajectory.points.back().accelerations.end(),
199 for(std::size_t i=0; i<req.start_state.joint_state.name.size(); ++i)
201 info.
start_joint_position[req.start_state.joint_state.name[i]] = req.start_state.joint_state.position[i];
206 if(!req.goal_constraints.at(0).joint_constraints.empty())
208 for(
const auto& joint_constraint : req.goal_constraints.at(0).joint_constraints)
216 geometry_msgs::Point p = req.goal_constraints.at(0).position_constraints.at(0).
217 constraint_region.primitive_poses.at(0).position;
218 p.x -= req.goal_constraints.at(0).position_constraints.at(0).target_point_offset.x;
219 p.y -= req.goal_constraints.at(0).position_constraints.at(0).target_point_offset.y;
220 p.z -= req.goal_constraints.at(0).position_constraints.at(0).target_point_offset.z;
222 geometry_msgs::Pose pose;
224 pose.orientation = req.goal_constraints.at(0).orientation_constraints.at(0).orientation;
225 Eigen::Affine3d pose_eigen;
230 req.goal_constraints.at(0).position_constraints.at(0).link_name,
236 throw PtpNoIkSolutionForGoalPose(
"No IK solution for goal pose");
243 const double& sampling_time,
244 trajectory_msgs::JointTrajectory& joint_trajectory)
248 req.max_velocity_scaling_factor, req.max_acceleration_scaling_factor, sampling_time);
std::map< std::string, double > start_joint_position
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
std::map< std::string, pilz_extensions::JointLimit > most_strict_limits_
virtual void plan(const planning_interface::MotionPlanRequest &req, const MotionPlanInfo &plan_info, const double &sampling_time, trajectory_msgs::JointTrajectory &joint_trajectory) override
void poseMsgToEigen(const geometry_msgs::Pose &m, Eigen::Affine3d &e)
void planPTP(const std::map< std::string, double > &start_pos, const std::map< std::string, double > &goal_pos, trajectory_msgs::JointTrajectory &joint_trajectory, const std::string &group_name, const double &velocity_scaling_factor, const double &acceleration_scaling_factor, const double &sampling_time)
plan ptp joint trajectory with zero start velocity
bool has_deceleration_limits
TrajectoryGeneratorPTP(const robot_model::RobotModelConstPtr &robot_model, const pilz::LimitsContainer &planner_limits)
Constructor of PTP Trajectory Generator.
pilz::JointLimitsContainer joint_limits_
const robot_model::RobotModelConstPtr robot_model_
const double MIN_MOVEMENT
const pilz::LimitsContainer planner_limits_
const JointLimitsContainer & getJointLimitContainer() const
Obtain the Joint Limits from the container.
This class combines CartesianLimit and JointLimits into on single class.
virtual void extractMotionPlanInfo(const planning_interface::MotionPlanRequest &req, MotionPlanInfo &info) const override
Extract needed information from a motion plan request in order to simplify further usages...
pilz_extensions::JointLimit getCommonLimit() const
Returns joint limit fusion of all(position, velocity, acceleration, deceleration) limits for all join...
moveit_msgs::MotionPlanRequest MotionPlanRequest
#define ROS_INFO_STREAM(args)
This class is used to extract needed information from motion plan request.
#define ROS_ERROR_STREAM(args)
void normalizeQuaternion(geometry_msgs::Quaternion &quat)
A PTP Trajectory Generator of Asymmetric Trapezoidal Velocity Profile. Differences to VelocityProfile...
bool hasJointLimits() const
Return if this LimitsContainer has defined joint limits.