trajectory_generator.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Pilz GmbH & Co. KG
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13 
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef TRAJECTORYGENERATOR_H
19 #define TRAJECTORYGENERATOR_H
20 
21 #include <string>
22 #include <sstream>
23 
26 #include <Eigen/Geometry>
27 #include <kdl/frames.hpp>
28 #include <kdl/trajectory.hpp>
29 
34 
35 using namespace pilz_trajectory_generation;
36 
37 namespace pilz
38 {
39 
40 CREATE_MOVEIT_ERROR_CODE_EXCEPTION(TrajectoryGeneratorInvalidLimitsException, moveit_msgs::MoveItErrorCodes::FAILURE);
41 
42 CREATE_MOVEIT_ERROR_CODE_EXCEPTION(VelocityScalingIncorrect, moveit_msgs::MoveItErrorCodes::INVALID_MOTION_PLAN);
43 CREATE_MOVEIT_ERROR_CODE_EXCEPTION(AccelerationScalingIncorrect, moveit_msgs::MoveItErrorCodes::INVALID_MOTION_PLAN);
44 CREATE_MOVEIT_ERROR_CODE_EXCEPTION(UnknownPlanningGroup, moveit_msgs::MoveItErrorCodes::INVALID_GROUP_NAME);
45 
46 CREATE_MOVEIT_ERROR_CODE_EXCEPTION(NoJointNamesInStartState, moveit_msgs::MoveItErrorCodes::INVALID_ROBOT_STATE);
47 CREATE_MOVEIT_ERROR_CODE_EXCEPTION(SizeMismatchInStartState, moveit_msgs::MoveItErrorCodes::INVALID_ROBOT_STATE);
48 CREATE_MOVEIT_ERROR_CODE_EXCEPTION(JointsOfStartStateOutOfRange, moveit_msgs::MoveItErrorCodes::INVALID_ROBOT_STATE);
49 CREATE_MOVEIT_ERROR_CODE_EXCEPTION(NonZeroVelocityInStartState, moveit_msgs::MoveItErrorCodes::INVALID_ROBOT_STATE);
50 
51 CREATE_MOVEIT_ERROR_CODE_EXCEPTION(NotExactlyOneGoalConstraintGiven, moveit_msgs::MoveItErrorCodes::INVALID_GOAL_CONSTRAINTS);
52 CREATE_MOVEIT_ERROR_CODE_EXCEPTION(OnlyOneGoalTypeAllowed, moveit_msgs::MoveItErrorCodes::INVALID_GOAL_CONSTRAINTS);
53 
54 CREATE_MOVEIT_ERROR_CODE_EXCEPTION(StartStateGoalStateMismatch, moveit_msgs::MoveItErrorCodes::INVALID_GOAL_CONSTRAINTS);
55 CREATE_MOVEIT_ERROR_CODE_EXCEPTION(JointConstraintDoesNotBelongToGroup, moveit_msgs::MoveItErrorCodes::INVALID_GOAL_CONSTRAINTS);
56 CREATE_MOVEIT_ERROR_CODE_EXCEPTION(JointsOfGoalOutOfRange, moveit_msgs::MoveItErrorCodes::INVALID_GOAL_CONSTRAINTS);
57 
58 CREATE_MOVEIT_ERROR_CODE_EXCEPTION(PositionConstraintNameMissing, moveit_msgs::MoveItErrorCodes::INVALID_GOAL_CONSTRAINTS);
59 CREATE_MOVEIT_ERROR_CODE_EXCEPTION(OrientationConstraintNameMissing, moveit_msgs::MoveItErrorCodes::INVALID_GOAL_CONSTRAINTS);
60 CREATE_MOVEIT_ERROR_CODE_EXCEPTION(PositionOrientationConstraintNameMismatch, moveit_msgs::MoveItErrorCodes::INVALID_GOAL_CONSTRAINTS);
61 CREATE_MOVEIT_ERROR_CODE_EXCEPTION(NoIKSolverAvailable, moveit_msgs::MoveItErrorCodes::NO_IK_SOLUTION);
62 CREATE_MOVEIT_ERROR_CODE_EXCEPTION(NoPrimitivePoseGiven, moveit_msgs::MoveItErrorCodes::INVALID_GOAL_CONSTRAINTS);
63 
70 {
71 public:
72 
73  TrajectoryGenerator(const robot_model::RobotModelConstPtr& robot_model,
74  const pilz::LimitsContainer& planner_limits)
75  :robot_model_(robot_model),
76  planner_limits_(planner_limits)
77  {
78  }
79 
80  virtual ~TrajectoryGenerator() = default;
81 
91  double sampling_time=0.1);
92 
93 protected:
98  {
99  public:
100  std::string group_name;
101  std::string link_name;
102  Eigen::Affine3d start_pose;
103  Eigen::Affine3d goal_pose;
104  std::map<std::string, double> start_joint_position;
105  std::map<std::string, double> goal_joint_position;
106  std::pair<std::string, Eigen::Vector3d> circ_path_point;
107  };
108 
115  std::unique_ptr<KDL::VelocityProfile> cartesianTrapVelocityProfile(
116  const double& max_velocity_scaling_factor,
117  const double& max_acceleration_scaling_factor,
118  const std::unique_ptr<KDL::Path> &path) const;
119 
120 private:
121  virtual void cmdSpecificRequestValidation(const planning_interface::MotionPlanRequest &req) const;
122 
129  virtual void extractMotionPlanInfo(const planning_interface::MotionPlanRequest& req,
130  MotionPlanInfo& info) const = 0;
131 
132  virtual void plan(const planning_interface::MotionPlanRequest &req,
133  const MotionPlanInfo& plan_info,
134  const double& sampling_time,
135  trajectory_msgs::JointTrajectory& joint_trajectory) = 0;
136 
137 private:
160  void validateRequest(const planning_interface::MotionPlanRequest& req) const;
161 
165  void setSuccessResponse(const std::string& group_name,
166  const moveit_msgs::RobotState& start_state,
167  const trajectory_msgs::JointTrajectory& joint_trajectory,
168  const ros::Time &planning_start,
170 
171  void setFailureResponse(const ros::Time &planning_start,
173 
174  void checkForValidGroupName(const std::string& group_name) const;
175 
185  void checkStartState(const moveit_msgs::RobotState &start_state) const;
186 
187  void checkGoalConstraints(const moveit_msgs::MotionPlanRequest::_goal_constraints_type &goal_constraints,
188  const std::vector<std::string> &expected_joint_names,
189  const std::string &group_name) const;
190 
191  void checkJointGoalConstraint(const moveit_msgs::Constraints& constraint,
192  const std::vector<std::string>& expected_joint_names,
193  const std::string &group_name) const;
194 
195  void checkCartesianGoalConstraint(const moveit_msgs::Constraints& constraint,
196  const std::string &group_name) const;
197 
198  void convertToRobotTrajectory(const trajectory_msgs::JointTrajectory& joint_trajectory,
199  const moveit_msgs::RobotState &start_state,
201 
202 private:
206  static bool isScalingFactorValid(const double& scaling_factor);
207  static void checkVelocityScaling(const double& scaling_factor);
208  static void checkAccelerationScaling(const double& scaling_factor);
209 
214  static bool isCartesianGoalGiven(const moveit_msgs::Constraints& constraint);
215 
219  static bool isJointGoalGiven(const moveit_msgs::Constraints& constraint);
220 
225  static bool isOnlyOneGoalTypeGiven(const moveit_msgs::Constraints& constraint);
226 
227 protected:
228  const robot_model::RobotModelConstPtr robot_model_;
230  static constexpr double MIN_SCALING_FACTOR {0.0001};
231  static constexpr double MAX_SCALING_FACTOR {1.};
232  static constexpr double VELOCITY_TOLERANCE {1e-8};
233 };
234 
235 inline bool TrajectoryGenerator::isScalingFactorValid(const double& scaling_factor)
236 {
237  return (scaling_factor > MIN_SCALING_FACTOR && scaling_factor <= MAX_SCALING_FACTOR);
238 }
239 
240 inline bool TrajectoryGenerator::isCartesianGoalGiven(const moveit_msgs::Constraints &constraint)
241 {
242  return constraint.position_constraints.size() == 1 && constraint.orientation_constraints.size() == 1;
243 }
244 
245 inline bool TrajectoryGenerator::isJointGoalGiven(const moveit_msgs::Constraints& constraint)
246 {
247  return constraint.joint_constraints.size() >= 1;
248 }
249 
250 inline bool TrajectoryGenerator::isOnlyOneGoalTypeGiven(const moveit_msgs::Constraints& constraint)
251 {
252  return (isJointGoalGiven(constraint) && !isCartesianGoalGiven(constraint))
253  || (!isJointGoalGiven(constraint) && isCartesianGoalGiven(constraint));
254 }
255 
256 }
257 #endif // TRAJECTORYGENERATOR_H
std::map< std::string, double > start_joint_position
std::map< std::string, double > goal_joint_position
Base class of trajectory generators.
def generate(srv_path)
const robot_model::RobotModelConstPtr robot_model_
std::pair< std::string, Eigen::Vector3d > circ_path_point
const pilz::LimitsContainer planner_limits_
CREATE_MOVEIT_ERROR_CODE_EXCEPTION(NegativeBlendRadiusException, moveit_msgs::MoveItErrorCodes::INVALID_MOTION_PLAN)
This class combines CartesianLimit and JointLimits into on single class.
moveit_msgs::MotionPlanRequest MotionPlanRequest
res
This class is used to extract needed information from motion plan request.
TrajectoryGenerator(const robot_model::RobotModelConstPtr &robot_model, const pilz::LimitsContainer &planner_limits)


pilz_trajectory_generation
Author(s):
autogenerated on Mon Apr 6 2020 03:17:33