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
27namespace hardware_interface
28{
34{
39 std::string name;
41 std::string min = "";
43 std::string max = "";
45 std::string initial_value = "";
47 std::string data_type = "double";
49 int size;
53 std::unordered_map<std::string, std::string> parameters;
56};
57
60{
61 std::size_t joint_index;
62 std::size_t mimicked_joint_index;
63 double multiplier = 1.0;
64 double offset = 0.0;
65};
66
69{
70 NOT_SET,
71 TRUE,
72 FALSE
73};
74
80{
82 std::string name;
84 std::string type;
85
87 MimicAttribute is_mimic = MimicAttribute::NOT_SET;
88
90 bool enable_limits = true;
91
96 std::vector<InterfaceInfo> command_interfaces;
101 std::vector<InterfaceInfo> state_interfaces;
103 std::unordered_map<std::string, std::string> parameters;
104};
105
108{
109 std::string name;
110 std::vector<std::string> state_interfaces;
111 std::vector<std::string> command_interfaces;
112 std::string role;
113 double mechanical_reduction = 1.0;
114 double offset = 0.0;
115 bool read_only = false;
116};
117
120{
121 std::string name;
122 std::vector<std::string> state_interfaces;
123 std::vector<std::string> command_interfaces;
124 std::string role;
125 double mechanical_reduction = 1.0;
126 double offset = 0.0;
127 bool read_only = false;
128};
129
132{
133 std::string name;
134 std::string type;
135 std::vector<JointInfo> joints;
136 std::vector<ActuatorInfo> actuators;
138 std::unordered_map<std::string, std::string> parameters;
139};
140
145using HANDLE_DATATYPE = std::variant<
146 std::monostate, double, float, bool, uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t>;
148{
149public:
150 enum Value : int8_t
151 {
152 UNKNOWN = -1,
153 DOUBLE,
154 FLOAT32,
155 BOOL,
156 UINT8,
157 INT8,
158 UINT16,
159 INT16,
160 UINT32,
161 INT32,
162 };
163
164 HandleDataType() = default;
165 constexpr HandleDataType(Value value) : value_(value) {} // NOLINT(runtime/explicit)
166 explicit HandleDataType(const std::string & data_type)
167 {
168 if (data_type == "double")
169 {
170 value_ = DOUBLE;
171 }
172 else if (data_type == "bool")
173 {
174 value_ = BOOL;
175 }
176 else if (data_type == "float32")
177 {
178 value_ = FLOAT32;
179 }
180 else if (data_type == "uint8")
181 {
182 value_ = UINT8;
183 }
184 else if (data_type == "int8")
185 {
186 value_ = INT8;
187 }
188 else if (data_type == "uint16")
189 {
190 value_ = UINT16;
191 }
192 else if (data_type == "int16")
193 {
194 value_ = INT16;
195 }
196 else if (data_type == "uint32")
197 {
198 value_ = UINT32;
199 }
200 else if (data_type == "int32")
201 {
202 value_ = INT32;
203 }
204 else
205 {
206 value_ = UNKNOWN;
207 }
208 }
209
210 operator Value() const { return value_; }
211
212 explicit operator bool() const = delete;
213
214 constexpr bool operator==(HandleDataType other) const { return value_ == other.value_; }
215 constexpr bool operator!=(HandleDataType other) const { return value_ != other.value_; }
216
217 constexpr bool operator==(Value other) const { return value_ == other; }
218 constexpr bool operator!=(Value other) const { return value_ != other; }
219
220 std::string to_string() const
221 {
222 switch (value_)
223 {
224 case DOUBLE:
225 return "double";
226 case BOOL:
227 return "bool";
228 case FLOAT32:
229 return "float32";
230 case UINT8:
231 return "uint8";
232 case INT8:
233 return "int8";
234 case UINT16:
235 return "uint16";
236 case INT16:
237 return "int16";
238 case UINT32:
239 return "uint32";
240 case INT32:
241 return "int32";
242 default:
243 return "unknown";
244 }
245 }
246
253 {
254 switch (value_)
255 {
256 case DOUBLE: // fallthrough
257 case FLOAT32: // fallthrough
258 case BOOL: // fallthrough
259 case UINT8: // fallthrough
260 case INT8: // fallthrough
261 case UINT16: // fallthrough
262 case INT16: // fallthrough
263 case UINT32: // fallthrough
264 case INT32:
265 return true;
266 default:
267 return false; // unknown type cannot be converted
268 }
269 }
270
278 double cast_to_double(const HANDLE_DATATYPE & value) const
279 {
280 switch (value_)
281 {
282 case DOUBLE:
283 return std::get<double>(value);
284 case FLOAT32:
285 return static_cast<double>(std::get<float>(value));
286 case BOOL:
287 return static_cast<double>(std::get<bool>(value));
288 case UINT8:
289 return static_cast<double>(std::get<uint8_t>(value));
290 case INT8:
291 return static_cast<double>(std::get<int8_t>(value));
292 case UINT16:
293 return static_cast<double>(std::get<uint16_t>(value));
294 case INT16:
295 return static_cast<double>(std::get<int16_t>(value));
296 case UINT32:
297 return static_cast<double>(std::get<uint32_t>(value));
298 case INT32:
299 return static_cast<double>(std::get<int32_t>(value));
300 default:
301 throw std::runtime_error(
302 fmt::format(FMT_COMPILE("Data type : '{}' cannot be casted to double."), to_string()));
303 }
304 }
305
306 HandleDataType from_string(const std::string & data_type) { return HandleDataType(data_type); }
307
308private:
309 Value value_ = UNKNOWN;
310};
311
317{
318 InterfaceDescription(const std::string & prefix_name_in, const InterfaceInfo & interface_info_in)
319 : prefix_name(prefix_name_in),
320 interface_info(interface_info_in),
322 {
323 }
324
328 std::string prefix_name;
329
334
338 std::string interface_name;
339
340 const std::string & get_prefix_name() const { return prefix_name; }
341
342 const std::string & get_interface_name() const { return interface_info.name; }
343
344 const std::string & get_name() const { return interface_name; }
345
346 const std::string & get_data_type_string() const { return interface_info.data_type; }
347
348 HandleDataType get_data_type() const { return HandleDataType(interface_info.data_type); }
349};
350
352{
356 std::string scheduling_policy = "synchronized";
358 std::vector<int> cpu_affinity_cores = {};
360 bool print_warnings = true;
361};
362
364#ifdef _MSC_VER
365#pragma warning(push)
366#pragma warning(disable : 4996)
367#else
368#pragma GCC diagnostic push
369#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
370#endif
372{
374 std::string name;
376 std::string type;
378 std::string group;
380 unsigned int rw_rate;
384 [[deprecated("Use async_params instead.")]] int thread_priority;
390 std::unordered_map<std::string, std::string> hardware_parameters;
395 std::vector<ComponentInfo> joints;
399 std::vector<MimicJoint> mimic_joints;
404 std::vector<ComponentInfo> sensors;
409 std::vector<ComponentInfo> gpios;
414 std::vector<TransmissionInfo> transmissions;
418 std::string original_xml;
422 std::unordered_map<std::string, joint_limits::JointLimits> limits;
423
429 std::unordered_map<std::string, joint_limits::SoftJointLimits> soft_limits;
430};
431#ifdef _MSC_VER
432#pragma warning(pop)
433#else
434#pragma GCC diagnostic pop
435#endif
436
437} // namespace hardware_interface
438#endif // HARDWARE_INTERFACE__HARDWARE_INFO_HPP_
Definition hardware_info.hpp:148
bool is_castable_to_double() const
Check if the HandleDataType can be casted to double.
Definition hardware_info.hpp:252
double cast_to_double(const HANDLE_DATATYPE &value) const
Cast the given value to double.
Definition hardware_info.hpp:278
Definition mujoco_system_interface.hpp:57
MimicAttribute
This enum is used to store the mimic attribute of a joint.
Definition hardware_info.hpp:69
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:146
Contains semantic info about a given actuator loaded from URDF for a transmission.
Definition hardware_info.hpp:120
Definition hardware_info.hpp:80
bool enable_limits
Whether limits are enabled for this component (set at joint level with <limits enable="....
Definition hardware_info.hpp:90
std::vector< InterfaceInfo > command_interfaces
Definition hardware_info.hpp:96
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:103
std::vector< InterfaceInfo > state_interfaces
Definition hardware_info.hpp:101
std::string name
Name of the component.
Definition hardware_info.hpp:82
MimicAttribute is_mimic
Hold the value of the mimic attribute if given, NOT_SET otherwise.
Definition hardware_info.hpp:87
std::string type
Type of the component: sensor, joint, or GPIO.
Definition hardware_info.hpp:84
Definition hardware_info.hpp:352
bool print_warnings
Whether to print warnings when the async thread doesn't meet its deadline.
Definition hardware_info.hpp:360
std::string scheduling_policy
Scheduling policy for the async worker thread.
Definition hardware_info.hpp:356
int thread_priority
Thread priority for the async worker thread.
Definition hardware_info.hpp:354
std::vector< int > cpu_affinity_cores
CPU affinity cores for the async worker thread.
Definition hardware_info.hpp:358
This structure stores information about hardware defined in a robot's URDF.
Definition hardware_info.hpp:372
std::string type
Type of the hardware: actuator, sensor or system.
Definition hardware_info.hpp:376
int thread_priority
Async thread priority.
Definition hardware_info.hpp:384
std::vector< MimicJoint > mimic_joints
Definition hardware_info.hpp:399
std::string hardware_plugin_name
Name of the pluginlib plugin of the hardware that will be loaded.
Definition hardware_info.hpp:388
std::unordered_map< std::string, joint_limits::JointLimits > limits
Definition hardware_info.hpp:422
HardwareAsyncParams async_params
Async Parameters.
Definition hardware_info.hpp:386
std::unordered_map< std::string, std::string > hardware_parameters
(Optional) Key-value pairs for hardware parameters.
Definition hardware_info.hpp:390
std::string group
Hardware group to which the hardware belongs.
Definition hardware_info.hpp:378
bool is_async
Component is async.
Definition hardware_info.hpp:382
std::unordered_map< std::string, joint_limits::SoftJointLimits > soft_limits
Definition hardware_info.hpp:429
std::vector< ComponentInfo > gpios
Definition hardware_info.hpp:409
std::vector< ComponentInfo > joints
Definition hardware_info.hpp:395
std::string original_xml
Definition hardware_info.hpp:418
std::string name
Name of the hardware.
Definition hardware_info.hpp:374
std::vector< ComponentInfo > sensors
Definition hardware_info.hpp:404
std::vector< TransmissionInfo > transmissions
Definition hardware_info.hpp:414
unsigned int rw_rate
Component's read and write rates in Hz.
Definition hardware_info.hpp:380
Definition hardware_info.hpp:317
InterfaceInfo interface_info
Definition hardware_info.hpp:333
std::string interface_name
Definition hardware_info.hpp:338
std::string prefix_name
Definition hardware_info.hpp:328
Definition hardware_info.hpp:34
std::string max
(Optional) Maximal allowed values of the interface.
Definition hardware_info.hpp:43
std::string initial_value
(Optional) Initial value of the interface.
Definition hardware_info.hpp:45
std::string name
Definition hardware_info.hpp:39
int size
(Optional) If the handle is an array, the size of the array.
Definition hardware_info.hpp:49
std::string min
(Optional) Minimal allowed values of the interface.
Definition hardware_info.hpp:41
std::string data_type
(Optional) The datatype of the interface, e.g. "bool", "int".
Definition hardware_info.hpp:47
std::unordered_map< std::string, std::string > parameters
Definition hardware_info.hpp:53
bool enable_limits
(Optional) enable or disable the limits for the command interfaces
Definition hardware_info.hpp:55
Contains semantic info about a given joint loaded from URDF for a transmission.
Definition hardware_info.hpp:108
This structure stores information about a joint that is mimicking another joint.
Definition hardware_info.hpp:60
Contains semantic info about a given transmission loaded from URDF.
Definition hardware_info.hpp:132
std::unordered_map< std::string, std::string > parameters
(Optional) Key-value pairs of custom parameters
Definition hardware_info.hpp:138