robot_hw.h
Go to the documentation of this file.
1 // Copyright (C) 2012, hiDOF 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. 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 #ifndef HARDWARE_INTERFACE_ROBOT_HW_H
29 #define HARDWARE_INTERFACE_ROBOT_HW_H
30 
31 #include <list>
32 #include <map>
33 #include <typeinfo>
38 #include <ros/console.h>
39 #include <ros/node_handle.h>
40 
41 namespace hardware_interface
42 {
43 
57 class RobotHW : public InterfaceManager
58 {
59 public:
61  {
62 
63  }
64 
65  virtual ~RobotHW()
66  {
67 
68  }
69 
80  virtual bool init(ros::NodeHandle& root_nh, ros::NodeHandle &robot_hw_nh) {return true;}
81 
91  virtual bool checkForConflict(const std::list<ControllerInfo>& info) const
92  {
93  // Map from resource name to all controllers claiming it
94  typedef std::map<std::string, std::list<ControllerInfo> > ResourceMap;
95 
96  typedef std::list<ControllerInfo>::const_iterator CtrlInfoIt;
97  typedef std::vector<InterfaceResources>::const_iterator ClaimedResIt;
98  typedef std::set<std::string>::const_iterator ResourceIt;
99 
100  // Populate a map of all controllers claiming individual resources.
101  // We do this by iterating over every claimed resource of every hardware interface used by every controller
102  ResourceMap resource_map;
103  for (CtrlInfoIt info_it = info.begin(); info_it != info.end(); ++info_it)
104  {
105  const std::vector<InterfaceResources>& c_res = info_it->claimed_resources;
106  for (ClaimedResIt c_res_it = c_res.begin(); c_res_it != c_res.end(); ++c_res_it)
107  {
108  const std::set<std::string>& iface_resources = c_res_it->resources;
109  for (ResourceIt resource_it = iface_resources.begin(); resource_it != iface_resources.end(); ++resource_it)
110  {
111  resource_map[*resource_it].push_back(*info_it);
112  }
113  }
114  }
115 
116  // Enforce resource exclusivity policy: No resource can be claimed by more than one controller
117  bool in_conflict = false;
118  for (ResourceMap::iterator it = resource_map.begin(); it != resource_map.end(); ++it)
119  {
120  if (it->second.size() > 1)
121  {
122  std::string controller_list;
123  for (CtrlInfoIt controller_it = it->second.begin(); controller_it != it->second.end(); ++controller_it)
124  controller_list += controller_it->name + ", ";
125  ROS_WARN("Resource conflict on [%s]. Controllers = [%s]", it->first.c_str(), controller_list.c_str());
126  in_conflict = true;
127  }
128  }
129 
130  return in_conflict;
131  }
140  virtual bool prepareSwitch(const std::list<ControllerInfo>& start_list,
141  const std::list<ControllerInfo>& stop_list) { return true; }
142 
147  virtual void doSwitch(const std::list<ControllerInfo>& /*start_list*/,
148  const std::list<ControllerInfo>& /*stop_list*/) {}
149 
156  virtual void read(const ros::Time& time, const ros::Duration& period) {}
157 
164  virtual void write(const ros::Time& time, const ros::Duration& period) {}
165 };
166 
168 
169 }
170 
171 #endif
172 
virtual void doSwitch(const std::list< ControllerInfo > &, const std::list< ControllerInfo > &)
Definition: robot_hw.h:147
virtual bool checkForConflict(const std::list< ControllerInfo > &info) const
Definition: robot_hw.h:91
virtual bool init(ros::NodeHandle &root_nh, ros::NodeHandle &robot_hw_nh)
The init function is called to initialize the RobotHW from a non-realtime thread. ...
Definition: robot_hw.h:80
#define ROS_WARN(...)
virtual bool prepareSwitch(const std::list< ControllerInfo > &start_list, const std::list< ControllerInfo > &stop_list)
Definition: robot_hw.h:140
virtual void read(const ros::Time &time, const ros::Duration &period)
Definition: robot_hw.h:156
boost::shared_ptr< RobotHW > RobotHWSharedPtr
Definition: robot_hw.h:167
std::map< std::string, std::vector< std::string > > ResourceMap
Robot Hardware Interface and Resource Manager.
Definition: robot_hw.h:57
virtual void write(const ros::Time &time, const ros::Duration &period)
Definition: robot_hw.h:164


hardware_interface
Author(s): Wim Meeussen, Adolfo Rodriguez Tsouroukdissian
autogenerated on Fri Jun 7 2019 22:00:02