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 #ifndef HARDWARE_INTERFACE_ROBOT_HW_H
00029 #define HARDWARE_INTERFACE_ROBOT_HW_H
00030
00031 #include <list>
00032 #include <map>
00033 #include <typeinfo>
00034 #include <hardware_interface/internal/demangle_symbol.h>
00035 #include <hardware_interface/internal/interface_manager.h>
00036 #include <hardware_interface/hardware_interface.h>
00037 #include <hardware_interface/controller_info.h>
00038 #include <ros/console.h>
00039
00040 namespace hardware_interface
00041 {
00042
00056 class RobotHW : public InterfaceManager
00057 {
00058 public:
00059 RobotHW()
00060 {
00061
00062 }
00063
00073 virtual bool checkForConflict(const std::list<ControllerInfo>& info) const
00074 {
00075
00076 typedef std::map<std::string, std::list<ControllerInfo> > ResourceMap;
00077
00078 typedef std::list<ControllerInfo>::const_iterator CtrlInfoIt;
00079 typedef std::vector<InterfaceResources>::const_iterator ClaimedResIt;
00080 typedef std::set<std::string>::const_iterator ResourceIt;
00081
00082
00083
00084 ResourceMap resource_map;
00085 for (CtrlInfoIt info_it = info.begin(); info_it != info.end(); ++info_it)
00086 {
00087 const std::vector<InterfaceResources>& c_res = info_it->claimed_resources;
00088 for (ClaimedResIt c_res_it = c_res.begin(); c_res_it != c_res.end(); ++c_res_it)
00089 {
00090 const std::set<std::string>& iface_resources = c_res_it->resources;
00091 for (ResourceIt resource_it = iface_resources.begin(); resource_it != iface_resources.end(); ++resource_it)
00092 {
00093 resource_map[*resource_it].push_back(*info_it);
00094 }
00095 }
00096 }
00097
00098
00099 bool in_conflict = false;
00100 for (ResourceMap::iterator it = resource_map.begin(); it != resource_map.end(); ++it)
00101 {
00102 if (it->second.size() > 1)
00103 {
00104 std::string controller_list;
00105 for (CtrlInfoIt controller_it = it->second.begin(); controller_it != it->second.end(); ++controller_it)
00106 controller_list += controller_it->name + ", ";
00107 ROS_WARN("Resource conflict on [%s]. Controllers = [%s]", it->first.c_str(), controller_list.c_str());
00108 in_conflict = true;
00109 }
00110 }
00111
00112 return in_conflict;
00113 }
00122 virtual bool prepareSwitch(const std::list<ControllerInfo>& start_list,
00123 const std::list<ControllerInfo>& stop_list) { return true; }
00124
00129 virtual void doSwitch(const std::list<ControllerInfo>& ,
00130 const std::list<ControllerInfo>& ) {}
00131 };
00132
00133 }
00134
00135 #endif
00136