32 using Deleter = std::function<void(
void)>;
40 : command_interface_(*command_interface), deleter_(std::forward<Deleter>(deleter))
50 auto logger = rclcpp::get_logger(command_interface_.get_name());
51 RCLCPP_WARN_EXPRESSION(
52 rclcpp::get_logger(get_name()),
53 (get_value_statistics_.failed_counter > 0 || get_value_statistics_.timeout_counter > 0),
54 "LoanedCommandInterface %s has %u (%.4f %%) timeouts and %u (~ %.4f %%) missed calls out of "
56 get_name().c_str(), get_value_statistics_.timeout_counter,
57 (get_value_statistics_.timeout_counter * 100.0) / get_value_statistics_.total_counter,
58 get_value_statistics_.failed_counter,
59 (get_value_statistics_.failed_counter * 100.0) / get_value_statistics_.total_counter,
60 get_value_statistics_.total_counter);
61 RCLCPP_WARN_EXPRESSION(
62 rclcpp::get_logger(get_name()),
63 (set_value_statistics_.failed_counter > 0 || set_value_statistics_.timeout_counter > 0),
64 "LoanedCommandInterface %s has %u (%.4f %%) timeouts and %u (~ %.4f %%) missed calls out of "
66 get_name().c_str(), set_value_statistics_.timeout_counter,
67 (set_value_statistics_.timeout_counter * 100.0) / set_value_statistics_.total_counter,
68 set_value_statistics_.failed_counter,
69 (set_value_statistics_.failed_counter * 100.0) / set_value_statistics_.total_counter,
70 set_value_statistics_.total_counter);
77 const std::string & get_name()
const {
return command_interface_.get_name(); }
79 const std::string & get_interface_name()
const {
return command_interface_.get_interface_name(); }
81 const std::string & get_prefix_name()
const {
return command_interface_.get_prefix_name(); }
99 [[nodiscard]]
bool set_value(
const T & value,
unsigned int max_tries = 10)
101 unsigned int nr_tries = 0;
102 ++set_value_statistics_.total_counter;
105 ++set_value_statistics_.failed_counter;
107 if (nr_tries == max_tries)
109 ++set_value_statistics_.timeout_counter;
112 std::this_thread::yield();
118 "Use std::optional<T> get_optional() instead to retrieve the value. This method will be "
119 "removed by the ROS 2 Lyrical Luth release.")]]
120 double get_value()
const
123 if (opt_value.has_value())
125 return opt_value.value();
129 return std::numeric_limits<double>::quiet_NaN();
147 template <
typename T =
double>
148 [[nodiscard]] std::optional<T>
get_optional(
unsigned int max_tries = 10)
const
150 unsigned int nr_tries = 0;
153 ++get_value_statistics_.total_counter;
154 const std::optional<T> data = command_interface_.
get_optional<T>();
155 if (data.has_value())
159 ++get_value_statistics_.failed_counter;
161 std::this_thread::yield();
162 }
while (nr_tries < max_tries);
164 ++get_value_statistics_.timeout_counter;
185 struct HandleRTStatistics
187 unsigned int total_counter = 0;
188 unsigned int failed_counter = 0;
189 unsigned int timeout_counter = 0;
191 mutable HandleRTStatistics get_value_statistics_;
192 HandleRTStatistics set_value_statistics_;