moveit2
The MoveIt Motion Planning Framework for ROS 2.
Loading...
Searching...
No Matches
planning_context_base.hpp
Go to the documentation of this file.
1/*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2018 Pilz GmbH & Co. KG
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of Pilz GmbH & Co. KG nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34
35#pragma once
36
39
40#include <rclcpp/rclcpp.hpp>
41
46
47#include <atomic>
48#include <thread>
49
51{
55template <typename GeneratorT>
57{
58public:
59 PlanningContextBase(const std::string& name, const std::string& group, const moveit::core::RobotModelConstPtr& model,
62 , terminated_(false)
63 , model_(model)
64 , limits_(limits)
65 , generator_(model, limits_, group)
66 {
67 }
68
70 {
71 }
72
81
92
98 bool terminate() override;
99
103 void clear() override;
104
106 std::atomic_bool terminated_;
107
109 moveit::core::RobotModelConstPtr model_;
110
113
114protected:
115 GeneratorT generator_;
116};
117
118template <typename GeneratorT>
120{
121 if (terminated_)
122 {
123 RCLCPP_ERROR(rclcpp::get_logger("moveit.pilz_industrial_motion_planner.planning_context_base"),
124 "Using solve on a terminated planning context!");
125 res.error_code.val = moveit_msgs::msg::MoveItErrorCodes::PLANNING_FAILED;
126 return;
127 }
128 generator_.generate(getPlanningScene(), request_, res);
129}
130
131template <typename GeneratorT>
134{
135 // delegate to regular response
136 planning_interface::MotionPlanResponse undetailed_response;
137 solve(undetailed_response);
138
139 res.description.push_back("plan");
140 res.trajectory.push_back(undetailed_response.trajectory);
141 res.processing_time.push_back(undetailed_response.planning_time);
142
143 res.description.push_back("simplify");
144 res.trajectory.push_back(undetailed_response.trajectory);
145 res.processing_time.push_back(0);
146
147 res.description.push_back("interpolate");
148 res.trajectory.push_back(undetailed_response.trajectory);
149 res.processing_time.push_back(0);
150
151 res.error_code = undetailed_response.error_code;
152}
153
154template <typename GeneratorT>
156{
157 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("moveit.pilz_industrial_motion_planner.planning_context_base"),
158 "Terminate called");
159 terminated_ = true;
160 return true;
161}
162
163template <typename GeneratorT>
165{
166 // No structures that need cleaning
167 return;
168}
169
170} // namespace pilz_industrial_motion_planner
This class combines CartesianLimit and JointLimits into on single class.
void solve(planning_interface::MotionPlanResponse &res) override
Calculates a trajectory for the request this context is currently set for.
pilz_industrial_motion_planner::LimitsContainer limits_
Joint limits to be used during planning.
void clear() override
Clear the data structures used by the planner.
moveit::core::RobotModelConstPtr model_
The robot model.
PlanningContextBase(const std::string &name, const std::string &group, const moveit::core::RobotModelConstPtr &model, const pilz_industrial_motion_planner::LimitsContainer &limits)
Representation of a particular planning context – the planning scene and the request are known,...
MotionPlanRequest request_
The planning request for this context.
const planning_scene::PlanningSceneConstPtr & getPlanningScene() const
Get the planning scene associated to this planning context.
PlanningContext(const std::string &name, const std::string &group)
Construct a planning context named name for the group group.
This namespace includes the base class for MoveIt planners.
moveit_msgs::msg::MoveItErrorCodes error_code
std::vector< robot_trajectory::RobotTrajectoryPtr > trajectory
moveit::core::MoveItErrorCode error_code
robot_trajectory::RobotTrajectoryPtr trajectory