32 using Deleter = std::function<void(
void)>;
42 : command_interface_(command_interface), deleter_(std::forward<Deleter>(deleter))
47 : command_interface_(*command_interface), deleter_(std::forward<Deleter>(deleter))
57 auto logger = rclcpp::get_logger(command_interface_.get_name());
58 RCLCPP_WARN_EXPRESSION(
59 rclcpp::get_logger(get_name()),
60 (get_value_statistics_.failed_counter > 0 || get_value_statistics_.timeout_counter > 0),
61 "LoanedCommandInterface %s has %u (%.4f %%) timeouts and %u (~ %.4f %%) missed calls out of "
63 get_name().c_str(), get_value_statistics_.timeout_counter,
64 (get_value_statistics_.timeout_counter * 100.0) / get_value_statistics_.total_counter,
65 get_value_statistics_.failed_counter,
66 (get_value_statistics_.failed_counter * 10.0) / get_value_statistics_.total_counter,
67 get_value_statistics_.total_counter);
68 RCLCPP_WARN_EXPRESSION(
69 rclcpp::get_logger(get_name()),
70 (set_value_statistics_.failed_counter > 0 || set_value_statistics_.timeout_counter > 0),
71 "LoanedCommandInterface %s has %u (%.4f %%) timeouts and %u (~ %.4f %%) missed calls out of "
73 get_name().c_str(), set_value_statistics_.timeout_counter,
74 (set_value_statistics_.timeout_counter * 100.0) / set_value_statistics_.total_counter,
75 set_value_statistics_.failed_counter,
76 (set_value_statistics_.failed_counter * 10.0) / set_value_statistics_.total_counter,
77 set_value_statistics_.total_counter);
84 const std::string & get_name()
const {
return command_interface_.get_name(); }
86 const std::string & get_interface_name()
const {
return command_interface_.get_interface_name(); }
89 "Replaced by get_name method, which is semantically more correct")]]
const std::string
92 return command_interface_.get_name();
95 const std::string & get_prefix_name()
const {
return command_interface_.get_prefix_name(); }
98 [[nodiscard]]
bool set_value(T value,
unsigned int max_tries = 10)
100 unsigned int nr_tries = 0;
101 ++set_value_statistics_.total_counter;
102 while (!command_interface_.set_value(value))
104 ++set_value_statistics_.failed_counter;
106 if (nr_tries == max_tries)
108 ++set_value_statistics_.timeout_counter;
111 std::this_thread::yield();
116 double get_value()
const
119 if (get_value(value))
125 return std::numeric_limits<double>::quiet_NaN();
129 template <
typename T>
130 [[nodiscard]]
bool get_value(T & value,
unsigned int max_tries = 10)
const
132 unsigned int nr_tries = 0;
133 ++get_value_statistics_.total_counter;
134 while (!command_interface_.get_value(value))
136 ++get_value_statistics_.failed_counter;
138 if (nr_tries == max_tries)
140 ++get_value_statistics_.timeout_counter;
143 std::this_thread::yield();
153 struct HandleRTStatistics
155 unsigned int total_counter = 0;
156 unsigned int failed_counter = 0;
157 unsigned int timeout_counter = 0;
159 mutable HandleRTStatistics get_value_statistics_;
160 HandleRTStatistics set_value_statistics_;