00001 /********************************************************************* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2011, Willow Garage, Inc. 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of Willow Garage nor the names of its 00018 * contributors may be used to endorse or promote products derived 00019 * from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 *********************************************************************/ 00034 00035 #include <moveit/planning_interface/planning_interface.h> 00036 #include <moveit/planning_scene/planning_scene.h> 00037 #include <moveit/robot_model/robot_model.h> 00038 #include <moveit_msgs/GetMotionPlan.h> 00039 #include <chomp_interface/chomp_planning_context.h> 00040 00041 #include <boost/shared_ptr.hpp> 00042 00043 #include <pluginlib/class_list_macros.h> 00044 00045 namespace chomp_interface 00046 { 00047 class CHOMPPlannerManager : public planning_interface::PlannerManager 00048 { 00049 public: 00050 CHOMPPlannerManager() : planning_interface::PlannerManager() 00051 { 00052 } 00053 00054 bool initialize(const robot_model::RobotModelConstPtr& model, const std::string& ns) 00055 { 00056 // model->printModelInfo(std::cout); 00057 std::vector<std::string> groups = model->getJointModelGroupNames(); 00058 ROS_INFO_STREAM("Following groups exist:"); 00059 for (int i = 0; i < groups.size(); i++) 00060 { 00061 ROS_INFO("%s", groups[i].c_str()); 00062 planning_contexts_[groups[i]] = 00063 CHOMPPlanningContextPtr(new CHOMPPlanningContext("chomp_planning_context", groups[i], model)); 00064 } 00065 return true; 00066 } 00067 00068 planning_interface::PlanningContextPtr getPlanningContext(const planning_scene::PlanningSceneConstPtr& planning_scene, 00069 const planning_interface::MotionPlanRequest& req, 00070 moveit_msgs::MoveItErrorCodes& error_code) const 00071 { 00072 error_code.val = moveit_msgs::MoveItErrorCodes::SUCCESS; 00073 00074 if (req.group_name.empty()) 00075 { 00076 ROS_ERROR("No group specified to plan for"); 00077 error_code.val = moveit_msgs::MoveItErrorCodes::INVALID_GROUP_NAME; 00078 return planning_interface::PlanningContextPtr(); 00079 } 00080 00081 if (!planning_scene) 00082 { 00083 ROS_ERROR("No planning scene supplied as input"); 00084 error_code.val = moveit_msgs::MoveItErrorCodes::FAILURE; 00085 return planning_interface::PlanningContextPtr(); 00086 } 00087 00088 planning_contexts_.at(req.group_name)->setMotionPlanRequest(req); 00089 planning_contexts_.at(req.group_name)->setPlanningScene(planning_scene); 00090 error_code.val = moveit_msgs::MoveItErrorCodes::SUCCESS; 00091 return planning_contexts_.at(req.group_name); 00092 } 00093 00094 bool canServiceRequest(const planning_interface::MotionPlanRequest& req) const 00095 { 00096 // TODO: this is a dummy implementation 00097 // capabilities.dummy = false; 00098 return true; 00099 } 00100 00101 std::string getDescription() const 00102 { 00103 return "CHOMP"; 00104 } 00105 00106 void getPlanningAlgorithms(std::vector<std::string>& algs) const 00107 { 00108 algs.resize(1); 00109 algs[0] = "CHOMP"; 00110 } 00111 00112 protected: 00113 std::map<std::string, CHOMPPlanningContextPtr> planning_contexts_; 00114 }; 00115 00116 } // ompl_interface_ros 00117 00118 PLUGINLIB_EXPORT_CLASS(chomp_interface::CHOMPPlannerManager, planning_interface::PlannerManager);