robot_hw.h
Go to the documentation of this file.
00001 
00002 // Copyright (C) 2012, hiDOF INC.
00003 //
00004 // Redistribution and use in source and binary forms, with or without
00005 // modification, are permitted provided that the following conditions are met:
00006 //   * Redistributions of source code must retain the above copyright notice,
00007 //     this list of conditions and the following disclaimer.
00008 //   * Redistributions in binary form must reproduce the above copyright
00009 //     notice, this list of conditions and the following disclaimer in the
00010 //     documentation and/or other materials provided with the distribution.
00011 //   * Neither the name of hiDOF, Inc. nor the names of its
00012 //     contributors may be used to endorse or promote products derived from
00013 //     this software without specific prior written permission.
00014 //
00015 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00016 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00017 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00018 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00019 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00020 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00021 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00022 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00023 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00024 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00025 // POSSIBILITY OF SUCH DAMAGE.
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     // Map from resource name to all controllers claiming it
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     // Populate a map of all controllers claiming individual resources.
00083     // We do this by iterating over every claimed resource of every hardware interface used by every controller
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     // Enforce resource exclusivity policy: No resource can be claimed by more than one controller
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>& /*start_list*/,
00130                         const std::list<ControllerInfo>& /*stop_list*/) {}
00131 };
00132 
00133 }
00134 
00135 #endif
00136 


hardware_interface
Author(s): Wim Meeussen, Adolfo Rodriguez Tsouroukdissian
autogenerated on Thu Dec 1 2016 03:45:48