controller_manager.h
Go to the documentation of this file.
1 // Copyright (C) 2012, hiDOF, INC & 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 hiDOF, Inc., Willow Garage, Inc., 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: Wim Meeussen
30  */
31 
32 #pragma once
33 
34 
36 #include <cstdio>
37 #include <map>
38 #include <mutex>
39 #include <string>
40 #include <vector>
41 #include <ros/ros.h>
43 #include <ros/node_handle.h>
45 #include <controller_manager_msgs/ListControllerTypes.h>
46 #include <controller_manager_msgs/ListControllers.h>
47 #include <controller_manager_msgs/ReloadControllerLibraries.h>
48 #include <controller_manager_msgs/LoadController.h>
49 #include <controller_manager_msgs/UnloadController.h>
50 #include <controller_manager_msgs/SwitchController.h>
52 
53 
54 namespace controller_manager{
55 
65 
66 public:
67  static constexpr bool WAIT_FOR_ALL_RESOURCES = false;
68  static constexpr double INFINITE_TIMEOUT = 0.0;
69 
77  const ros::NodeHandle& nh=ros::NodeHandle());
78  virtual ~ControllerManager() = default;
79 
92  void update(const ros::Time& time, const ros::Duration& period, bool reset_controllers=false);
93  /*\}*/
94 
120  bool loadController(const std::string& name);
121 
127  bool unloadController(const std::string &name);
128 
143  bool switchController(const std::vector<std::string>& start_controllers,
144  const std::vector<std::string>& stop_controllers,
145  const int strictness, bool start_asap = WAIT_FOR_ALL_RESOURCES,
146  double timeout = INFINITE_TIMEOUT);
147 
153  virtual controller_interface::ControllerBase* getControllerByName(const std::string& name);
154 
169  /*\}*/
170 
171 
172 private:
173  void getControllerNames(std::vector<std::string> &v);
174 
175  void manageSwitch(const ros::Time& time);
176  void stopControllers(const ros::Time& time);
177  void startControllers(const ros::Time& time);
178  void startControllersAsap(const ros::Time& time);
179 
181 
183 
184  std::list<ControllerLoaderInterfaceSharedPtr> controller_loaders_;
185 
188  std::vector<controller_interface::ControllerBase*> start_request_, stop_request_;
189  std::list<hardware_interface::ControllerInfo> switch_start_list_, switch_stop_list_;
190 
192  {
193  bool do_switch = {false};
194  bool started = {false};
196 
197  // Switch options
198  int strictness = {0};
199  bool start_asap = {false};
200  double timeout = {0.0};
201  };
202 
204 
205  /*\}*/
206 
211  std::recursive_mutex controllers_lock_;
214  std::vector<ControllerSpec> controllers_lists_[2];
218  int used_by_realtime_ = {-1};
219  /*\}*/
220 
221 
224  bool listControllerTypesSrv(controller_manager_msgs::ListControllerTypes::Request &req,
225  controller_manager_msgs::ListControllerTypes::Response &resp);
226  bool listControllersSrv(controller_manager_msgs::ListControllers::Request &req,
227  controller_manager_msgs::ListControllers::Response &resp);
228  bool switchControllerSrv(controller_manager_msgs::SwitchController::Request &req,
229  controller_manager_msgs::SwitchController::Response &resp);
230  bool loadControllerSrv(controller_manager_msgs::LoadController::Request &req,
231  controller_manager_msgs::LoadController::Response &resp);
232  bool unloadControllerSrv(controller_manager_msgs::UnloadController::Request &req,
233  controller_manager_msgs::UnloadController::Response &resp);
234  bool reloadControllerLibrariesSrv(controller_manager_msgs::ReloadControllerLibraries::Request &req,
235  controller_manager_msgs::ReloadControllerLibraries::Response &resp);
236  std::mutex services_lock_;
239  /*\}*/
240 };
241 
242 }
bool switchControllerSrv(controller_manager_msgs::SwitchController::Request &req, controller_manager_msgs::SwitchController::Response &resp)
void getControllerNames(std::vector< std::string > &v)
ROS Controller Manager and Runner.
bool loadControllerSrv(controller_manager_msgs::LoadController::Request &req, controller_manager_msgs::LoadController::Response &resp)
std::vector< controller_interface::ControllerBase * > stop_request_
void startControllersAsap(const ros::Time &time)
static constexpr double INFINITE_TIMEOUT
bool loadController(const std::string &name)
Load a new controller by name.
void stopControllers(const ros::Time &time)
int used_by_realtime_
The index of the controllers list being used in the real-time thread.
std::vector< ControllerSpec > controllers_lists_[2]
Double-buffered controllers list.
void manageSwitch(const ros::Time &time)
hardware_interface::RobotHW * robot_hw_
std::vector< controller_interface::ControllerBase * > start_request_
bool listControllerTypesSrv(controller_manager_msgs::ListControllerTypes::Request &req, controller_manager_msgs::ListControllerTypes::Response &resp)
bool switchController(const std::vector< std::string > &start_controllers, const std::vector< std::string > &stop_controllers, const int strictness, bool start_asap=WAIT_FOR_ALL_RESOURCES, double timeout=INFINITE_TIMEOUT)
Switch multiple controllers simultaneously.
virtual controller_interface::ControllerBase * getControllerByName(const std::string &name)
Get a controller by name.
bool unloadController(const std::string &name)
Unload a controller by name.
bool listControllersSrv(controller_manager_msgs::ListControllers::Request &req, controller_manager_msgs::ListControllers::Response &resp)
static constexpr bool WAIT_FOR_ALL_RESOURCES
ROSTIME_DECL const Time TIME_MAX
bool unloadControllerSrv(controller_manager_msgs::UnloadController::Request &req, controller_manager_msgs::UnloadController::Response &resp)
std::shared_ptr< ControllerLoaderInterface > ControllerLoaderInterfaceSharedPtr
std::list< ControllerLoaderInterfaceSharedPtr > controller_loaders_
std::list< hardware_interface::ControllerInfo > switch_start_list_
int current_controllers_list_
The index of the current controllers list.
bool reloadControllerLibrariesSrv(controller_manager_msgs::ReloadControllerLibraries::Request &req, controller_manager_msgs::ReloadControllerLibraries::Response &resp)
void startControllers(const ros::Time &time)
ControllerManager(hardware_interface::RobotHW *robot_hw, const ros::NodeHandle &nh=ros::NodeHandle())
Constructor.
void registerControllerLoader(ControllerLoaderInterfaceSharedPtr controller_loader)
Register a controller loader.
std::list< hardware_interface::ControllerInfo > switch_stop_list_
void update(const ros::Time &time, const ros::Duration &period, bool reset_controllers=false)
Update all active controllers.
std::recursive_mutex controllers_lock_
Mutex protecting the current controllers list.


controller_manager
Author(s): Wim Meeussen, Mathias Lüdtke
autogenerated on Mon Feb 28 2022 23:30:17