stomp_planner_manager.cpp
Go to the documentation of this file.
1 
29 
30 namespace stomp_moveit
31 {
32 
34  planning_interface::PlannerManager(),
35  nh_("~")
36 {
37 
38 }
39 
40 StompPlannerManager::~StompPlannerManager()
41 {
42 
43 }
44 
45 bool StompPlannerManager::initialize(const robot_model::RobotModelConstPtr &model, const std::string &ns)
46 {
47  if (!ns.empty())
48  {
49  nh_ = ros::NodeHandle(ns);
50  }
51 
52  robot_model_ = model;
53 
54  // each element under 'stomp' should be a group name
55  std::map<std::string, XmlRpc::XmlRpcValue> group_config;
56 
57  if (!StompPlanner::getConfigData(nh_, group_config))
58  {
59  return false;
60  }
61 
62  for(std::map<std::string, XmlRpc::XmlRpcValue>::iterator v = group_config.begin(); v != group_config.end(); v++)
63  {
64  if(!model->hasJointModelGroup(v->first))
65  {
66  ROS_WARN("The robot model does not support the planning group '%s' in the STOMP configuration, skipping STOMP setup for this group",
67  v->first.c_str());
68  continue;
69  }
70 
71  std::shared_ptr<StompPlanner> planner(new StompPlanner(v->first, v->second, robot_model_));
72  planners_.insert(std::make_pair(v->first, planner));
73  }
74 
75  if(planners_.empty())
76  {
77  ROS_ERROR("All planning groups are invalid, STOMP could not be configured");
78  return false;
79  }
80 
81  return true;
82 }
83 
84 bool StompPlannerManager::canServiceRequest(const moveit_msgs::MotionPlanRequest &req) const
85 {
86  if(planners_.count(req.group_name) == 0)
87  {
88  return false;
89  }
90 
91  // Get planner
92  std::shared_ptr<StompPlanner> planner = std::static_pointer_cast<StompPlanner>(planners_.at(req.group_name));
93  return planner->canServiceRequest(req);
94 }
95 
96 void StompPlannerManager::getPlanningAlgorithms(std::vector<std::string> &algs) const
97 {
98  algs.clear();
99  if(!planners_.empty())
100  {
101  algs.push_back(planners_.begin()->second->getName());
102  }
103 }
104 
106 {
107  ROS_WARN_STREAM("The "<<__FUNCTION__<<" method is not applicable");
108 }
109 
110 planning_interface::PlanningContextPtr StompPlannerManager::getPlanningContext(const planning_scene::PlanningSceneConstPtr &planning_scene,
112  moveit_msgs::MoveItErrorCodes &error_code) const
113 {
114  error_code.val = moveit_msgs::MoveItErrorCodes::SUCCESS;
115 
116  if (req.group_name.empty())
117  {
118  ROS_ERROR("No group specified to plan for");
119  error_code.val = moveit_msgs::MoveItErrorCodes::INVALID_GROUP_NAME;
120  return planning_interface::PlanningContextPtr();
121  }
122 
123  if (!planning_scene)
124  {
125  ROS_ERROR("No planning scene supplied as input");
126  error_code.val = moveit_msgs::MoveItErrorCodes::FAILURE;
127  return planning_interface::PlanningContextPtr();
128  }
129 
130  if(planners_.count(req.group_name) <=0)
131  {
132  ROS_ERROR("STOMP does not have a planning context for group %s",req.group_name.c_str());
133  error_code.val = moveit_msgs::MoveItErrorCodes::FAILURE;
134  return planning_interface::PlanningContextPtr();
135  }
136 
137  // Get planner
138  std::shared_ptr<StompPlanner> planner = std::static_pointer_cast<StompPlanner>(planners_.at(req.group_name));
139 
140  if(!planner->canServiceRequest(req))
141  {
142  error_code.val = moveit_msgs::MoveItErrorCodes::FAILURE;
143  return planning_interface::PlanningContextPtr();
144  }
145 
146  // Setup Planner
147  planner->clear();
148  planner->setPlanningScene(planning_scene);
149  planner->setMotionPlanRequest(req);
150 
151  // Return Planner
152  return planner;
153 }
154 
155 
156 } /* namespace stomp_moveit_interface */
bool initialize(const robot_model::RobotModelConstPtr &model, const std::string &ns) override
Loads the ros parameters for each planning group and initializes the all the planners.
std::map< std::string, planning_interface::PlanningContextPtr > planners_
This defines the stomp planner for MoveIt.
std::map< std::string, PlannerConfigurationSettings > PlannerConfigurationMap
planning_interface::PlanningContextPtr getPlanningContext(const planning_scene::PlanningSceneConstPtr &planning_scene, const planning_interface::MotionPlanRequest &req, moveit_msgs::MoveItErrorCodes &error_code) const override
Provides a planning context that matches the desired plan requests specifications.
#define ROS_WARN(...)
The PlannerManager implementation that loads STOMP into moveit.
void setPlannerConfigurations(const planning_interface::PlannerConfigurationMap &pcs) override
Not applicable.
bool canServiceRequest(const moveit_msgs::MotionPlanRequest &req) const
Checks some conditions to determine whether it is able to plan given for this planning request...
void getPlanningAlgorithms(std::vector< std::string > &algs) const override
Getter for a list of the available planners, usually one STOMP planner per planning group...
bool canServiceRequest(const moveit_msgs::MotionPlanRequest &req) const override
Checks if the request can be planned for.
#define ROS_WARN_STREAM(args)
moveit_msgs::MotionPlanRequest MotionPlanRequest
This defines the stomp planning manager for MoveIt.
static bool getConfigData(ros::NodeHandle &nh, std::map< std::string, XmlRpc::XmlRpcValue > &config, std::string param=std::string("stomp"))
Convenience method to load extract the parameters for each supported planning group.
The PlanningContext specialization that wraps the STOMP algorithm.
Definition: stomp_planner.h:48
#define ROS_ERROR(...)
CLASS_LOADER_REGISTER_CLASS(Dog, Base)


stomp_moveit
Author(s): Jorge Nicho
autogenerated on Fri May 8 2020 03:35:47