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(); }
88 const std::string & get_prefix_name()
const {
return command_interface_.get_prefix_name(); }
105 template <
typename T>
106 [[nodiscard]]
bool set_value(
const T & value,
unsigned int max_tries = 10)
108 unsigned int nr_tries = 0;
109 ++set_value_statistics_.total_counter;
112 ++set_value_statistics_.failed_counter;
114 if (nr_tries == max_tries)
116 ++set_value_statistics_.timeout_counter;
119 std::this_thread::yield();
125 "Use std::optional<T> get_optional() instead to retrieve the value. This method will be "
126 "removed by the ROS 2 Kilted Kaiju release.")]]
127 double get_value()
const
130 if (opt_value.has_value())
132 return opt_value.value();
136 return std::numeric_limits<double>::quiet_NaN();
154 template <
typename T =
double>
155 [[nodiscard]] std::optional<T>
get_optional(
unsigned int max_tries = 10)
const
157 unsigned int nr_tries = 0;
160 ++get_value_statistics_.total_counter;
161 const std::optional<T> data = command_interface_.
get_optional<T>();
162 if (data.has_value())
166 ++get_value_statistics_.failed_counter;
168 std::this_thread::yield();
169 }
while (nr_tries < max_tries);
171 ++get_value_statistics_.timeout_counter;
192 struct HandleRTStatistics
194 unsigned int total_counter = 0;
195 unsigned int failed_counter = 0;
196 unsigned int timeout_counter = 0;
198 mutable HandleRTStatistics get_value_statistics_;
199 HandleRTStatistics set_value_statistics_;