37 #include <rclcpp/logger.hpp>
38 #include <rclcpp/logging.hpp>
47 #include "cartesian_limits_parameters.hpp"
65 const moveit::core::RobotModelConstPtr& model)
66 : node_(node), model_(model)
76 params_ = param_listener_->get_params();
83 plan_comp_builder_.
setBlender(std::unique_ptr<pilz_industrial_motion_planner::TrajectoryBlender>(
89 const moveit_msgs::msg::MotionSequenceRequest& req_list)
91 if (req_list.items.empty())
96 checkForNegativeRadii(req_list);
97 checkLastBlendRadiusZero(req_list);
98 checkStartStates(req_list);
103 RadiiCont radii{ extractBlendRadii(*model_, req_list) };
104 checkForOverlappingRadii(resp_cont, radii);
106 plan_comp_builder_.
reset();
107 for (MotionResponseCont::size_type i = 0; i < resp_cont.size(); ++i)
113 (i > 0 ? radii.at(i - 1) : 0.));
115 return plan_comp_builder_.
build();
120 const double radii_B)
const
128 auto sum_radii{ radii_A + radii_B };
134 const std::string& blend_frame{ getSolverTipFrame(model_->getJointModelGroup(traj_A.
getGroupName())) };
138 return distance_endpoints <= sum_radii;
141 void CommandListManager::checkForOverlappingRadii(
const MotionResponseCont& resp_cont,
const RadiiCont& radii)
const
143 if (resp_cont.empty())
147 if (resp_cont.size() < 3)
152 for (MotionResponseCont::size_type i = 0; i < resp_cont.size() - 2; ++i)
154 if (checkRadiiForOverlap(*(resp_cont.at(i).trajectory), radii.at(i), *(resp_cont.at(i + 1).trajectory),
157 std::ostringstream os;
158 os <<
"Overlapping blend radii between command [" << i <<
"] and [" << i + 1 <<
"].";
159 throw OverlappingBlendRadiiException(os.str());
164 CommandListManager::RobotState_OptRef
165 CommandListManager::getPreviousEndState(
const MotionResponseCont& motion_plan_responses,
const std::string& group_name)
167 for (MotionResponseCont::const_reverse_iterator it = motion_plan_responses.crbegin();
168 it != motion_plan_responses.crend(); ++it)
170 if (it->trajectory->getGroupName() == group_name)
172 return std::reference_wrapper(it->trajectory->getLastWayPoint());
178 void CommandListManager::setStartState(
const MotionResponseCont& motion_plan_responses,
const std::string& group_name,
179 moveit_msgs::msg::RobotState& start_state)
181 RobotState_OptRef rob_state_op{ getPreviousEndState(motion_plan_responses, group_name) };
189 const moveit_msgs::msg::MotionSequenceItem& item_A,
190 const moveit_msgs::msg::MotionSequenceItem& item_B)
193 if (item_A.blend_radius == 0.)
199 if (item_A.req.group_name != item_B.req.group_name)
201 RCLCPP_WARN_STREAM(
getLogger(),
"Blending between different groups (in this case: \""
202 << item_A.req.group_name <<
"\" and \"" << item_B.req.group_name
203 <<
"\") not allowed");
210 RCLCPP_WARN_STREAM(
getLogger(),
"Blending for groups without solver not allowed");
217 CommandListManager::RadiiCont
219 const moveit_msgs::msg::MotionSequenceRequest& req_list)
221 RadiiCont radii(req_list.items.size(), 0.);
222 for (RadiiCont::size_type i = 0; i < (radii.size() - 1); ++i)
224 if (isInvalidBlendRadii(model, req_list.items.at(i), req_list.items.at(i + 1)))
226 RCLCPP_WARN_STREAM(
getLogger(),
"Invalid blend radii between commands: [" << i <<
"] and [" << i + 1
227 <<
"] => Blend radii set to zero");
230 radii.at(i) = req_list.items.at(i).blend_radius;
235 CommandListManager::MotionResponseCont
236 CommandListManager::solveSequenceItems(
const planning_scene::PlanningSceneConstPtr&
planning_scene,
238 const moveit_msgs::msg::MotionSequenceRequest& req_list)
const
240 MotionResponseCont motion_plan_responses;
241 size_t curr_req_index{ 0 };
242 const size_t num_req{ req_list.items.size() };
243 for (
const auto& seq_item : req_list.items)
246 setStartState(motion_plan_responses, req.group_name, req.start_state);
251 RCLCPP_ERROR(
getLogger(),
"Generating a plan with planning pipeline failed.");
252 res.
error_code.val = moveit_msgs::msg::MoveItErrorCodes::FAILURE;
256 std::ostringstream os;
257 os <<
"Could not solve request\n";
258 throw PlanningPipelineException(os.str(), res.
error_code.val);
260 motion_plan_responses.emplace_back(res);
261 RCLCPP_DEBUG_STREAM(
getLogger(),
"Solved [" << ++curr_req_index <<
'/' << num_req <<
']');
263 return motion_plan_responses;
266 void CommandListManager::checkForNegativeRadii(
const moveit_msgs::msg::MotionSequenceRequest& req_list)
268 if (!std::all_of(req_list.items.begin(), req_list.items.end(),
269 [](
const moveit_msgs::msg::MotionSequenceItem& req) { return (req.blend_radius >= 0.); }))
271 throw NegativeBlendRadiusException(
"All blending radii MUST be non negative");
275 void CommandListManager::checkStartStatesOfGroup(
const moveit_msgs::msg::MotionSequenceRequest& req_list,
276 const std::string& group_name)
278 bool first_elem{
true };
279 for (
const moveit_msgs::msg::MotionSequenceItem& item : req_list.items)
281 if (item.req.group_name != group_name)
292 if (!(item.req.start_state.joint_state.position.empty() && item.req.start_state.joint_state.velocity.empty() &&
293 item.req.start_state.joint_state.effort.empty() && item.req.start_state.joint_state.name.empty()))
295 std::ostringstream os;
296 os <<
"Only the first request is allowed to have a start state, but"
297 <<
" the requests for group: \"" << group_name <<
"\" violate the rule";
298 throw StartStateSetException(os.str());
303 void CommandListManager::checkStartStates(
const moveit_msgs::msg::MotionSequenceRequest& req_list)
305 if (req_list.items.size() <= 1)
310 GroupNamesCont group_names{ getGroupNames(req_list) };
311 for (
const auto& curr_group_name : group_names)
313 checkStartStatesOfGroup(req_list, curr_group_name);
317 CommandListManager::GroupNamesCont
318 CommandListManager::getGroupNames(
const moveit_msgs::msg::MotionSequenceRequest& req_list)
320 GroupNamesCont group_names;
321 std::for_each(req_list.items.cbegin(), req_list.items.cend(),
322 [&group_names](
const moveit_msgs::msg::MotionSequenceItem& item) {
323 if (std::find(group_names.cbegin(), group_names.cend(), item.req.group_name) == group_names.cend())
325 group_names.emplace_back(item.req.group_name);
Definition of a kinematic model. This class is not thread safe, however multiple instances can be cre...
const JointModelGroup * getJointModelGroup(const std::string &name) const
Get a joint group from this model (by name)
const Eigen::Isometry3d & getFrameTransform(const std::string &frame_id, bool *frame_found=nullptr)
Get the transformation matrix from the model frame (root of model) to the frame identified by frame_i...
CommandListManager(const rclcpp::Node::SharedPtr &node, const moveit::core::RobotModelConstPtr &model)
RobotTrajCont solve(const planning_scene::PlanningSceneConstPtr &planning_scene, const planning_pipeline::PlanningPipelinePtr &planning_pipeline, const moveit_msgs::msg::MotionSequenceRequest &req_list)
Generates trajectories for the specified list of motion commands.
static JointLimitsContainer getAggregatedLimits(const rclcpp::Node::SharedPtr &node, const std::string ¶m_namespace, const std::vector< const moveit::core::JointModel * > &joint_models)
Aggregates(combines) the joint limits from joint model and node parameters. The rules for the combina...
Container for JointLimits, essentially a map with convenience functions. Adds the ability to as for l...
This class combines CartesianLimit and JointLimits into on single class.
void setCartesianLimits(cartesian_limits::Params &cartesian_limit)
Set cartesian limits.
void setJointLimits(JointLimitsContainer &joint_limits)
Set joint limits.
std::vector< robot_trajectory::RobotTrajectoryPtr > build() const
void reset()
Clears the trajectory container under construction.
void setModel(const moveit::core::RobotModelConstPtr &model)
Sets the robot model needed to create new trajectory elements.
void setBlender(std::unique_ptr< pilz_industrial_motion_planner::TrajectoryBlender > blender)
Sets the blender used to blend two trajectories.
void append(const planning_scene::PlanningSceneConstPtr &planning_scene, const robot_trajectory::RobotTrajectoryPtr &other, const double blend_radius)
Appends the specified trajectory to the trajectory container under construction.
Trajectory blender implementing transition window algorithm.
Maintain a sequence of waypoints and the time durations between these waypoints.
const std::string & getGroupName() const
const moveit::core::RobotState & getLastWayPoint() const
rclcpp::Logger getLogger()
void robotStateToRobotStateMsg(const RobotState &state, moveit_msgs::msg::RobotState &robot_state, bool copy_attached_bodies=true)
Convert a MoveIt robot state to a robot state message.
rclcpp::Logger getLogger(const std::string &name)
Creates a namespaced logger.
std::vector< robot_trajectory::RobotTrajectoryPtr > RobotTrajCont
moveit_msgs::msg::MotionPlanRequest MotionPlanRequest
This namespace includes the central class for representing planning contexts.
Response to a planning query.
moveit::core::MoveItErrorCode error_code
const std::string PARAM_NAMESPACE_LIMITS