chomp_plugin.cpp
Go to the documentation of this file.
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     error_code.val = moveit_msgs::MoveItErrorCodes::SUCCESS;
00090     return planning_contexts_.at(req.group_name);
00091   }
00092 
00093   bool canServiceRequest(const planning_interface::MotionPlanRequest &req) const
00094   {
00095     // TODO: this is a dummy implementation
00096     //      capabilities.dummy = false;
00097     return true;
00098   }
00099 
00100   std::string getDescription() const
00101   {
00102     return "CHOMP";
00103   }
00104 
00105   void getPlanningAlgorithms(std::vector<std::string> &algs) const
00106   {
00107     algs.resize(1);
00108     algs[0] = "CHOMP";
00109   }
00110 
00111 protected:
00112   std::map<std::string, CHOMPPlanningContextPtr> planning_contexts_;
00113 };
00114 
00115 }  // ompl_interface_ros
00116 
00117 PLUGINLIB_EXPORT_CLASS(chomp_interface::CHOMPPlannerManager, planning_interface::PlannerManager);


chomp_interface
Author(s): Gil Jones
autogenerated on Thu Oct 27 2016 05:22:26