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     // Figure out which resources have multiple users
00076     typedef std::map<std::string, std::list<ControllerInfo> > ResourceMap;
00077     ResourceMap resource_map;
00078     for (std::list<ControllerInfo>::const_iterator info_it = info.begin(); info_it != info.end(); ++info_it)
00079       for (std::set<std::string>::const_iterator resource_it = info_it->resources.begin(); resource_it != info_it->resources.end(); ++resource_it)
00080         resource_map[*resource_it].push_back(*info_it);
00081 
00082     bool in_conflict = false;
00083     for (ResourceMap::iterator it = resource_map.begin(); it != resource_map.end(); ++it)
00084     {
00085       if (it->second.size() > 1)
00086       {
00087         std::string controller_list;
00088         for (std::list<ControllerInfo>::const_iterator controller_it = it->second.begin(); controller_it != it->second.end(); ++controller_it)
00089           controller_list += controller_it->name + ", ";
00090         ROS_WARN("Resource conflict on [%s].  Controllers = [%s]", it->first.c_str(), controller_list.c_str());
00091         in_conflict = true;
00092       }
00093     }
00094 
00095     return in_conflict;
00096   }
00106   virtual bool canSwitch(const std::list<ControllerInfo>& /*start_list*/,
00107                          const std::list<ControllerInfo>& /*stop_list*/) const { return true; }
00108 
00114   virtual bool prepareSwitch(const std::list<ControllerInfo>& start_list,
00115                              const std::list<ControllerInfo>& stop_list) { return canSwitch(start_list, stop_list); }
00116 
00121   virtual void doSwitch(const std::list<ControllerInfo>& /*start_list*/,
00122                         const std::list<ControllerInfo>& /*stop_list*/) {}
00123 };
00124 
00125 typedef boost::shared_ptr<RobotHW> RobotHWSharedPtr;
00126 
00127 }
00128 
00129 #endif
00130 


hardware_interface
Author(s): Wim Meeussen, Adolfo Rodriguez Tsouroukdissian
autogenerated on Sat Jun 8 2019 20:09:17