15 #ifndef HARDWARE_INTERFACE__LOANED_STATE_INTERFACE_HPP_
16 #define HARDWARE_INTERFACE__LOANED_STATE_INTERFACE_HPP_
24 #include "hardware_interface/handle.hpp"
25 #include "rclcpp/logging.hpp"
31 using Deleter = std::function<void(
void)>;
41 : state_interface_(state_interface), deleter_(std::forward<Deleter>(deleter))
51 : state_interface_(*state_interface), deleter_(std::forward<Deleter>(deleter))
61 auto logger = rclcpp::get_logger(state_interface_.get_name());
62 RCLCPP_WARN_EXPRESSION(
64 (get_value_statistics_.failed_counter > 0 || get_value_statistics_.timeout_counter > 0),
65 "LoanedStateInterface %s has %u (%.4f %%) timeouts and %u (%.4f %%) missed calls out of %u "
67 state_interface_.get_name().c_str(), get_value_statistics_.timeout_counter,
68 (get_value_statistics_.timeout_counter * 100.0) / get_value_statistics_.total_counter,
69 get_value_statistics_.failed_counter,
70 (get_value_statistics_.failed_counter * 10.0) / get_value_statistics_.total_counter,
71 get_value_statistics_.total_counter);
78 const std::string & get_name()
const {
return state_interface_.get_name(); }
80 const std::string & get_interface_name()
const {
return state_interface_.get_interface_name(); }
83 "Replaced by get_name method, which is semantically more correct")]]
const std::string
86 return state_interface_.get_name();
89 const std::string & get_prefix_name()
const {
return state_interface_.get_prefix_name(); }
91 double get_value()
const
100 return std::numeric_limits<double>::quiet_NaN();
104 template <
typename T>
105 [[nodiscard]]
bool get_value(T & value,
unsigned int max_tries = 10)
const
107 unsigned int nr_tries = 0;
108 ++get_value_statistics_.total_counter;
109 while (!state_interface_.get_value(value))
111 ++get_value_statistics_.failed_counter;
113 if (nr_tries == max_tries)
115 ++get_value_statistics_.timeout_counter;
118 std::this_thread::yield();
128 struct HandleRTStatistics
130 unsigned int total_counter = 0;
131 unsigned int failed_counter = 0;
132 unsigned int timeout_counter = 0;
134 mutable HandleRTStatistics get_value_statistics_;
Definition: loaned_state_interface.hpp:29
Definition: handle.hpp:203
Definition: actuator.hpp:33