qb_device_hardware_resources.h
Go to the documentation of this file.
1 /***
2  * Software License Agreement: BSD 3-Clause License
3  *
4  * Copyright (c) 2016-2018, qbrobotics®
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
8  * following conditions are met:
9  *
10  * * Redistributions of source code must retain the above copyright notice, this list of conditions and the
11  * following disclaimer.
12  *
13  * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
14  * following disclaimer in the documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
17  * products derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
25  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef QB_DEVICE_HARDWARE_INTERFACE_RESOURCES_H
29 #define QB_DEVICE_HARDWARE_INTERFACE_RESOURCES_H
30 
31 //TODO: maybe hardware_interface::qb_device:: would be a better namespace (it could simplify names inside)
37  public:
43  : qbDeviceResources(1) {}
44 
51  qbDeviceResources(const int &signed_id)
52  : motor_axis_direction((0 < signed_id) - (signed_id < 0)),
53  id(std::abs(signed_id)),
54  max_repeats(3),
55  get_currents(true),
56  get_positions(true),
57  get_distinct_packages(false),
58  set_commands(true),
59  set_commands_async(false) {
60  // qbhand uses only a subset of the followings
61  position_limits.resize(4); // qbmove has two motors
62  encoder_resolutions.resize(3); // qbmove has one encoder per motor and one for the shaft
63  }
64 
68  virtual ~qbDeviceResources() {}
69 
70  // device info
71  int id;
73  std::string name; // device name is chosen to properly set ROS namespaces to avoid name clashes
74  std::string serial_port; // serial port to which the device is connected
75  std::vector<int> position_limits; // lower and upper limits for each motor [ticks]
76  std::vector<int> encoder_resolutions; // used to convert from [ticks] to [radians/degrees] and vice versa
77 
78  // read/write settings for the current device
79  int max_repeats; // max number of consecutive repetitions to mark retrieved data as corrupted
80  bool get_currents; // specify if motor currents are retrieved at each control loop
81  bool get_positions; // specify if motor positions are retrieved at each control loop
82  bool get_distinct_packages; // old devices cannot retrieve current and position measurements in a single package
83  bool set_commands; // specify if command references are sent at each control loop
84  bool set_commands_async; // specify if command references are sent in a non-blocking fashion
85 };
86 
95  public:
100 
106  qbDeviceHWResources(const int &joint_size) {
107  // no known names
108  setNumberOfJoints(joint_size);
109  }
110 
117  qbDeviceHWResources(const std::vector<std::string> &joints) {
118  setJoints(joints);
119  }
120 
124  virtual ~qbDeviceHWResources() {}
125 
132  inline void setJoints(const std::vector<std::string> &joints) {
133  names = joints;
134  setNumberOfJoints(joints.size());
135  }
136 
141  inline void setNumberOfJoints(const int &joint_size) {
142  names.resize(joint_size); // redundant if called by `setJoints`, yet non destructive
143  // automatically initialized with zeros
144  positions.resize(joint_size);
145  velocities.resize(joint_size);
146  efforts.resize(joint_size);
147  commands.resize(joint_size);
148  limits.resize(joint_size);
149  soft_limits.resize(joint_size);
150  }
151 
158  inline void setReliability(const int &max_repeats, const int &consecutive_failures) {
159  this->consecutive_failures = consecutive_failures;
160  this->is_reliable = consecutive_failures >= 0 && consecutive_failures <= max_repeats;
161  }
162 
163  std::vector<std::string> names;
164  std::vector<double> positions;
165  std::vector<double> velocities;
166  std::vector<double> efforts;
167  std::vector<double> commands;
168  std::vector<joint_limits_interface::JointLimits> limits;
169  std::vector<joint_limits_interface::SoftJointLimits> soft_limits;
170  ros::Time stamp; // actual time stamp of stored measurements
171  bool is_reliable; // specify whether stored measurements are reliable or not
172  int consecutive_failures; // the number of consecutive failures while retrieving measurements from the device
173 };
174 
185  public:
191 
196 
205  for (int i=0; i<joints.names.size(); i++) {
206  hardware_interface::JointStateHandle joint_state_handle(joints.names.at(i), &joints.positions.at(i), &joints.velocities.at(i), &joints.efforts.at(i));
207  joint_state.registerHandle(joint_state_handle);
208  hardware_interface::JointHandle joint_position_handle(joint_state.getHandle(joints.names.at(i)), &joints.commands.at(i));
209  joint_position.registerHandle(joint_position_handle);
210  }
211 
212  robot->registerInterface(&joint_state);
213  robot->registerInterface(&joint_position);
214  }
215 
218 };
219 } // namespace qb_device_hardware_interface
220 
221 #endif // QB_DEVICE_HARDWARE_INTERFACE_RESOURCES_H
void setReliability(const int &max_repeats, const int &consecutive_failures)
Compare the given consecutive failures w.r.t.
The qbrobotics Device HardWare Resources contains vectors of named joints.
std::vector< joint_limits_interface::SoftJointLimits > soft_limits
void setNumberOfJoints(const int &joint_size)
Resize all the Resource members with the given size.
qbDeviceHWResources(const int &joint_size)
Construct the Resource specifying no joint names but only the size of all the members.
hardware_interface::PositionJointInterface joint_position
qbDeviceResources(const int &signed_id)
Construct the Resource from the "signed" device ID.
The qbrobotics Device HardWare Interfaces is a simple class aimed to group all the hardware_interface...
qbDeviceResources()
Construct the Resource with the default ID, 1.
qbDeviceHWResources(const std::vector< std::string > &joints)
Construct the Resource with the given vector of joint names.
The qbrobotics Device Resources contains just few device information.
void setJoints(const std::vector< std::string > &joints)
Initialize the joint names of the Resource with the given vector.
std::vector< joint_limits_interface::JointLimits > limits
void initialize(hardware_interface::RobotHW *robot, qbDeviceHWResources &joints)
Initialize the joint_state and joint_position HW interfaces with the given device Resource...


qb_device_hardware_interface
Author(s): qbrobotics®
autogenerated on Thu Jun 6 2019 19:46:29