ros2_control - rolling
Loading...
Searching...
No Matches
handle.hpp
1// Copyright 2020 PAL Robotics S.L.
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__HANDLE_HPP_
16#define HARDWARE_INTERFACE__HANDLE_HPP_
17
18#include <fmt/compile.h>
19
20#include <algorithm>
21#include <cstdint>
22#include <cstdlib>
23#include <functional>
24#include <limits>
25#include <memory>
26#include <mutex>
27#include <optional>
28#include <shared_mutex>
29#include <stdexcept>
30#include <string>
31#include <type_traits>
32#include <typeinfo>
33#include <utility>
34#include <variant>
35
36#ifndef _WIN32
37#include <cxxabi.h>
38#endif
39
40#include "hardware_interface/hardware_info.hpp"
41#include "hardware_interface/introspection.hpp"
42#include "hardware_interface/lexical_casts.hpp"
43#include "hardware_interface/macros.hpp"
44
45#include "rclcpp/logging.hpp"
46
47namespace
48{
49#ifndef _WIN32
50template <typename T>
51std::string get_type_name()
52{
53 int status = 0;
54 std::unique_ptr<char[], void (*)(void *)> res{
55 abi::__cxa_demangle(typeid(T).name(), nullptr, nullptr, &status), std::free};
56 return (status == 0) ? res.get() : typeid(T).name();
57}
58#else
59// not supported on Windows, use typeid directly
60template <typename T>
61std::string get_type_name()
62{
63 return typeid(T).name();
64}
65#endif
66} // namespace
67
68namespace hardware_interface
69{
70
72class Handle
73{
74public:
75 explicit Handle(
76 const std::string & prefix_name, const std::string & interface_name,
77 const std::string & data_type = "double", const std::string & initial_value = "")
78 : prefix_name_(prefix_name),
79 interface_name_(interface_name),
80 handle_name_(prefix_name_ + "/" + interface_name_),
81 data_type_(data_type)
82 {
83 // we need to initialize according the type passed in interface description
84 if (data_type_ == hardware_interface::HandleDataType::DOUBLE)
85 {
86 try
87 {
88 value_ = initial_value.empty() ? std::numeric_limits<double>::quiet_NaN()
89 : hardware_interface::stod(initial_value);
90 }
91 catch (const std::invalid_argument & err)
92 {
93 throw std::invalid_argument(
94 fmt::format(
95 FMT_COMPILE("Invalid initial value: '{}' parsed for interface: '{}' with type: '{}'"),
96 initial_value, handle_name_, data_type_.to_string()));
97 }
98 }
99 else if (data_type_ == hardware_interface::HandleDataType::FLOAT32)
100 {
101 try
102 {
103 value_ = initial_value.empty()
104 ? std::numeric_limits<float>::quiet_NaN()
105 : static_cast<float>(hardware_interface::stof(initial_value));
106 }
107 catch (const std::invalid_argument & err)
108 {
109 throw std::invalid_argument(
110 fmt::format(
111 FMT_COMPILE("Invalid initial value: '{}' parsed for interface: '{}' with type: '{}'"),
112 initial_value, handle_name_, data_type_.to_string()));
113 }
114 }
115 else if (data_type_ == hardware_interface::HandleDataType::BOOL)
116 {
117 try
118 {
119 value_ = initial_value.empty() ? false : hardware_interface::parse_bool(initial_value);
120 }
121 catch (const std::invalid_argument & err)
122 {
123 throw std::invalid_argument(
124 fmt::format(
125 FMT_COMPILE("Invalid initial value: '{}' parsed for interface: '{}' with type: '{}'"),
126 initial_value, handle_name_, data_type_.to_string()));
127 }
128 }
129 else if (data_type_ == hardware_interface::HandleDataType::UINT8)
130 {
131 try
132 {
133 value_ = initial_value.empty()
134 ? static_cast<uint8_t>(std::numeric_limits<uint8_t>::max())
135 : static_cast<uint8_t>(hardware_interface::stoui8(initial_value));
136 }
137 catch (const std::invalid_argument & err)
138 {
139 throw std::invalid_argument(
140 fmt::format(
141 FMT_COMPILE("Invalid initial value: '{}' parsed for interface: '{}' with type: '{}'"),
142 initial_value, handle_name_, data_type_.to_string()));
143 }
144 }
145 else if (data_type_ == hardware_interface::HandleDataType::INT8)
146 {
147 try
148 {
149 value_ = initial_value.empty()
150 ? static_cast<int8_t>(std::numeric_limits<int8_t>::max())
151 : static_cast<int8_t>(hardware_interface::stoi8(initial_value));
152 }
153 catch (const std::invalid_argument & err)
154 {
155 throw std::invalid_argument(
156 fmt::format(
157 FMT_COMPILE("Invalid initial value: '{}' parsed for interface: '{}' with type: '{}'"),
158 initial_value, handle_name_, data_type_.to_string()));
159 }
160 }
161 else if (data_type_ == hardware_interface::HandleDataType::UINT16)
162 {
163 try
164 {
165 value_ = initial_value.empty()
166 ? static_cast<uint16_t>(std::numeric_limits<uint16_t>::max())
167 : static_cast<uint16_t>(hardware_interface::stoui16(initial_value));
168 }
169 catch (const std::invalid_argument & err)
170 {
171 throw std::invalid_argument(
172 fmt::format(
173 FMT_COMPILE("Invalid initial value: '{}' parsed for interface: '{}' with type: '{}'"),
174 initial_value, handle_name_, data_type_.to_string()));
175 }
176 }
177 else if (data_type_ == hardware_interface::HandleDataType::INT16)
178 {
179 try
180 {
181 value_ = initial_value.empty()
182 ? static_cast<int16_t>(std::numeric_limits<int16_t>::max())
183 : static_cast<int16_t>(hardware_interface::stoi16(initial_value));
184 }
185 catch (const std::invalid_argument & err)
186 {
187 throw std::invalid_argument(
188 fmt::format(
189 FMT_COMPILE("Invalid initial value: '{}' parsed for interface: '{}' with type: '{}'"),
190 initial_value, handle_name_, data_type_.to_string()));
191 }
192 }
193 else if (data_type_ == hardware_interface::HandleDataType::UINT32)
194 {
195 try
196 {
197 value_ = initial_value.empty()
198 ? static_cast<uint32_t>(std::numeric_limits<uint32_t>::max())
199 : static_cast<uint32_t>(hardware_interface::stoui32(initial_value));
200 }
201 catch (const std::invalid_argument & err)
202 {
203 throw std::invalid_argument(
204 fmt::format(
205 FMT_COMPILE("Invalid initial value: '{}' parsed for interface: '{}' with type: '{}'"),
206 initial_value, handle_name_, data_type_.to_string()));
207 }
208 }
209 else if (data_type_ == hardware_interface::HandleDataType::INT32)
210 {
211 try
212 {
213 value_ = initial_value.empty()
214 ? static_cast<int32_t>(std::numeric_limits<int32_t>::max())
215 : static_cast<int32_t>(hardware_interface::stoi32(initial_value));
216 }
217 catch (const std::invalid_argument & err)
218 {
219 throw std::invalid_argument(
220 fmt::format(
221 FMT_COMPILE("Invalid initial value: '{}' parsed for interface: '{}' with type: '{}'"),
222 initial_value, handle_name_, data_type_.to_string()));
223 }
224 }
225 else if (data_type_ == hardware_interface::HandleDataType::UINT64)
226 {
227 try
228 {
229 value_ = initial_value.empty()
230 ? static_cast<uint64_t>(std::numeric_limits<uint64_t>::max())
231 : static_cast<uint64_t>(hardware_interface::stoui64(initial_value));
232 }
233 catch (const std::invalid_argument & err)
234 {
235 throw std::invalid_argument(
236 fmt::format(
237 FMT_COMPILE("Invalid initial value: '{}' parsed for interface: '{}' with type: '{}'"),
238 initial_value, handle_name_, data_type_.to_string()));
239 }
240 }
241 else if (data_type_ == hardware_interface::HandleDataType::INT64)
242 {
243 try
244 {
245 value_ = initial_value.empty()
246 ? static_cast<int64_t>(std::numeric_limits<int64_t>::max())
247 : static_cast<int64_t>(hardware_interface::stoi64(initial_value));
248 }
249 catch (const std::invalid_argument & err)
250 {
251 throw std::invalid_argument(
252 fmt::format(
253 FMT_COMPILE("Invalid initial value: '{}' parsed for interface: '{}' with type: '{}'"),
254 initial_value, handle_name_, data_type_.to_string()));
255 }
256 }
257 else
258 {
259 throw std::runtime_error(
260 fmt::format(
261 FMT_COMPILE("Invalid data type: '{}' for interface: {}. Check supported types."),
262 data_type, handle_name_));
263 }
264 }
265
266 explicit Handle(const InterfaceDescription & interface_description)
267 : Handle(
268 interface_description.get_prefix_name(), interface_description.get_interface_name(),
269 interface_description.get_data_type_string(),
270 interface_description.interface_info.initial_value)
271 {
272 }
273
274 [[deprecated("Use InterfaceDescription for initializing the Interface")]]
275
276 explicit Handle(const std::string & interface_name)
277 : interface_name_(interface_name), handle_name_("/" + interface_name_)
278 {
279 }
280
281 [[deprecated("Use InterfaceDescription for initializing the Interface")]]
282
283 explicit Handle(const char * interface_name)
284 : interface_name_(interface_name), handle_name_("/" + interface_name_)
285 {
286 }
287
288 Handle(const Handle & other) noexcept { copy(other); }
289
290 Handle & operator=(const Handle & other)
291 {
292 if (this != &other)
293 {
294 copy(other);
295 }
296 return *this;
297 }
298
299 Handle(Handle && other) noexcept { swap(*this, other); }
300
301 Handle & operator=(Handle && other)
302 {
303 swap(*this, other);
304 return *this;
305 }
306
307 virtual ~Handle() = default;
308
309 const std::string & get_name() const { return handle_name_; }
310
311 const std::string & get_interface_name() const { return interface_name_; }
312
313 const std::string & get_prefix_name() const { return prefix_name_; }
314
325 template <typename T = double>
326 [[nodiscard]] std::optional<T> get_optional() const
327 {
328 std::shared_lock<std::shared_mutex> lock(handle_mutex_, std::try_to_lock);
329 return get_optional<T>(lock);
330 }
331
342 template <typename T = double>
343 [[nodiscard]] std::optional<T> get_optional(std::shared_lock<std::shared_mutex> & lock) const
344 {
345 if (!lock.owns_lock())
346 {
347 return std::nullopt;
348 }
349 // BEGIN (Handle export change): for backward compatibility
350 // TODO(saikishor) return value_ if old functionality is removed
351 if constexpr (std::is_same_v<T, double>)
352 {
353 switch (data_type_)
354 {
355 case HandleDataType::DOUBLE:
356 return std::get<double>(value_);
357 case HandleDataType::BOOL:
358 // TODO(christophfroehlich): replace with RCLCPP_WARN_ONCE once
359 // https://github.com/ros2/rclcpp/issues/2587
360 // is fixed
361 if (!notified_)
362 {
363 RCLCPP_WARN(
364 rclcpp::get_logger(get_name()), "%s",
365 fmt::format(
366 FMT_COMPILE(
367 "Casting bool to double for interface '{}'. Better use get_optional<bool>()."),
368 get_name())
369 .c_str());
370 notified_ = true;
371 }
372 return static_cast<double>(std::get<bool>(value_));
373 case HandleDataType::FLOAT32: // fallthrough
374 case HandleDataType::UINT8: // fallthrough
375 case HandleDataType::INT8: // fallthrough
376 case HandleDataType::UINT16: // fallthrough
377 case HandleDataType::INT16: // fallthrough
378 case HandleDataType::UINT32: // fallthrough
379 case HandleDataType::INT32: // fallthrough
380 case HandleDataType::UINT64: // fallthrough
381 case HandleDataType::INT64: // fallthrough
382 throw std::runtime_error(
383 fmt::format(
384 FMT_COMPILE(
385 "Data type: '{}' will not be casted to double for interface: {}. Use "
386 "get_optional<{}>() instead."),
387 data_type_.to_string(), get_name(), data_type_.to_string()));
388 default:
389 throw std::runtime_error(
390 fmt::format(
391 FMT_COMPILE("Data type: '{}' cannot be casted to double for interface: {}"),
392 data_type_.to_string(), get_name()));
393 }
394 }
395 try
396 {
397 return std::get<T>(value_);
398 }
399 catch (const std::bad_variant_access & err)
400 {
401 throw std::runtime_error(
402 fmt::format(
403 FMT_COMPILE("Invalid data type: '{}' access for interface: {} expected: '{}'"),
404 get_type_name<T>(), get_name(), data_type_.to_string()));
405 }
406 // END
407 }
408
421 template <
422 typename T, typename = std::enable_if_t<
423 !std::is_same_v<std::decay_t<T>, std::shared_lock<std::shared_mutex>>>>
424 [[nodiscard]] bool get_value(T & value, bool wait_for_lock) const
425 {
426 if (wait_for_lock)
427 {
428 std::shared_lock<std::shared_mutex> lock(handle_mutex_);
429 return get_value(lock, value);
430 }
431 else
432 {
433 std::shared_lock<std::shared_mutex> lock(handle_mutex_, std::try_to_lock);
434 return get_value(lock, value);
435 }
436 }
437
449 template <typename T>
450 [[nodiscard]] bool set_value(const T & value, bool wait_for_lock)
451 {
452 if (wait_for_lock)
453 {
454 std::unique_lock<std::shared_mutex> lock(handle_mutex_);
455 return set_value(lock, value);
456 }
457 else
458 {
459 std::unique_lock<std::shared_mutex> lock(handle_mutex_, std::try_to_lock);
460 return set_value(lock, value);
461 }
462 }
463
475 template <typename T>
476 [[nodiscard]] bool set_value(const T & value)
477 {
478 std::unique_lock<std::shared_mutex> lock(handle_mutex_, std::try_to_lock);
479 return set_value(lock, value);
480 }
481
494 template <typename T>
495 [[nodiscard]] bool set_value(std::unique_lock<std::shared_mutex> & lock, const T & value)
496 {
497 if (!lock.owns_lock())
498 {
499 return false;
500 }
501 if (!std::holds_alternative<T>(value_))
502 {
503 throw std::runtime_error(
504 fmt::format(
505 FMT_COMPILE("Invalid data type: '{}' access for interface: {} expected: '{}'"),
506 get_type_name<T>(), get_name(), data_type_.to_string()));
507 }
508 value_ = value;
509 return true;
510 }
511
512 std::shared_mutex & get_mutex() const { return handle_mutex_; }
513
514 HandleDataType get_data_type() const { return data_type_; }
515
517 bool is_castable_to_double() const { return data_type_.is_castable_to_double(); }
518
519 bool is_valid() const { return !std::holds_alternative<std::monostate>(value_); }
520
521protected:
531 template <typename T>
532 [[nodiscard]] bool get_value(std::shared_lock<std::shared_mutex> & lock, T & value) const
533 {
534 if (!lock.owns_lock())
535 {
536 return false;
537 }
538 // BEGIN (Handle export change): for backward compatibility
539 // TODO(saikishor) get value_ if old functionality is removed
540 if constexpr (std::is_same_v<T, double>)
541 {
542 switch (data_type_)
543 {
544 case HandleDataType::DOUBLE:
545 value = std::get<double>(value_);
546 return true;
547 case HandleDataType::BOOL:
548 // TODO(christophfroehlich): replace with RCLCPP_WARN_ONCE once
549 // https://github.com/ros2/rclcpp/issues/2587
550 // is fixed
551 if (!notified_)
552 {
553 RCLCPP_WARN(
554 rclcpp::get_logger(get_name()),
555 "Casting bool to double for interface: %s. Better use get_optional<bool>().",
556 get_name().c_str());
557 notified_ = true;
558 }
559 value = static_cast<double>(std::get<bool>(value_));
560 return true;
561 case HandleDataType::FLOAT32: // fallthrough
562 case HandleDataType::UINT8: // fallthrough
563 case HandleDataType::INT8: // fallthrough
564 case HandleDataType::UINT16: // fallthrough
565 case HandleDataType::INT16: // fallthrough
566 case HandleDataType::UINT32: // fallthrough
567 case HandleDataType::INT32: // fallthrough
568 case HandleDataType::UINT64: // fallthrough
569 case HandleDataType::INT64: // fallthrough
570 throw std::runtime_error(
571 fmt::format(
572 FMT_COMPILE(
573 "Data type: '{}' will not be casted to double for interface: {}. Use "
574 "get_optional<{}>() instead."),
575 data_type_.to_string(), get_name(), data_type_.to_string()));
576 default:
577 throw std::runtime_error(
578 fmt::format(
579 FMT_COMPILE("Data type: '{}' cannot be casted to double for interface: {}"),
580 data_type_.to_string(), get_name()));
581 }
582 }
583 try
584 {
585 value = std::get<T>(value_);
586 return true;
587 }
588 catch (const std::bad_variant_access & err)
589 {
590 throw std::runtime_error(
591 fmt::format(
592 FMT_COMPILE("Invalid data type: '{}' access for interface: {} expected: '{}'"),
593 get_type_name<T>(), get_name(), data_type_.to_string()));
594 }
595 }
596
597private:
598 void copy(const Handle & other) noexcept
599 {
600 std::scoped_lock lock(other.handle_mutex_, handle_mutex_);
602 interface_name_ = other.interface_name_;
603 handle_name_ = other.handle_name_;
604 value_ = other.value_;
605 data_type_ = other.data_type_;
606 }
607
608 void swap(Handle & first, Handle & second) noexcept
609 {
610 std::scoped_lock lock(first.handle_mutex_, second.handle_mutex_);
611 std::swap(first.prefix_name_, second.prefix_name_);
612 std::swap(first.interface_name_, second.interface_name_);
613 std::swap(first.handle_name_, second.handle_name_);
614 std::swap(first.value_, second.value_);
615 std::swap(first.data_type_, second.data_type_);
616 }
617
618protected:
620 std::string prefix_name_;
621 std::string interface_name_;
622 std::string handle_name_;
623 HANDLE_DATATYPE value_ = std::monostate{};
624 HandleDataType data_type_ = HandleDataType::DOUBLE;
625 // END
626 mutable std::shared_mutex handle_mutex_;
627
628private:
629 // TODO(christophfroehlich): remove once
630 // https://github.com/ros2/rclcpp/issues/2587
631 // is fixed
632 mutable bool notified_ = false;
633};
634
635class StateInterface : public Handle
636{
637public:
638 explicit StateInterface(const InterfaceDescription & interface_description)
639 : Handle(interface_description)
640 {
641 }
642
643 void registerIntrospection() const
644 {
645 if (!is_valid())
646 {
647 RCLCPP_WARN(
648 rclcpp::get_logger(get_name()),
649 "Cannot register state introspection for state interface: %s without a valid value "
650 "pointer or initialized value.",
651 get_name().c_str());
652 return;
653 }
654 if (data_type_.is_castable_to_double())
655 {
656 std::function<double()> f = [this]() { return data_type_.cast_to_double(value_); };
657 DEFAULT_REGISTER_ROS2_CONTROL_INTROSPECTION("state_interface." + get_name(), f);
658 }
659 }
660
661 void unregisterIntrospection() const
662 {
663 if (is_valid() && (data_type_.is_castable_to_double()))
664 {
665 DEFAULT_UNREGISTER_ROS2_CONTROL_INTROSPECTION("state_interface." + get_name());
666 }
667 }
668
669 StateInterface(const StateInterface & other) = default;
670
671 StateInterface(StateInterface && other) = default;
672
673 using Handle::Handle;
674
675 using SharedPtr = std::shared_ptr<StateInterface>;
676 using ConstSharedPtr = std::shared_ptr<const StateInterface>;
677};
678
679class CommandInterface : public Handle
680{
681public:
682 explicit CommandInterface(const InterfaceDescription & interface_description)
683 : Handle(interface_description)
684 {
685 }
687
692 CommandInterface(const CommandInterface & other) = delete;
693
694 CommandInterface(CommandInterface && other) noexcept
695 : Handle(std::move(other)),
696 is_command_limited_(other.is_command_limited_.load()),
697 on_set_command_limiter_(std::move(other.on_set_command_limiter_))
698 {
699 }
700
701 void set_on_set_command_limiter(std::function<double(double, bool &)> on_set_command_limiter)
702 {
703 on_set_command_limiter_ = on_set_command_limiter;
704 }
705
707
711 template <typename T>
712 [[nodiscard]] bool set_limited_value(const T & value)
713 {
714 if constexpr (std::is_same_v<T, double>)
715 {
716 // The limiter writes to a local flag that is then published atomically, as the flag is
717 // read concurrently by the introspection sampler and is_limited() outside handle_mutex_
718 bool is_limited = false;
719 const double limited_value = on_set_command_limiter_(value, is_limited);
720 is_command_limited_.store(is_limited, std::memory_order_relaxed);
721 return set_value(limited_value);
722 }
723 else
724 {
725 return set_value(value);
726 }
727 }
728
730
733 bool is_limited() const { return is_command_limited_.load(std::memory_order_relaxed); }
734
735 void registerIntrospection() const
736 {
737 if (!is_valid())
738 {
739 RCLCPP_WARN(
740 rclcpp::get_logger(get_name()),
741 "Cannot register command introspection for command interface: %s without a valid value "
742 "pointer or initialized value.",
743 get_name().c_str());
744 return;
745 }
746 if (data_type_.is_castable_to_double())
747 {
748 std::function<double()> f = [this]() { return data_type_.cast_to_double(value_); };
749 DEFAULT_REGISTER_ROS2_CONTROL_INTROSPECTION("command_interface." + get_name(), f);
750 std::function<bool()> is_limited_fn = [this]() { return is_limited(); };
751 DEFAULT_REGISTER_ROS2_CONTROL_INTROSPECTION(
752 "command_interface." + get_name() + ".is_limited", is_limited_fn);
753 }
754 }
755
756 void unregisterIntrospection() const
757 {
758 if (is_valid() && data_type_.is_castable_to_double())
759 {
760 DEFAULT_UNREGISTER_ROS2_CONTROL_INTROSPECTION("command_interface." + get_name());
761 DEFAULT_UNREGISTER_ROS2_CONTROL_INTROSPECTION(
762 "command_interface." + get_name() + ".is_limited");
763 }
764 }
765
766 using Handle::Handle;
767
768 using SharedPtr = std::shared_ptr<CommandInterface>;
769
770private:
771 std::atomic<bool> is_command_limited_ = false;
772 std::function<double(double, bool &)> on_set_command_limiter_ =
773 [](double value, bool & is_limited)
774 {
775 is_limited = false;
776 return value;
777 };
778};
779
780} // namespace hardware_interface
781
782#endif // HARDWARE_INTERFACE__HANDLE_HPP_
bool is_limited() const
Returns whether the last value set through set_limited_value() was limited.
Definition handle.hpp:733
bool set_limited_value(const T &value)
A setter for the value of the command interface that triggers the limiter.
Definition handle.hpp:712
CommandInterface(const CommandInterface &other)=delete
CommandInterface copy constructor is actively deleted.
Definition hardware_info.hpp:159
bool is_castable_to_double() const
Check if the HandleDataType can be casted to double.
Definition hardware_info.hpp:278
double cast_to_double(const HANDLE_DATATYPE &value) const
Cast the given value to double.
Definition hardware_info.hpp:304
A handle used to get and set a value on a given interface.
Definition handle.hpp:73
bool set_value(const T &value)
Set the value of the handle.
Definition handle.hpp:476
bool get_value(std::shared_lock< std::shared_mutex > &lock, T &value) const
Get the value of the handle.
Definition handle.hpp:532
std::optional< T > get_optional(std::shared_lock< std::shared_mutex > &lock) const
Get the value of the handle.
Definition handle.hpp:343
bool get_value(T &value, bool wait_for_lock) const
Get the value of the handle.
Definition handle.hpp:424
bool is_castable_to_double() const
Returns true if the handle data type can be casted to double.
Definition handle.hpp:517
std::string prefix_name_
Definition handle.hpp:620
bool set_value(std::unique_lock< std::shared_mutex > &lock, const T &value)
Set the value of the handle.
Definition handle.hpp:495
bool set_value(const T &value, bool wait_for_lock)
Set the value of the handle.
Definition handle.hpp:450
std::optional< T > get_optional() const
Get the value of the handle.
Definition handle.hpp:326
Definition mujoco_system_interface.hpp:57
float stof(const std::string &s)
Helper function to convert a std::string to float in a locale-independent way.
Definition lexical_casts.cpp:116
double stod(const std::string &s)
Helper function to convert a std::string to double in a locale-independent way.
Definition lexical_casts.cpp:107
bool parse_bool(const std::string &bool_string)
Parse a boolean value from a string.
Definition lexical_casts.cpp:134
std::variant< std::monostate, double, float, bool, uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t > HANDLE_DATATYPE
Definition hardware_info.hpp:155
Definition hardware_info.hpp:344
InterfaceInfo interface_info
Definition hardware_info.hpp:360
std::string initial_value
(Optional) Initial value of the interface.
Definition hardware_info.hpp:55