transmission_loader.cpp
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 
28 // Boost
29 #include <boost/lexical_cast.hpp>
30 
31 // ros_control
33 
34 
35 namespace transmission_interface
36 {
37 
39 TransmissionLoader::getActuatorReduction(const TiXmlElement& parent_el,
40  const std::string& actuator_name,
41  const std::string& transmission_name,
42  bool required,
43  double& reduction)
44 {
45  // Get XML element
46  const TiXmlElement* reduction_el = parent_el.FirstChildElement("mechanicalReduction");
47  if(!reduction_el)
48  {
49  if (required)
50  {
51  ROS_ERROR_STREAM_NAMED("parser", "Actuator '" << actuator_name << "' of transmission '" << transmission_name <<
52  "' does not specify the required <mechanicalReduction> element.");
53  }
54  else
55  {
56  ROS_DEBUG_STREAM_NAMED("parser", "Actuator '" << actuator_name << "' of transmission '" << transmission_name <<
57  "' does not specify the optional <mechanicalReduction> element.");
58  }
59  return NO_DATA;
60  }
61 
62  // Cast to number
63  try {reduction = boost::lexical_cast<double>(reduction_el->GetText());}
64  catch (const boost::bad_lexical_cast&)
65  {
66  ROS_ERROR_STREAM_NAMED("parser", "Actuator '" << actuator_name << "' of transmission '" << transmission_name <<
67  "' specifies the <mechanicalReduction> element, but is not a number.");
68  return BAD_TYPE;
69  }
70  return SUCCESS;
71 }
72 
74 TransmissionLoader::getJointReduction(const TiXmlElement& parent_el,
75  const std::string& joint_name,
76  const std::string& transmission_name,
77  bool required,
78  double& reduction)
79 {
80  // Get XML element
81  const TiXmlElement* reduction_el = parent_el.FirstChildElement("mechanicalReduction");
82  if(!reduction_el)
83  {
84  if (required)
85  {
86  ROS_ERROR_STREAM_NAMED("parser", "Joint '" << joint_name << "' of transmission '" << transmission_name <<
87  "' does not specify the required <mechanicalReduction> element.");
88  }
89  else
90  {
91  ROS_DEBUG_STREAM_NAMED("parser", "Joint '" << joint_name << "' of transmission '" << transmission_name <<
92  "' does not specify the optional <mechanicalReduction> element.");
93  }
94  return NO_DATA;
95  }
96 
97  // Cast to number
98  try {reduction = boost::lexical_cast<double>(reduction_el->GetText());}
99  catch (const boost::bad_lexical_cast&)
100  {
101  ROS_ERROR_STREAM_NAMED("parser", "Joint '" << joint_name << "' of transmission '" << transmission_name <<
102  "' specifies the <mechanicalReduction> element, but is not a number.");
103  return BAD_TYPE;
104  }
105  return SUCCESS;
106 }
107 
109 TransmissionLoader::getJointOffset(const TiXmlElement& parent_el,
110  const std::string& joint_name,
111  const std::string& transmission_name,
112  bool required,
113  double& offset)
114 {
115  // Get XML element
116  const TiXmlElement* offset_el = parent_el.FirstChildElement("offset");
117  if(!offset_el)
118  {
119  if (required)
120  {
121  ROS_ERROR_STREAM_NAMED("parser", "Joint '" << joint_name << "' of transmission '" << transmission_name <<
122  "' does not specify the required <offset> element.");
123  }
124  else
125  {
126  ROS_DEBUG_STREAM_NAMED("parser", "Joint '" << joint_name << "' of transmission '" << transmission_name <<
127  "' does not specify the optional <offset> element.");
128  }
129  return NO_DATA;
130  }
131 
132  // Cast to number
133  try {offset = boost::lexical_cast<double>(offset_el->GetText());}
134  catch (const boost::bad_lexical_cast&)
135  {
136  ROS_ERROR_STREAM_NAMED("parser", "Joint '" << joint_name << "' of transmission '" << transmission_name <<
137  "' specifies the <offset> element, but is not a number.");
138  return BAD_TYPE;
139  }
140  return SUCCESS;
141 }
142 
144 TransmissionLoader::getActuatorRole(const TiXmlElement& parent_el,
145  const std::string& actuator_name,
146  const std::string& transmission_name,
147  bool required,
148  std::string& role)
149 {
150  // Get XML element
151  const TiXmlElement* role_el = parent_el.FirstChildElement("role");
152  if(!role_el)
153  {
154  if (required)
155  {
156  ROS_ERROR_STREAM_NAMED("parser", "Actuator '" << actuator_name << "' of transmission '" << transmission_name <<
157  "' does not specify the required <role> element.");
158  }
159  else
160  {
161  ROS_DEBUG_STREAM_NAMED("parser", "Actuator '" << actuator_name << "' of transmission '" << transmission_name <<
162  "' does not specify the optional <offset> element.");
163  }
164  return NO_DATA;
165  }
166 
167  // Cast to number
168  if (!role_el->GetText())
169  {
170  if (required)
171  {
172  ROS_ERROR_STREAM_NAMED("parser", "Actuator '" << actuator_name << "' of transmission '" << transmission_name <<
173  "' specifies an empty <role> element.");
174  }
175  else
176  {
177  ROS_DEBUG_STREAM_NAMED("parser", "Actuator '" << actuator_name << "' of transmission '" << transmission_name <<
178  "' specifies an empty <role> element.");
179  }
180  return NO_DATA;
181  }
182  role = role_el->GetText();
183 
184  return SUCCESS;
185 }
186 
188 TransmissionLoader::getJointRole(const TiXmlElement& parent_el,
189  const std::string& joint_name,
190  const std::string& transmission_name,
191  bool required,
192  std::string& role)
193 {
194  // Get XML element
195  const TiXmlElement* role_el = parent_el.FirstChildElement("role");
196  if(!role_el)
197  {
198  if (required)
199  {
200  ROS_ERROR_STREAM_NAMED("parser", "Joint '" << joint_name << "' of transmission '" << transmission_name <<
201  "' does not specify the required <role> element.");
202  }
203  else
204  {
205  ROS_DEBUG_STREAM_NAMED("parser", "Joint '" << joint_name << "' of transmission '" << transmission_name <<
206  "' does not specify the optional <offset> element.");
207  }
208  return NO_DATA;
209  }
210 
211  // Cast to number
212  if (!role_el->GetText())
213  {
214  if (required)
215  {
216  ROS_ERROR_STREAM_NAMED("parser", "Joint '" << joint_name << "' of transmission '" << transmission_name <<
217  "' specifies an empty <role> element.");
218  }
219  else
220  {
221  ROS_DEBUG_STREAM_NAMED("parser", "Joint '" << joint_name << "' of transmission '" << transmission_name <<
222  "' specifies an empty <role> element.");
223  }
224  return NO_DATA;
225  }
226  role = role_el->GetText();
227 
228  return SUCCESS;
229 }
230 
231 } // namespace
#define ROS_DEBUG_STREAM_NAMED(name, args)
#define ROS_ERROR_STREAM_NAMED(name, args)
static ParseStatus getActuatorReduction(const TiXmlElement &parent_el, const std::string &actuator_name, const std::string &transmission_name, bool required, double &reduction)
static ParseStatus getActuatorRole(const TiXmlElement &parent_el, const std::string &actuator_name, const std::string &transmission_name, bool required, std::string &role)
static ParseStatus getJointRole(const TiXmlElement &parent_el, const std::string &joint_name, const std::string &transmission_name, bool required, std::string &role)
static ParseStatus getJointReduction(const TiXmlElement &parent_el, const std::string &joint_name, const std::string &transmission_name, bool required, double &reduction)
static ParseStatus getJointOffset(const TiXmlElement &parent_el, const std::string &joint_name, const std::string &transmission_name, bool required, double &offset)


transmission_interface
Author(s): Adolfo Rodriguez Tsouroukdissian
autogenerated on Mon Apr 20 2020 03:52:15