transmission_loader.h
Go to the documentation of this file.
1 // Copyright (C) 2013, PAL Robotics S.L.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright notice,
7 // this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name of PAL Robotics S.L. nor the names of its
12 // contributors may be used to endorse or promote products derived from
13 // this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 // POSSIBILITY OF SUCH DAMAGE.
27 
29 
30 #pragma once
31 
32 
33 // C++ standard
34 #include <algorithm>
35 #include <limits>
36 #include <sstream>
37 #include <string>
38 #include <vector>
39 #include <memory>
40 
41 // TinyXML
42 #include <tinyxml.h>
43 
44 // ros_control
48 
52 
53 namespace transmission_interface
54 {
55 
62 {
63 public:
64  virtual ~TransmissionLoader() = default;
65 
66  virtual TransmissionSharedPtr load(const TransmissionInfo& transmission_info) = 0;
67 
68 protected:
70  {
74  };
75 
76  static bool checkActuatorDimension(const TransmissionInfo& transmission_info, const unsigned int expected_dim)
77  {
78  const unsigned int dim = transmission_info.actuators_.size();
79  if (expected_dim != dim)
80  {
81  ROS_ERROR_STREAM_NAMED("parser", "Invalid description for transmission '" << transmission_info.name_ <<
82  "' of type '" << transmission_info.type_ <<
83  "'. Expected " << expected_dim << " actuators, got " << dim << ".");
84  return false;
85  }
86  return true;
87  }
88 
89  static bool checkJointDimension(const TransmissionInfo& transmission_info, const unsigned int expected_dim)
90  {
91  const unsigned int dim = transmission_info.joints_.size();
92  if (expected_dim != dim)
93  {
94  ROS_ERROR_STREAM_NAMED("parser", "Invalid description for transmission '" << transmission_info.name_ <<
95  "' of type '" << transmission_info.type_ <<
96  "'. Expected " << expected_dim << " joints, got " << dim << ".");
97  return false;
98  }
99  return true;
100  }
101 
102  static TiXmlElement loadXmlElement(const std::string& element_str)
103  {
104  TiXmlElement element("");
105  std::stringstream element_stream;
106  element_stream << element_str;
107  element_stream >> element;
108  return element;
109  }
110 
111  static ParseStatus getActuatorReduction(const TiXmlElement& parent_el,
112  const std::string& actuator_name,
113  const std::string& transmission_name,
114  bool required,
115  double& reduction);
116 
117  static ParseStatus getJointReduction(const TiXmlElement& parent_el,
118  const std::string& joint_name,
119  const std::string& transmission_name,
120  bool required,
121  double& reduction);
122 
123  static ParseStatus getJointOffset(const TiXmlElement& parent_el,
124  const std::string& joint_name,
125  const std::string& transmission_name,
126  bool required,
127  double& offset);
128 
129  static ParseStatus getActuatorRole(const TiXmlElement& parent_el,
130  const std::string& actuator_name,
131  const std::string& transmission_name,
132  bool required,
133  std::string& role);
134 
135  static ParseStatus getJointRole(const TiXmlElement& parent_el,
136  const std::string& joint_name,
137  const std::string& transmission_name,
138  bool required,
139  std::string& role);
140 };
141 
142 typedef std::shared_ptr<TransmissionLoader> TransmissionLoaderSharedPtr;
143 
144 } // namespace
static TiXmlElement loadXmlElement(const std::string &element_str)
#define ROS_ERROR_STREAM_NAMED(name, args)
Abstract interface for loading transmission instances from configuration data.
std::shared_ptr< TransmissionLoader > TransmissionLoaderSharedPtr
Contains semantic info about a given transmission loaded from XML (URDF)
static ParseStatus getActuatorReduction(const TiXmlElement &parent_el, const std::string &actuator_name, const std::string &transmission_name, bool required, double &reduction)
Structs to hold transmission data loaded straight from XML (URDF).
static ParseStatus getActuatorRole(const TiXmlElement &parent_el, const std::string &actuator_name, const std::string &transmission_name, bool required, std::string &role)
static bool checkActuatorDimension(const TransmissionInfo &transmission_info, const unsigned int expected_dim)
static ParseStatus getJointRole(const TiXmlElement &parent_el, const std::string &joint_name, const std::string &transmission_name, bool required, std::string &role)
virtual TransmissionSharedPtr load(const TransmissionInfo &transmission_info)=0
static ParseStatus getJointReduction(const TiXmlElement &parent_el, const std::string &joint_name, const std::string &transmission_name, bool required, double &reduction)
std::shared_ptr< Transmission > TransmissionSharedPtr
Definition: transmission.h:184
std::vector< ActuatorInfo > actuators_
static ParseStatus getJointOffset(const TiXmlElement &parent_el, const std::string &joint_name, const std::string &transmission_name, bool required, double &offset)
static bool checkJointDimension(const TransmissionInfo &transmission_info, const unsigned int expected_dim)


transmission_interface
Author(s): Adolfo Rodriguez Tsouroukdissian
autogenerated on Sun May 10 2020 03:14:56