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
00029
00030 #ifndef TRANSMISSION_INTERFACE_TRANSMISSION_LOADER_H
00031 #define TRANSMISSION_INTERFACE_TRANSMISSION_LOADER_H
00032
00033
00034 #include <algorithm>
00035 #include <limits>
00036 #include <sstream>
00037 #include <string>
00038 #include <vector>
00039
00040
00041 #include <boost/foreach.hpp>
00042 #include <boost/shared_ptr.hpp>
00043
00044
00045 #include <tinyxml.h>
00046
00047
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 }
00149
00150 #endif // header guard