chomp_plugin.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011, Willow Garage, Inc.
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 Willow Garage 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 #include <memory>
36 
42 
44 
45 namespace chomp_interface
46 {
47 class CHOMPPlannerManager : public planning_interface::PlannerManager
48 {
49 public:
51  {
52  }
53 
54  bool initialize(const moveit::core::RobotModelConstPtr& model, const std::string& ns) override
55  {
56  ros::NodeHandle nh("~");
57  if (!ns.empty())
58  nh = ros::NodeHandle(ns);
59 
60  for (const std::string& group : model->getJointModelGroupNames())
61  {
62  planning_contexts_[group] = std::make_shared<CHOMPPlanningContext>("chomp_planning_context", group, model, nh);
63  }
64  return true;
65  }
66 
67  planning_interface::PlanningContextPtr getPlanningContext(const planning_scene::PlanningSceneConstPtr& planning_scene,
69  moveit_msgs::MoveItErrorCodes& error_code) const override
70  {
71  error_code.val = moveit_msgs::MoveItErrorCodes::SUCCESS;
72 
73  if (req.group_name.empty())
74  {
75  ROS_ERROR("No group specified to plan for");
76  error_code.val = moveit_msgs::MoveItErrorCodes::INVALID_GROUP_NAME;
77  return planning_interface::PlanningContextPtr();
78  }
79 
80  if (!planning_scene)
81  {
82  ROS_ERROR("No planning scene supplied as input");
83  error_code.val = moveit_msgs::MoveItErrorCodes::FAILURE;
84  return planning_interface::PlanningContextPtr();
85  }
86 
87  // create PlanningScene using hybrid collision detector
88  planning_scene::PlanningScenePtr ps = planning_scene->diff();
89  ps->setActiveCollisionDetector(collision_detection::CollisionDetectorAllocatorHybrid::create(), true);
90 
91  // retrieve and configure existing context
92  const CHOMPPlanningContextPtr& context = planning_contexts_.at(req.group_name);
93  context->setPlanningScene(ps);
94  context->setMotionPlanRequest(req);
95  error_code.val = moveit_msgs::MoveItErrorCodes::SUCCESS;
96  return context;
97  }
98 
99  bool canServiceRequest(const planning_interface::MotionPlanRequest& /*req*/) const override
100  {
101  // TODO: this is a dummy implementation
102  // capabilities.dummy = false;
103  return true;
104  }
105 
106  std::string getDescription() const override
107  {
108  return "CHOMP";
109  }
110 
111  void getPlanningAlgorithms(std::vector<std::string>& algs) const override
112  {
113  algs.resize(1);
114  algs[0] = "CHOMP";
115  }
116 
117 protected:
118  std::map<std::string, CHOMPPlanningContextPtr> planning_contexts_;
119 };
120 
121 } // namespace chomp_interface
122 
robot_model.h
chomp_interface::CHOMPPlannerManager::getPlanningContext
planning_interface::PlanningContextPtr getPlanningContext(const planning_scene::PlanningSceneConstPtr &planning_scene, const planning_interface::MotionPlanRequest &req, moveit_msgs::MoveItErrorCodes &error_code) const override
Definition: chomp_plugin.cpp:131
chomp_interface::CHOMPPlannerManager::getPlanningAlgorithms
void getPlanningAlgorithms(std::vector< std::string > &algs) const override
Definition: chomp_plugin.cpp:175
chomp_interface
Definition: chomp_interface.h:43
chomp_interface::CHOMPPlannerManager::canServiceRequest
bool canServiceRequest(const planning_interface::MotionPlanRequest &) const override
Definition: chomp_plugin.cpp:163
planning_interface.h
chomp_interface::CHOMPPlannerManager
Definition: chomp_plugin.cpp:79
PLUGINLIB_EXPORT_CLASS
PLUGINLIB_EXPORT_CLASS(chomp_interface::CHOMPPlannerManager, planning_interface::PlannerManager)
chomp_interface::CHOMPPlannerManager::initialize
bool initialize(const moveit::core::RobotModelConstPtr &model, const std::string &ns) override
Definition: chomp_plugin.cpp:118
planning_interface::PlannerManager::PlannerManager
PlannerManager()
ROS_ERROR
#define ROS_ERROR(...)
chomp_interface::CHOMPPlannerManager::CHOMPPlannerManager
CHOMPPlannerManager()
Definition: chomp_plugin.cpp:114
planning_interface::MotionPlanRequest
moveit_msgs::MotionPlanRequest MotionPlanRequest
CollisionDetectorAllocatorTemplate< CollisionEnvHybrid, CollisionDetectorAllocatorHybrid >::create
static CollisionDetectorAllocatorPtr create()
chomp_interface::CHOMPPlannerManager::planning_contexts_
std::map< std::string, CHOMPPlanningContextPtr > planning_contexts_
Definition: chomp_plugin.cpp:182
collision_detector_allocator_hybrid.h
planning_scene.h
chomp_interface::CHOMPPlannerManager::getDescription
std::string getDescription() const override
Definition: chomp_plugin.cpp:170
planning_interface
class_list_macros.hpp
planning_scene
chomp_planning_context.h
planning_interface::PlannerManager
ros::NodeHandle


chomp_interface
Author(s): Gil Jones
autogenerated on Sat May 3 2025 02:27:34