Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00027
00028
00029
00030
00031
00032
00033 #ifndef CONTROLLER_MANAGER_CONTROLLER_MANAGER_H
00034 #define CONTROLLER_MANAGER_CONTROLLER_MANAGER_H
00035
00036 #include "controller_manager/controller_spec.h"
00037 #include <pthread.h>
00038 #include <cstdio>
00039 #include <map>
00040 #include <string>
00041 #include <vector>
00042 #include <ros/ros.h>
00043 #include <tinyxml.h>
00044 #include <hardware_interface/robot_hw.h>
00045 #include <realtime_tools/realtime_publisher.h>
00046 #include <ros/node_handle.h>
00047 #include <pluginlib/class_loader.h>
00048 #include <controller_manager_msgs/ListControllerTypes.h>
00049 #include <controller_manager_msgs/ListControllers.h>
00050 #include <controller_manager_msgs/ReloadControllerLibraries.h>
00051 #include <controller_manager_msgs/LoadController.h>
00052 #include <controller_manager_msgs/UnloadController.h>
00053 #include <controller_manager_msgs/SwitchController.h>
00054 #include <boost/thread/condition.hpp>
00055 #include <boost/thread/recursive_mutex.hpp>
00056 #include <controller_manager/controller_loader_interface.h>
00057
00058
00059 namespace controller_manager{
00060
00069 class ControllerManager{
00070
00071 public:
00078 ControllerManager(hardware_interface::RobotHW *robot_hw,
00079 const ros::NodeHandle& nh=ros::NodeHandle());
00080 virtual ~ControllerManager();
00081
00094 void update(const ros::Time& time, const ros::Duration& period, bool reset_controllers=false);
00095
00096
00122 bool loadController(const std::string& name);
00123
00129 bool unloadController(const std::string &name);
00130
00141 bool switchController(const std::vector<std::string>& start_controllers,
00142 const std::vector<std::string>& stop_controllers,
00143 const int strictness);
00144
00150 virtual controller_interface::ControllerBase* getControllerByName(const std::string& name);
00151
00165 void registerControllerLoader(boost::shared_ptr<ControllerLoaderInterface> controller_loader);
00166
00167
00168
00169 private:
00170 void getControllerNames(std::vector<std::string> &v);
00171
00172 hardware_interface::RobotHW* robot_hw_;
00173
00174 ros::NodeHandle root_nh_, cm_node_;
00175
00176 typedef boost::shared_ptr<ControllerLoaderInterface> LoaderPtr;
00177 std::list<LoaderPtr> controller_loaders_;
00178
00181 std::vector<controller_interface::ControllerBase*> start_request_, stop_request_;
00182 std::list<hardware_interface::ControllerInfo> switch_start_list_, switch_stop_list_;
00183 bool please_switch_;
00184 int switch_strictness_;
00185
00186
00191
00192 boost::recursive_mutex controllers_lock_;
00194 std::vector<ControllerSpec> controllers_lists_[2];
00196 int current_controllers_list_;
00198 int used_by_realtime_;
00199
00200
00201
00204 bool listControllerTypesSrv(controller_manager_msgs::ListControllerTypes::Request &req,
00205 controller_manager_msgs::ListControllerTypes::Response &resp);
00206 bool listControllersSrv(controller_manager_msgs::ListControllers::Request &req,
00207 controller_manager_msgs::ListControllers::Response &resp);
00208 bool switchControllerSrv(controller_manager_msgs::SwitchController::Request &req,
00209 controller_manager_msgs::SwitchController::Response &resp);
00210 bool loadControllerSrv(controller_manager_msgs::LoadController::Request &req,
00211 controller_manager_msgs::LoadController::Response &resp);
00212 bool unloadControllerSrv(controller_manager_msgs::UnloadController::Request &req,
00213 controller_manager_msgs::UnloadController::Response &resp);
00214 bool reloadControllerLibrariesSrv(controller_manager_msgs::ReloadControllerLibraries::Request &req,
00215 controller_manager_msgs::ReloadControllerLibraries::Response &resp);
00216 boost::mutex services_lock_;
00217 ros::ServiceServer srv_list_controllers_, srv_list_controller_types_, srv_load_controller_;
00218 ros::ServiceServer srv_unload_controller_, srv_switch_controller_, srv_reload_libraries_;
00219
00220 };
00221
00222 }
00223 #endif