transmission_interface_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 <map>
37 #include <string>
38 #include <utility>
39 #include <vector>
40 #include <memory>
41 
42 // ROS
43 #include <ros/console.h>
44 
45 // pluginlib
47 
48 // ros_control
55 
62 
63 namespace transmission_interface
64 {
65 
72 // TODO: Don't assume interfaces?
74 {
75  double position = {std::numeric_limits<double>::quiet_NaN()};
76  double velocity = {std::numeric_limits<double>::quiet_NaN()};
77  double effort = {std::numeric_limits<double>::quiet_NaN()};
78  double position_cmd = {std::numeric_limits<double>::quiet_NaN()};
79  double velocity_cmd = {std::numeric_limits<double>::quiet_NaN()};
80  double effort_cmd = {std::numeric_limits<double>::quiet_NaN()};
81  double absolute_position = {std::numeric_limits<double>::quiet_NaN()};
82  double torque_sensor = {std::numeric_limits<double>::quiet_NaN()};
83 
84  bool hasAbsolutePosition = {true};
85  bool hasTorqueSensor = {true};
86 };
87 
88 typedef std::map<std::string, RawJointData> RawJointDataMap;
89 
94 {
99 };
100 
102 {
107 };
108 
110 {
115 };
116 
118 {
119  hardware_interface::RobotHW* robot_hw = {nullptr};
120  RobotTransmissions* robot_transmissions = {nullptr};
122  RawJointDataMap raw_joint_data_map;
125  std::vector<TransmissionSharedPtr> transmission_data;
126 };
127 
128 class RequisiteProvider // TODO: There must be a more descriptive name for this class!
129 {
130 public:
131  virtual ~RequisiteProvider() = default;
132 
147  virtual bool updateJointInterfaces(const TransmissionInfo& transmission_info,
148  hardware_interface::RobotHW* robot_hw,
149  JointInterfaces& joint_interfaces,
150  RawJointDataMap& raw_joint_data_map) = 0;
151 
152  bool loadTransmissionMaps(const TransmissionInfo& transmission_info,
153  TransmissionLoaderData& loader_data,
154  TransmissionSharedPtr transmission);
155 protected:
157  {
158  std::string name;
164  };
165 
166  virtual bool getJointStateData(const TransmissionInfo& transmission_info,
167  const RawJointDataMap& raw_joint_data_map,
168  JointData& jnt_state_data) = 0;
169 
170  virtual bool getJointCommandData(const TransmissionInfo& transmission_info,
171  const RawJointDataMap& raw_joint_data_map,
172  JointData& jnt_cmd_data) = 0;
173 
174  virtual bool getActuatorStateData(const TransmissionInfo& transmission_info,
175  hardware_interface::RobotHW* robot_hw,
176  ActuatorData& act_state_data) = 0;
177 
178  virtual bool getActuatorCommandData(const TransmissionInfo& transmission_info,
179  hardware_interface::RobotHW* robot_hw,
180  ActuatorData& act_cmd_data) = 0;
181 
182  virtual bool registerTransmission(TransmissionLoaderData& loader_data,
183  TransmissionHandleData& handle_data) = 0;
184 
185  template <class Interface>
186  static bool hasResource(const std::string& name, const Interface& iface)
187  {
189 
190  // Do nothing if resource already exists on the interface
191  const std::vector<std::string>& existing_resources = iface.getNames();
192  if (existing_resources.end() != std::find(existing_resources.begin(), existing_resources.end(), name))
193  {
194  ROS_DEBUG_STREAM_NAMED("parser", "Resource '" << name << "' already exists on interface '" <<
195  demangledTypeName<Interface>());
196  return true;
197  }
198  else
199  {
200  ROS_DEBUG_STREAM_NAMED("parser", "Resource '" << name << "' does not exist on interface '" <<
201  demangledTypeName<Interface>());
202  return false;
203  }
204  }
205 
206  template <class HardwareInterface, class Handle>
207  bool getActuatorHandles(const std::vector<ActuatorInfo>& actuators_info,
208  hardware_interface::RobotHW* robot_hw,
209  std::vector<Handle>& handles)
210  {
214 
215  HardwareInterface* hw_iface = robot_hw->get<HardwareInterface>();
216 
217  // Check required hardware interface
218  if (!hw_iface)
219  {
220  ROS_ERROR_STREAM_NAMED("parser", "Robot does not have the required hardware interface '" <<
221  demangledTypeName<HardwareInterface>() << "'.");
222  return false;
223  }
224 
225  // Get handles to all required resource
226  for (const auto& info : actuators_info)
227  {
228  try
229  {
230  handles.push_back(hw_iface->getHandle(info.name_));
231  }
232  catch(const HardwareInterfaceException& ex)
233  {
234  ROS_ERROR_STREAM_NAMED("parser", "Actuator '" << info.name_ <<
235  "' does not expose the required hardware interface '" <<
236  demangledTypeName<HardwareInterface>() << "'.");
237  return false;
238  }
239  }
240  return true;
241  }
242 };
243 
318 {
319 public:
325  RobotTransmissions* robot_transmissions);
326 
335  bool load(const std::string& urdf);
336 
345  bool load(const std::vector<TransmissionInfo>& transmission_info_vec);
346 
355  bool load(const TransmissionInfo& transmission_info);
356 
357  TransmissionLoaderData* getData() {return &loader_data_;}
358 
359 private:
361  typedef std::shared_ptr<TransmissionClassLoader> TransmissionClassLoaderPtr;
363  typedef std::shared_ptr<RequisiteProviderClassLoader> RequisiteProviderClassLoaderPtr;
364 
365  typedef std::shared_ptr<RequisiteProvider> RequisiteProviderPtr;
366 
367  TransmissionClassLoaderPtr transmission_class_loader_;
368  RequisiteProviderClassLoaderPtr req_provider_loader_;
369 
370 private:
373 
375 };
376 
377 } // namespace
bool getActuatorHandles(const std::vector< ActuatorInfo > &actuators_info, hardware_interface::RobotHW *robot_hw, std::vector< Handle > &handles)
#define ROS_DEBUG_STREAM_NAMED(name, args)
#define ROS_ERROR_STREAM_NAMED(name, args)
Contains pointers to raw data representing the position, velocity and acceleration of a transmission&#39;...
Definition: transmission.h:63
Parses <transmission> elements into corresponding structs from XML (URDF).
Contains semantic info about a given transmission loaded from XML (URDF)
std::shared_ptr< RequisiteProviderClassLoader > RequisiteProviderClassLoaderPtr
hardware_interface::VelocityJointInterface velocity_joint_interface
std::shared_ptr< TransmissionClassLoader > TransmissionClassLoaderPtr
Class for loading transmissions from a URDF description into ros_control interfaces.
hardware_interface::EffortJointInterface effort_joint_interface
Joint interfaces of a robot. Only used interfaces need to be populated.
Structs to hold transmission data loaded straight from XML (URDF).
static bool hasResource(const std::string &name, const Interface &iface)
hardware_interface::JointStateInterface joint_state_interface
pluginlib::ClassLoader< TransmissionLoader > TransmissionClassLoader
pluginlib::ClassLoader< RequisiteProvider > RequisiteProviderClassLoader
Contains pointers to raw data representing the position, velocity and acceleration of a transmission&#39;...
Definition: transmission.h:50
std::shared_ptr< Transmission > TransmissionSharedPtr
Definition: transmission.h:184
hardware_interface::PositionJointInterface position_joint_interface
std::map< std::string, RawJointData > RawJointDataMap


transmission_interface
Author(s): Adolfo Rodriguez Tsouroukdissian
autogenerated on Mon Feb 28 2022 23:30:26