controller_loader.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2017, Fetch Robotics Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Fetch Robotics Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL FETCH ROBOTICS INC. BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 // Author: Michael Ferguson
30 
32 
33 namespace robot_controllers
34 {
35 
37  plugin_loader_("robot_controllers", "robot_controllers::Controller"),
38  active_(false)
39 {
40 }
41 
42 bool ControllerLoader::init(const std::string& name, ControllerManager* manager)
43 {
44  ros::NodeHandle nh(name);
45  std::string controller_type;
46 
47  if (nh.getParam("type", controller_type))
48  {
49  // If plugin is bad, catch pluginlib exception
50  try
51  {
52  controller_ = plugin_loader_.createInstance(controller_type);
53  controller_->init(nh, manager);
54  }
56  {
57  ROS_ERROR_STREAM("Plugin error while loading controller: " << e.what());
58  return false;
59  }
60  return true;
61  }
62  ROS_ERROR_STREAM("Unable to load controller " << name.c_str());
63  return false;
64 }
65 
67 {
68  active_ = controller_->start();
69  return active_;
70 }
71 
72 bool ControllerLoader::stop(bool force)
73 {
74  bool stopped = controller_->stop(force);
75  if (stopped)
76  {
77  active_ = false;
78  }
79  return stopped;
80 }
81 
83 {
84  if (active_)
85  {
86  return controller_->reset();
87  }
88  return true;
89 }
90 
92 {
93  return active_;
94 }
95 
96 void ControllerLoader::update(const ros::Time& time, const ros::Duration& dt)
97 {
98  if (active_)
99  {
100  controller_->update(time, dt);
101  }
102 }
103 
105 {
106  return controller_;
107 }
108 
109 } // namespace robot_controllers
bool stop(bool force)
This calls through to controller, saves state locally.
pluginlib::ClassLoader< robot_controllers::Controller > plugin_loader_
void update(const ros::Time &time, const ros::Duration &dt)
If controller is active, calls through to controller.
ControllerPtr getController()
Returns the controller held by this loader.
bool start()
This calls through to controller, saves state locally.
Base class for a controller manager.
ControllerLoader()
Initialize this loader.
bool init(const std::string &name, ControllerManager *manager)
Load the controller.
bool isActive()
Returns true if the controller is active.
bool getParam(const std::string &key, std::string &s) const
bool reset()
This calls through to controller.
#define ROS_ERROR_STREAM(args)


robot_controllers_interface
Author(s): Michael Ferguson
autogenerated on Sun Sep 27 2020 03:22:36