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 
35 bool
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  return false;
51  }
52  else
53  {
54  ROS_DEBUG_STREAM_NAMED("parser", "Actuator '" << actuator_name << "' of transmission '" << transmission_name <<
55  "' does not specify the optional <mechanicalReduction> element.");
56  return true;
57  }
58  }
59 
60  // Cast to number
61  try {reduction = std::stod(reduction_el->GetText());}
62  catch (const std::logic_error&) // Captures both std::invalid_argument and std::out_of_range
63  {
64  ROS_ERROR_STREAM_NAMED("parser", "Actuator '" << actuator_name << "' of transmission '" << transmission_name <<
65  "' specifies the <mechanicalReduction> element, but is not a number.");
66  return false;
67  }
68  return true;
69 }
70 
71 bool
72 TransmissionLoader::getJointReduction(const TiXmlElement& parent_el,
73  const std::string& joint_name,
74  const std::string& transmission_name,
75  bool required,
76  double& reduction)
77 {
78  // Get XML element
79  const TiXmlElement* reduction_el = parent_el.FirstChildElement("mechanicalReduction");
80  if(!reduction_el)
81  {
82  if (required)
83  {
84  ROS_ERROR_STREAM_NAMED("parser", "Joint '" << joint_name << "' of transmission '" << transmission_name <<
85  "' does not specify the required <mechanicalReduction> element.");
86  return false;
87  }
88  else
89  {
90  ROS_DEBUG_STREAM_NAMED("parser", "Joint '" << joint_name << "' of transmission '" << transmission_name <<
91  "' does not specify the optional <mechanicalReduction> element.");
92  return true;
93  }
94  }
95 
96  // Cast to number
97  try {reduction = std::stod(reduction_el->GetText());}
98  catch (const std::logic_error&) // Captures both std::invalid_argument and std::out_of_range
99  {
100  ROS_ERROR_STREAM_NAMED("parser", "Joint '" << joint_name << "' of transmission '" << transmission_name <<
101  "' specifies the <mechanicalReduction> element, but is not a number.");
102  return false;
103  }
104  return true;
105 }
106 
107 bool
108 TransmissionLoader::getJointOffset(const TiXmlElement& parent_el,
109  const std::string& joint_name,
110  const std::string& transmission_name,
111  bool required,
112  double& offset)
113 {
114  // Get XML element
115  const TiXmlElement* offset_el = parent_el.FirstChildElement("offset");
116  if(!offset_el)
117  {
118  if (required)
119  {
120  ROS_ERROR_STREAM_NAMED("parser", "Joint '" << joint_name << "' of transmission '" << transmission_name <<
121  "' does not specify the required <offset> element.");
122  return false;
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  return true;
129  }
130  }
131 
132  // Cast to number
133  try {offset = std::stod(offset_el->GetText());}
134  catch (const std::logic_error&) // Captures both std::invalid_argument and std::out_of_range
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 false;
139  }
140  return true;
141 }
142 
143 bool
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  return false;
159  }
160  else
161  {
162  ROS_DEBUG_STREAM_NAMED("parser", "Actuator '" << actuator_name << "' of transmission '" << transmission_name <<
163  "' does not specify the optional <offset> element.");
164  return true;
165  }
166  }
167 
168  // Cast to number
169  if (!role_el->GetText())
170  {
171  if (required)
172  {
173  ROS_ERROR_STREAM_NAMED("parser", "Actuator '" << actuator_name << "' of transmission '" << transmission_name <<
174  "' specifies an empty <role> element.");
175  return false;
176  }
177  else
178  {
179  ROS_DEBUG_STREAM_NAMED("parser", "Actuator '" << actuator_name << "' of transmission '" << transmission_name <<
180  "' specifies an empty <role> element.");
181  return true;
182  }
183  }
184  role = role_el->GetText();
185 
186  return true;
187 }
188 
189 bool
190 TransmissionLoader::getJointRole(const TiXmlElement& parent_el,
191  const std::string& joint_name,
192  const std::string& transmission_name,
193  bool required,
194  std::string& role)
195 {
196  // Get XML element
197  const TiXmlElement* role_el = parent_el.FirstChildElement("role");
198  if(!role_el)
199  {
200  if (required)
201  {
202  ROS_ERROR_STREAM_NAMED("parser", "Joint '" << joint_name << "' of transmission '" << transmission_name <<
203  "' does not specify the required <role> element.");
204  return false;
205  }
206  else
207  {
208  ROS_DEBUG_STREAM_NAMED("parser", "Joint '" << joint_name << "' of transmission '" << transmission_name <<
209  "' does not specify the optional <offset> element.");
210  return true;
211  }
212  }
213 
214  // Cast to number
215  if (!role_el->GetText())
216  {
217  if (required)
218  {
219  ROS_ERROR_STREAM_NAMED("parser", "Joint '" << joint_name << "' of transmission '" << transmission_name <<
220  "' specifies an empty <role> element.");
221  return false;
222  }
223  else
224  {
225  ROS_DEBUG_STREAM_NAMED("parser", "Joint '" << joint_name << "' of transmission '" << transmission_name <<
226  "' specifies an empty <role> element.");
227  return true;
228  }
229  }
230  role = role_el->GetText();
231 
232  return true;
233 }
234 
235 } // namespace
ROS_DEBUG_STREAM_NAMED
#define ROS_DEBUG_STREAM_NAMED(name, args)
transmission_interface
Definition: bidirectional_effort_joint_interface_provider.h:36
transmission_interface::TransmissionLoader::getActuatorReduction
static bool getActuatorReduction(const TiXmlElement &parent_el, const std::string &actuator_name, const std::string &transmission_name, bool required, double &reduction)
Definition: transmission_loader.cpp:36
transmission_loader.h
transmission_interface::TransmissionLoader::getActuatorRole
static bool getActuatorRole(const TiXmlElement &parent_el, const std::string &actuator_name, const std::string &transmission_name, bool required, std::string &role)
Definition: transmission_loader.cpp:144
ROS_ERROR_STREAM_NAMED
#define ROS_ERROR_STREAM_NAMED(name, args)
transmission_interface::TransmissionLoader::getJointRole
static bool getJointRole(const TiXmlElement &parent_el, const std::string &joint_name, const std::string &transmission_name, bool required, std::string &role)
Definition: transmission_loader.cpp:190
transmission_interface::TransmissionLoader::getJointReduction
static bool getJointReduction(const TiXmlElement &parent_el, const std::string &joint_name, const std::string &transmission_name, bool required, double &reduction)
Definition: transmission_loader.cpp:72
transmission_interface::TransmissionLoader::getJointOffset
static bool getJointOffset(const TiXmlElement &parent_el, const std::string &joint_name, const std::string &transmission_name, bool required, double &offset)
Definition: transmission_loader.cpp:108


transmission_interface
Author(s): Adolfo Rodriguez Tsouroukdissian
autogenerated on Tue Oct 15 2024 02:08:29