moveit_controller_manager_example.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2013, Ioan A. Sucan
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 Ioan A. Sucan 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 /* Author: Ioan Sucan */
00036 
00037 #include <ros/ros.h>
00038 #include <moveit/controller_manager/controller_manager.h>
00039 #include <sensor_msgs/JointState.h>
00040 #include <pluginlib/class_list_macros.h>
00041 #include <map>
00042 
00043 namespace moveit_controller_manager_example
00044 {
00045 
00046 class ExampleControllerHandle : public moveit_controller_manager::MoveItControllerHandle
00047 {
00048 public:
00049   ExampleControllerHandle(const std::string &name) : moveit_controller_manager::MoveItControllerHandle(name)
00050   {
00051   }
00052   
00053   virtual bool sendTrajectory(const moveit_msgs::RobotTrajectory &t)
00054   {
00055     // do whatever is needed to actually execute this trajectory
00056     return true;
00057   }
00058   
00059   virtual bool cancelExecution()
00060   {   
00061     // do whatever is needed to cancel execution 
00062     return true;
00063   }
00064   
00065   virtual bool waitForExecution(const ros::Duration &)
00066   {
00067     // wait for the current execution to finish
00068     return true;
00069   }
00070   
00071   virtual moveit_controller_manager::ExecutionStatus getLastExecutionStatus()
00072   {
00073     return moveit_controller_manager::ExecutionStatus(moveit_controller_manager::ExecutionStatus::SUCCEEDED);
00074   }
00075 };
00076 
00077 
00078 class MoveItControllerManagerExample : public moveit_controller_manager::MoveItControllerManager
00079 {
00080 public:
00081 
00082   MoveItControllerManagerExample()
00083   {
00084   }
00085   
00086   virtual ~MoveItControllerManagerExample()
00087   {
00088   }
00089 
00090   virtual moveit_controller_manager::MoveItControllerHandlePtr getControllerHandle(const std::string &name)
00091   {
00092     return moveit_controller_manager::MoveItControllerHandlePtr(new ExampleControllerHandle(name));
00093   }
00094   
00095   /*
00096    * Get the list of controller names.
00097    */
00098   virtual void getControllersList(std::vector<std::string> &names)
00099   {
00100     names.resize(1);
00101     names[0] = "my_example_controller";
00102   }
00103 
00104   /*
00105    * This plugin assumes that all controllers are already active -- and if they are not, well, it has no way to deal with it anyways!
00106    */
00107   virtual void getActiveControllers(std::vector<std::string> &names)
00108   {
00109     getControllersList(names);
00110   }
00111 
00112   /*
00113    * Controller must be loaded to be active, see comment above about active controllers...
00114    */
00115   virtual void getLoadedControllers(std::vector<std::string> &names)
00116   {
00117     getControllersList(names);
00118   }
00119 
00120   /*
00121    * Get the list of joints that a controller can control.
00122    */
00123   virtual void getControllerJoints(const std::string &name, std::vector<std::string> &joints)
00124   {
00125     joints.clear();
00126     if (name == "my_example_controller")
00127     {
00128       // declare which joints this controller actuates
00129       joints.push_back("joint1");
00130       joints.push_back("joint2");
00131       joints.push_back("joint3");
00132       joints.push_back("joint4");
00133       // ... 
00134     }
00135   }
00136 
00137   /*
00138    * Controllers are all active and default.
00139    */
00140   virtual moveit_controller_manager::MoveItControllerManager::ControllerState getControllerState(const std::string &name)
00141   {
00142     moveit_controller_manager::MoveItControllerManager::ControllerState state;
00143     state.active_ = true;
00144     state.default_ = true;
00145     return state;
00146   }
00147 
00148   /* Cannot switch our controllers */
00149   virtual bool switchControllers(const std::vector<std::string> &activate, const std::vector<std::string> &deactivate) { return false; }
00150 
00151 protected:
00152 
00153   ros::NodeHandle node_handle_;
00154   std::map<std::string, moveit_controller_manager::MoveItControllerHandlePtr> controllers_;
00155 };
00156 
00157 } // end namespace moveit_controller_manager_example
00158 
00159 PLUGINLIB_EXPORT_CLASS(moveit_controller_manager_example::MoveItControllerManagerExample,
00160                        moveit_controller_manager::MoveItControllerManager);


moveit_controller_manager_example
Author(s): Ioan Sucan
autogenerated on Wed Aug 26 2015 12:42:27