transmission_loader.h
Go to the documentation of this file.
00001 
00002 // Copyright (C) 2013, PAL Robotics S.L.
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 PAL Robotics S.L. 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 
00029 
00030 #ifndef TRANSMISSION_INTERFACE_TRANSMISSION_LOADER_H
00031 #define TRANSMISSION_INTERFACE_TRANSMISSION_LOADER_H
00032 
00033 // C++ standard
00034 #include <algorithm>
00035 #include <limits>
00036 #include <sstream>
00037 #include <string>
00038 #include <vector>
00039 
00040 // Boost
00041 #include <boost/foreach.hpp>
00042 #include <boost/shared_ptr.hpp>
00043 
00044 // TinyXML
00045 #include <tinyxml.h>
00046 
00047 // ros_control
00048 #include <hardware_interface/actuator_command_interface.h>
00049 #include <hardware_interface/joint_command_interface.h>
00050 #include <hardware_interface/robot_hw.h>
00051 
00052 #include <transmission_interface/robot_transmissions.h>
00053 #include <transmission_interface/transmission_info.h>
00054 #include <transmission_interface/transmission.h>
00055 
00056 namespace transmission_interface
00057 {
00058 
00064 class TransmissionLoader
00065 {
00066 public:
00067 
00068   virtual ~TransmissionLoader() {}
00069 
00070   virtual TransmissionSharedPtr load(const TransmissionInfo& transmission_info) = 0;
00071 
00072 protected:
00073   enum ParseStatus
00074   {
00075     SUCCESS,
00076     NO_DATA,
00077     BAD_TYPE
00078   };
00079 
00080   static bool checkActuatorDimension(const TransmissionInfo& transmission_info, const unsigned int expected_dim)
00081   {
00082     const unsigned int dim = transmission_info.actuators_.size();
00083     if (expected_dim != dim)
00084     {
00085       ROS_ERROR_STREAM_NAMED("parser", "Invalid description for transmission '" << transmission_info.name_ <<
00086                              "' of type '" << transmission_info.type_ <<
00087                              "'. Expected " << expected_dim << " actuators, got " << dim << ".");
00088       return false;
00089     }
00090     return true;
00091   }
00092 
00093   static bool checkJointDimension(const TransmissionInfo& transmission_info, const unsigned int expected_dim)
00094   {
00095     const unsigned int dim = transmission_info.joints_.size();
00096     if (expected_dim != dim)
00097     {
00098       ROS_ERROR_STREAM_NAMED("parser", "Invalid description for transmission '" << transmission_info.name_ <<
00099                              "' of type '" << transmission_info.type_ <<
00100                              "'. Expected " << expected_dim << " joints, got " << dim << ".");
00101       return false;
00102     }
00103     return true;
00104   }
00105 
00106   static TiXmlElement loadXmlElement(const std::string& element_str)
00107   {
00108     TiXmlElement element("");
00109     std::stringstream element_stream;
00110     element_stream << element_str;
00111     element_stream >> element;
00112     return element;
00113   }
00114 
00115   static ParseStatus getActuatorReduction(const TiXmlElement& parent_el,
00116                                           const std::string&  actuator_name,
00117                                           const std::string&  transmission_name,
00118                                           bool                required,
00119                                           double&             reduction);
00120 
00121   static ParseStatus getJointReduction(const TiXmlElement& parent_el,
00122                                        const std::string&  joint_name,
00123                                        const std::string&  transmission_name,
00124                                        bool                required,
00125                                        double&             reduction);
00126 
00127   static ParseStatus getJointOffset(const TiXmlElement& parent_el,
00128                                     const std::string&  joint_name,
00129                                     const std::string&  transmission_name,
00130                                     bool                required,
00131                                     double&             offset);
00132 
00133   static ParseStatus getActuatorRole(const TiXmlElement& parent_el,
00134                                      const std::string&  actuator_name,
00135                                      const std::string&  transmission_name,
00136                                      bool                required,
00137                                      std::string&        role);
00138 
00139   static ParseStatus getJointRole(const TiXmlElement& parent_el,
00140                                   const std::string&  joint_name,
00141                                   const std::string&  transmission_name,
00142                                   bool                required,
00143                                   std::string&        role);
00144 };
00145 
00146 typedef boost::shared_ptr<TransmissionLoader> TransmissionLoaderSharedPtr;
00147 
00148 } // namespace
00149 
00150 #endif // header guard


transmission_interface
Author(s): Adolfo Rodriguez Tsouroukdissian
autogenerated on Sat Jun 8 2019 20:09:31