controller_manager.h
Go to the documentation of this file.
1 // Copyright (C) 2008-2009, Willow Garage, Inc.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright notice,
7 // this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name of Stanford University nor the names of its
12 // contributors may be used to endorse or promote products derived from
13 // this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 // POSSIBILITY OF SUCH DAMAGE.
27 
28 /*
29  * Author: Stuart Glaser, Wim Meeussen
30  */
31 #ifndef MECHANISM_CONTROL_H
32 #define MECHANISM_CONTROL_H
33 
34 #include <pthread.h>
35 #include <map>
36 #include <string>
37 #include <vector>
38 #include "ros/ros.h"
40 #include <tinyxml.h>
44 #include <ros/node_handle.h>
46 #include "pluginlib/class_loader.h"
47 #include <pr2_mechanism_msgs/ListControllerTypes.h>
48 #include <pr2_mechanism_msgs/ListControllers.h>
49 #include <pr2_mechanism_msgs/ReloadControllerLibraries.h>
50 #include <pr2_mechanism_msgs/LoadController.h>
51 #include <pr2_mechanism_msgs/UnloadController.h>
52 #include <pr2_mechanism_msgs/SwitchController.h>
53 #include <pr2_mechanism_msgs/MechanismStatistics.h>
54 #include <sensor_msgs/JointState.h>
55 #include <boost/thread/condition.hpp>
56 
57 
59 
61 
62 public:
64  const ros::NodeHandle& nh=ros::NodeHandle());
65  virtual ~ControllerManager();
66 
67  // Real-time functions
68  void update();
69 
70  // Non real-time functions
71  bool initXml(TiXmlElement* config);
72  bool loadController(const std::string& name);
73  bool unloadController(const std::string &name);
74  bool switchController(const std::vector<std::string>& start_controllers,
75  const std::vector<std::string>& stop_controllers,
76  const int strictness);
77 
78  // controllers_lock_ must be locked before calling
79  virtual pr2_controller_interface::Controller* getControllerByName(const std::string& name);
80 
83 
84 private:
85  void getControllerNames(std::vector<std::string> &v);
86  void getControllerSchedule(std::vector<size_t> &schedule);
87 
90 
91  // for controller switching
92  std::vector<pr2_controller_interface::Controller*> start_request_, stop_request_;
95 
96  // controller lists
97  boost::mutex controllers_lock_;
98  std::vector<ControllerSpec> controllers_lists_[2];
99  std::vector<size_t> controllers_scheduling_[2];
101 
102  // for controller statistics
106 
107  // for publishing constroller state
108  void publishJointState();
114 
115  // services to work with controllers
116  bool listControllerTypesSrv(pr2_mechanism_msgs::ListControllerTypes::Request &req,
117  pr2_mechanism_msgs::ListControllerTypes::Response &resp);
118  bool listControllersSrv(pr2_mechanism_msgs::ListControllers::Request &req,
119  pr2_mechanism_msgs::ListControllers::Response &resp);
120  bool switchControllerSrv(pr2_mechanism_msgs::SwitchController::Request &req,
121  pr2_mechanism_msgs::SwitchController::Response &resp);
122  bool loadControllerSrv(pr2_mechanism_msgs::LoadController::Request &req,
123  pr2_mechanism_msgs::LoadController::Response &resp);
124  bool unloadControllerSrv(pr2_mechanism_msgs::UnloadController::Request &req,
125  pr2_mechanism_msgs::UnloadController::Response &resp);
126  bool reloadControllerLibrariesSrv(pr2_mechanism_msgs::ReloadControllerLibraries::Request &req,
127  pr2_mechanism_msgs::ReloadControllerLibraries::Response &resp);
128  boost::mutex services_lock_;
132 };
133 
134 }
135 #endif /* MECHANISM_CONTROL_H */
std::vector< pr2_controller_interface::Controller * > stop_request_
bool listControllerTypesSrv(pr2_mechanism_msgs::ListControllerTypes::Request &req, pr2_mechanism_msgs::ListControllerTypes::Response &resp)
bool unloadControllerSrv(pr2_mechanism_msgs::UnloadController::Request &req, pr2_mechanism_msgs::UnloadController::Response &resp)
bool switchController(const std::vector< std::string > &start_controllers, const std::vector< std::string > &stop_controllers, const int strictness)
std::vector< size_t > controllers_scheduling_[2]
bool switchControllerSrv(pr2_mechanism_msgs::SwitchController::Request &req, pr2_mechanism_msgs::SwitchController::Response &resp)
void getControllerSchedule(std::vector< size_t > &schedule)
boost::shared_ptr< pluginlib::ClassLoader< pr2_controller_interface::Controller > > controller_loader_
bool reloadControllerLibrariesSrv(pr2_mechanism_msgs::ReloadControllerLibraries::Request &req, pr2_mechanism_msgs::ReloadControllerLibraries::Response &resp)
std::vector< pr2_controller_interface::Controller * > start_request_
bool loadControllerSrv(pr2_mechanism_msgs::LoadController::Request &req, pr2_mechanism_msgs::LoadController::Response &resp)
realtime_tools::RealtimePublisher< pr2_mechanism_msgs::MechanismStatistics > pub_mech_stats_
bool unloadController(const std::string &name)
virtual pr2_controller_interface::Controller * getControllerByName(const std::string &name)
bool listControllersSrv(pr2_mechanism_msgs::ListControllers::Request &req, pr2_mechanism_msgs::ListControllers::Response &resp)
std::vector< ControllerSpec > controllers_lists_[2]
bool loadController(const std::string &name)
pr2_mechanism_model::RobotState * state_
realtime_tools::RealtimePublisher< sensor_msgs::JointState > pub_joint_state_
ControllerManager(pr2_hardware_interface::HardwareInterface *hw, const ros::NodeHandle &nh=ros::NodeHandle())
void getControllerNames(std::vector< std::string > &v)


pr2_controller_manager
Author(s): Eric Berger berger@willowgarage.com, Stuart Glaser, Wim Meeussen
autogenerated on Fri Jun 7 2019 22:04:28