pilz_command_planner.cpp
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 
19 
23 
26 
27 // Boost includes
28 #include <boost/scoped_ptr.hpp>
29 
31 
32 #include <pluginlib/class_loader.h>
33 
34 namespace pilz {
35 
36 static const std::string PARAM_NAMESPACE_LIMTS = "robot_description_planning";
37 
38 bool CommandPlanner::initialize(const moveit::core::RobotModelConstPtr &model, const std::string &ns)
39 {
40  // Call parent class initialize
42 
43  // Store the model and the namespace
44  model_ = model;
45  namespace_ = ns;
46 
47  // Obtain the aggregated joint limits
49  ros::NodeHandle(PARAM_NAMESPACE_LIMTS),model->getActiveJointModels());
50 
51  // Obtain cartesian limits
53 
54  // Load the planning context loader
55  planner_context_loader.reset(new pluginlib::ClassLoader<PlanningContextLoader>("pilz_trajectory_generation",
56  "pilz::PlanningContextLoader"));
57 
58  // List available plugins
59  const std::vector<std::string> &factories = planner_context_loader->getDeclaredClasses();
60  std::stringstream ss;
61  for (const auto& factory : factories)
62  {
63  ss << factory << " ";
64  }
65 
66  ROS_INFO_STREAM("Available plugins: " << ss.str());
67 
68  // Load each factory
69  for (const auto& factory : factories)
70  {
71 
72  ROS_INFO_STREAM("About to load: " << factory);
73  PlanningContextLoaderPtr loader_pointer(planner_context_loader->createInstance(factory));
74 
75  pilz::LimitsContainer limits;
77  limits.setCartesianLimits(cartesian_limit_);
78 
79  loader_pointer->setLimits(limits);
80  loader_pointer->setModel(model_);
81 
82  registerContextLoader(loader_pointer);
83 
84  }
85 
86  return true;
87 }
88 
89 std::string CommandPlanner::getDescription() const
90 {
91  return "Simple Command Planner";
92 }
93 
94 void CommandPlanner::getPlanningAlgorithms(std::vector<std::string> &algs) const
95 {
96  algs.clear();
97 
98  for(const auto& context_loader : context_loader_map_)
99  {
100  algs.push_back(context_loader.first);
101  }
102 }
103 
104 planning_interface::PlanningContextPtr CommandPlanner::getPlanningContext(
105  const planning_scene::PlanningSceneConstPtr& planning_scene,
106  const moveit_msgs::MotionPlanRequest& req,
107  moveit_msgs::MoveItErrorCodes& error_code) const
108 {
109  ROS_DEBUG_STREAM("Loading PlanningContext for request\n<request>\n" << req << "\n</request>");
110 
111  // Check that a loaded for this request exists
112  if(!canServiceRequest(req))
113  {
114  ROS_ERROR_STREAM("No ContextLoader for planner_id " << req.planner_id.c_str() << " found. Planning not possible.");
115  return nullptr;
116  }
117 
118  planning_interface::PlanningContextPtr planning_context;
119 
120  if(context_loader_map_.at(req.planner_id)->loadContext(planning_context, req.planner_id, req.group_name))
121  {
122  ROS_DEBUG_STREAM("Found planning context loader for " << req.planner_id << " group:" << req.group_name);
123  planning_context->setMotionPlanRequest(req);
124  planning_context->setPlanningScene(planning_scene);
125  return planning_context;
126  }
127  else {
128  error_code.val = moveit_msgs::MoveItErrorCodes::PLANNING_FAILED;
129  return nullptr;
130  }
131 
132 }
133 
134 bool CommandPlanner::canServiceRequest(const moveit_msgs::MotionPlanRequest& req) const
135 {
136  return context_loader_map_.find(req.planner_id) != context_loader_map_.end();
137 }
138 
140 {
141  // Only add if command is not already in list, throw exception if not
142  if(context_loader_map_.find(planning_context_loader->getAlgorithm()) == context_loader_map_.end())
143  {
144  context_loader_map_[planning_context_loader->getAlgorithm()] = planning_context_loader;
145  ROS_INFO_STREAM("Registered Algorithm [" << planning_context_loader->getAlgorithm() << "]");
146  }
147  else
148  {
149  throw ContextLoaderRegistrationException("The command [" + planning_context_loader->getAlgorithm()
150  + "] is already registered");
151  }
152 }
153 
154 } // namespace pilz
155 
std::map< std::string, pilz::PlanningContextLoaderPtr > context_loader_map_
Mapping from command to loader.
virtual planning_interface::PlanningContextPtr getPlanningContext(const planning_scene::PlanningSceneConstPtr &planning_scene, const planning_interface::MotionPlanRequest &req, moveit_msgs::MoveItErrorCodes &error_code) const override
Returns a PlanningContext that can be used to solve(calculate) the trajectory that corresponds to com...
pilz::CartesianLimit cartesian_limit_
cartesian limit
std::string namespace_
Namespace where the parameters are stored, obtained at initialize.
static JointLimitsContainer getAggregatedLimits(const ros::NodeHandle &nh, const std::vector< const moveit::core::JointModel * > &joint_models)
Aggregates(combines) the joint limits from joint model and parameter server. The rules for the combin...
static CartesianLimit getAggregatedLimits(const ros::NodeHandle &nh)
Loads cartesian limits from the parameter server.
PLUGINLIB_EXPORT_CLASS(cached_ik_kinematics_plugin::CachedIKKinematicsPlugin< kdl_kinematics_plugin::KDLKinematicsPlugin >, kinematics::KinematicsBase)
virtual void getPlanningAlgorithms(std::vector< std::string > &algs) const override
Returns the available planning commands.
pilz::JointLimitsContainer aggregated_limit_active_joints_
aggregated limits of the active joints
virtual bool initialize(const robot_model::RobotModelConstPtr &model, const std::string &ns)
virtual std::string getDescription() const override
Description of the planner.
This class combines CartesianLimit and JointLimits into on single class.
#define ROS_DEBUG_STREAM(args)
boost::scoped_ptr< pluginlib::ClassLoader< PlanningContextLoader > > planner_context_loader
Plugin loader.
Moveit Plugin for Planning with Standart Robot Commands This planner is dedicated to return a instanc...
#define ROS_INFO_STREAM(args)
moveit::core::RobotModelConstPtr model_
Robot model obtained at initialize.
#define ROS_ERROR_STREAM(args)
void registerContextLoader(const pilz::PlanningContextLoaderPtr &planning_context_loader)
Register a PlanningContextLoader to be used by the CommandPlanner.
virtual bool initialize(const robot_model::RobotModelConstPtr &model, const std::string &ns) override
Initializes the planner Upon initialization this planner will look for plugins implementing pilz::Pla...
virtual bool canServiceRequest(const planning_interface::MotionPlanRequest &req) const override
Checks if the request can be handled.
static const std::string PARAM_NAMESPACE_LIMTS
void setJointLimits(JointLimitsContainer &joint_limits)
Set joint limits.


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