ros2_control - rolling
Loading...
Searching...
No Matches
hardware_info.hpp
1// Copyright 2020 ros2_control Development Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef HARDWARE_INTERFACE__HARDWARE_INFO_HPP_
16#define HARDWARE_INTERFACE__HARDWARE_INFO_HPP_
17
18#include <fmt/compile.h>
19
20#include <string>
21#include <unordered_map>
22#include <variant>
23#include <vector>
24
25#include "joint_limits/joint_limits.hpp"
26
27#ifdef TRUE
28#undef TRUE
29#endif
30
31#ifdef FALSE
32#undef FALSE
33#endif
34
35namespace hardware_interface
36{
42{
47 std::string name;
49 std::string min = "";
51 std::string max = "";
53 std::string initial_value = "";
55 std::string data_type = "double";
57 int size;
61 std::unordered_map<std::string, std::string> parameters;
64};
65
68{
69 std::size_t joint_index;
70 std::size_t mimicked_joint_index;
71 double multiplier = 1.0;
72 double offset = 0.0;
73};
74
77{
78 NOT_SET,
79 TRUE,
80 FALSE
81};
82
88{
90 std::string name;
92 std::string type;
93
95 MimicAttribute is_mimic = MimicAttribute::NOT_SET;
96
98 bool enable_limits = true;
99
104 std::vector<InterfaceInfo> command_interfaces;
109 std::vector<InterfaceInfo> state_interfaces;
111 std::unordered_map<std::string, std::string> parameters;
112};
113
116{
117 std::string name;
118 std::vector<std::string> state_interfaces;
119 std::vector<std::string> command_interfaces;
120 std::string role;
121 double mechanical_reduction = 1.0;
122 double offset = 0.0;
123 bool read_only = false;
124};
125
128{
129 std::string name;
130 std::vector<std::string> state_interfaces;
131 std::vector<std::string> command_interfaces;
132 std::string role;
133 double mechanical_reduction = 1.0;
134 double offset = 0.0;
135 bool read_only = false;
136};
137
140{
141 std::string name;
142 std::string type;
143 std::vector<JointInfo> joints;
144 std::vector<ActuatorInfo> actuators;
146 std::unordered_map<std::string, std::string> parameters;
147};
148
153using HANDLE_DATATYPE = std::variant<
154 std::monostate, double, float, bool, uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t>;
156{
157public:
158 enum Value : int8_t
159 {
160 UNKNOWN = -1,
161 DOUBLE,
162 FLOAT32,
163 BOOL,
164 UINT8,
165 INT8,
166 UINT16,
167 INT16,
168 UINT32,
169 INT32,
170 };
171
172 HandleDataType() = default;
173 constexpr HandleDataType(Value value) : value_(value) {} // NOLINT(runtime/explicit)
174 explicit HandleDataType(const std::string & data_type)
175 {
176 if (data_type == "double")
177 {
178 value_ = DOUBLE;
179 }
180 else if (data_type == "bool")
181 {
182 value_ = BOOL;
183 }
184 else if (data_type == "float32")
185 {
186 value_ = FLOAT32;
187 }
188 else if (data_type == "uint8")
189 {
190 value_ = UINT8;
191 }
192 else if (data_type == "int8")
193 {
194 value_ = INT8;
195 }
196 else if (data_type == "uint16")
197 {
198 value_ = UINT16;
199 }
200 else if (data_type == "int16")
201 {
202 value_ = INT16;
203 }
204 else if (data_type == "uint32")
205 {
206 value_ = UINT32;
207 }
208 else if (data_type == "int32")
209 {
210 value_ = INT32;
211 }
212 else
213 {
214 value_ = UNKNOWN;
215 }
216 }
217
218 operator Value() const { return value_; }
219
220 explicit operator bool() const = delete;
221
222 constexpr bool operator==(HandleDataType other) const { return value_ == other.value_; }
223 constexpr bool operator!=(HandleDataType other) const { return value_ != other.value_; }
224
225 constexpr bool operator==(Value other) const { return value_ == other; }
226 constexpr bool operator!=(Value other) const { return value_ != other; }
227
228 std::string to_string() const
229 {
230 switch (value_)
231 {
232 case DOUBLE:
233 return "double";
234 case BOOL:
235 return "bool";
236 case FLOAT32:
237 return "float32";
238 case UINT8:
239 return "uint8";
240 case INT8:
241 return "int8";
242 case UINT16:
243 return "uint16";
244 case INT16:
245 return "int16";
246 case UINT32:
247 return "uint32";
248 case INT32:
249 return "int32";
250 default:
251 return "unknown";
252 }
253 }
254
261 {
262 switch (value_)
263 {
264 case DOUBLE: // fallthrough
265 case FLOAT32: // fallthrough
266 case BOOL: // fallthrough
267 case UINT8: // fallthrough
268 case INT8: // fallthrough
269 case UINT16: // fallthrough
270 case INT16: // fallthrough
271 case UINT32: // fallthrough
272 case INT32:
273 return true;
274 default:
275 return false; // unknown type cannot be converted
276 }
277 }
278
286 double cast_to_double(const HANDLE_DATATYPE & value) const
287 {
288 switch (value_)
289 {
290 case DOUBLE:
291 return std::get<double>(value);
292 case FLOAT32:
293 return static_cast<double>(std::get<float>(value));
294 case BOOL:
295 return static_cast<double>(std::get<bool>(value));
296 case UINT8:
297 return static_cast<double>(std::get<uint8_t>(value));
298 case INT8:
299 return static_cast<double>(std::get<int8_t>(value));
300 case UINT16:
301 return static_cast<double>(std::get<uint16_t>(value));
302 case INT16:
303 return static_cast<double>(std::get<int16_t>(value));
304 case UINT32:
305 return static_cast<double>(std::get<uint32_t>(value));
306 case INT32:
307 return static_cast<double>(std::get<int32_t>(value));
308 default:
309 throw std::runtime_error(
310 fmt::format(FMT_COMPILE("Data type : '{}' cannot be casted to double."), to_string()));
311 }
312 }
313
314 HandleDataType from_string(const std::string & data_type) { return HandleDataType(data_type); }
315
316private:
317 Value value_ = UNKNOWN;
318};
319
325{
326 InterfaceDescription(const std::string & prefix_name_in, const InterfaceInfo & interface_info_in)
327 : prefix_name(prefix_name_in),
328 interface_info(interface_info_in),
330 {
331 }
332
336 std::string prefix_name;
337
342
346 std::string interface_name;
347
348 const std::string & get_prefix_name() const { return prefix_name; }
349
350 const std::string & get_interface_name() const { return interface_info.name; }
351
352 const std::string & get_name() const { return interface_name; }
353
354 const std::string & get_data_type_string() const { return interface_info.data_type; }
355
356 HandleDataType get_data_type() const { return HandleDataType(interface_info.data_type); }
357};
358
360{
364 std::string scheduling_policy = "synchronized";
366 std::vector<int> cpu_affinity_cores = {};
368 bool print_warnings = true;
369};
370
373{
375 std::string name;
377 std::string type;
379 std::string group;
381 unsigned int rw_rate;
389 std::unordered_map<std::string, std::string> hardware_parameters;
394 std::vector<ComponentInfo> joints;
398 std::vector<MimicJoint> mimic_joints;
403 std::vector<ComponentInfo> sensors;
408 std::vector<ComponentInfo> gpios;
413 std::vector<TransmissionInfo> transmissions;
417 std::string original_xml;
421 std::unordered_map<std::string, joint_limits::JointLimits> limits;
422
428 std::unordered_map<std::string, joint_limits::SoftJointLimits> soft_limits;
429};
430
431} // namespace hardware_interface
432#endif // HARDWARE_INTERFACE__HARDWARE_INFO_HPP_
Definition hardware_info.hpp:156
bool is_castable_to_double() const
Check if the HandleDataType can be casted to double.
Definition hardware_info.hpp:260
double cast_to_double(const HANDLE_DATATYPE &value) const
Cast the given value to double.
Definition hardware_info.hpp:286
Definition mujoco_system_interface.hpp:57
MimicAttribute
This enum is used to store the mimic attribute of a joint.
Definition hardware_info.hpp:77
std::variant< std::monostate, double, float, bool, uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t > HANDLE_DATATYPE
Definition hardware_info.hpp:154
Contains semantic info about a given actuator loaded from URDF for a transmission.
Definition hardware_info.hpp:128
Definition hardware_info.hpp:88
bool enable_limits
Whether limits are enabled for this component (set at joint level with <limits enable="....
Definition hardware_info.hpp:98
std::vector< InterfaceInfo > command_interfaces
Definition hardware_info.hpp:104
std::unordered_map< std::string, std::string > parameters
(Optional) Key-value pairs of component parameters, e.g. min/max values or serial number.
Definition hardware_info.hpp:111
std::vector< InterfaceInfo > state_interfaces
Definition hardware_info.hpp:109
std::string name
Name of the component.
Definition hardware_info.hpp:90
MimicAttribute is_mimic
Hold the value of the mimic attribute if given, NOT_SET otherwise.
Definition hardware_info.hpp:95
std::string type
Type of the component: sensor, joint, or GPIO.
Definition hardware_info.hpp:92
Definition hardware_info.hpp:360
bool print_warnings
Whether to print warnings when the async thread doesn't meet its deadline.
Definition hardware_info.hpp:368
std::string scheduling_policy
Scheduling policy for the async worker thread.
Definition hardware_info.hpp:364
int thread_priority
Thread priority for the async worker thread.
Definition hardware_info.hpp:362
std::vector< int > cpu_affinity_cores
CPU affinity cores for the async worker thread.
Definition hardware_info.hpp:366
This structure stores information about hardware defined in a robot's URDF.
Definition hardware_info.hpp:373
std::string type
Type of the hardware: actuator, sensor or system.
Definition hardware_info.hpp:377
std::vector< MimicJoint > mimic_joints
Definition hardware_info.hpp:398
std::string hardware_plugin_name
Name of the pluginlib plugin of the hardware that will be loaded.
Definition hardware_info.hpp:387
std::unordered_map< std::string, joint_limits::JointLimits > limits
Definition hardware_info.hpp:421
HardwareAsyncParams async_params
Async Parameters.
Definition hardware_info.hpp:385
std::unordered_map< std::string, std::string > hardware_parameters
(Optional) Key-value pairs for hardware parameters.
Definition hardware_info.hpp:389
std::string group
Hardware group to which the hardware belongs.
Definition hardware_info.hpp:379
bool is_async
Component is async.
Definition hardware_info.hpp:383
std::unordered_map< std::string, joint_limits::SoftJointLimits > soft_limits
Definition hardware_info.hpp:428
std::vector< ComponentInfo > gpios
Definition hardware_info.hpp:408
std::vector< ComponentInfo > joints
Definition hardware_info.hpp:394
std::string original_xml
Definition hardware_info.hpp:417
std::string name
Name of the hardware.
Definition hardware_info.hpp:375
std::vector< ComponentInfo > sensors
Definition hardware_info.hpp:403
std::vector< TransmissionInfo > transmissions
Definition hardware_info.hpp:413
unsigned int rw_rate
Component's read and write rates in Hz.
Definition hardware_info.hpp:381
Definition hardware_info.hpp:325
InterfaceInfo interface_info
Definition hardware_info.hpp:341
std::string interface_name
Definition hardware_info.hpp:346
std::string prefix_name
Definition hardware_info.hpp:336
Definition hardware_info.hpp:42
std::string max
(Optional) Maximal allowed values of the interface.
Definition hardware_info.hpp:51
std::string initial_value
(Optional) Initial value of the interface.
Definition hardware_info.hpp:53
std::string name
Definition hardware_info.hpp:47
int size
(Optional) If the handle is an array, the size of the array.
Definition hardware_info.hpp:57
std::string min
(Optional) Minimal allowed values of the interface.
Definition hardware_info.hpp:49
std::string data_type
(Optional) The datatype of the interface, e.g. "bool", "int".
Definition hardware_info.hpp:55
std::unordered_map< std::string, std::string > parameters
Definition hardware_info.hpp:61
bool enable_limits
(Optional) enable or disable the limits for the command interfaces
Definition hardware_info.hpp:63
Contains semantic info about a given joint loaded from URDF for a transmission.
Definition hardware_info.hpp:116
This structure stores information about a joint that is mimicking another joint.
Definition hardware_info.hpp:68
Contains semantic info about a given transmission loaded from URDF.
Definition hardware_info.hpp:140
std::unordered_map< std::string, std::string > parameters
(Optional) Key-value pairs of custom parameters
Definition hardware_info.hpp:146