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