33 using Deleter = std::function<void(
void)>;
41 : command_interface_(command_interface),
42 interface_name_(command_interface->get_name()),
43 deleter_(std::forward<Deleter>(deleter))
53 if (command_interface_)
55 auto logger = rclcpp::get_logger(interface_name_);
56 RCLCPP_WARN_EXPRESSION(
58 (get_value_statistics_.failed_counter > 0 || get_value_statistics_.timeout_counter > 0),
59 "LoanedCommandInterface %s has %u (%.4f %%) timeouts and %u (~ %.4f %%) missed calls out "
62 interface_name_.c_str(), get_value_statistics_.timeout_counter,
63 (get_value_statistics_.timeout_counter * 100.0) / get_value_statistics_.total_counter,
64 get_value_statistics_.failed_counter,
65 (get_value_statistics_.failed_counter * 100.0) / get_value_statistics_.total_counter,
66 get_value_statistics_.total_counter);
67 RCLCPP_WARN_EXPRESSION(
69 (set_value_statistics_.failed_counter > 0 || set_value_statistics_.timeout_counter > 0),
70 "LoanedCommandInterface %s has %u (%.4f %%) timeouts and %u (~ %.4f %%) missed calls out "
73 interface_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 * 100.0) / set_value_statistics_.total_counter,
77 set_value_statistics_.total_counter);
85 const std::string & get_name()
const {
return command_interface_->get_name(); }
87 const std::string & get_interface_name()
const
89 return command_interface_->get_interface_name();
92 const std::string & get_prefix_name()
const {
return command_interface_->get_prefix_name(); }
109 template <
typename T>
110 [[nodiscard]]
bool set_value(
const T & value,
unsigned int max_tries = 10)
112 unsigned int nr_tries = 0;
113 ++set_value_statistics_.total_counter;
114 while (!command_interface_->set_limited_value(value))
116 ++set_value_statistics_.failed_counter;
118 if (nr_tries == max_tries)
120 ++set_value_statistics_.timeout_counter;
123 std::this_thread::yield();
129 "Use std::optional<T> get_optional() instead to retrieve the value. This method will be "
130 "removed by the ROS 2 Lyrical Luth release.")]]
131 double get_value()
const
134 if (opt_value.has_value())
136 return opt_value.value();
140 return std::numeric_limits<double>::quiet_NaN();
158 template <
typename T =
double>
159 [[nodiscard]] std::optional<T>
get_optional(
unsigned int max_tries = 10)
const
161 unsigned int nr_tries = 0;
164 ++get_value_statistics_.total_counter;
165 const std::optional<T> data = command_interface_->get_optional<T>();
166 if (data.has_value())
170 ++get_value_statistics_.failed_counter;
172 std::this_thread::yield();
173 }
while (nr_tries < max_tries);
175 ++get_value_statistics_.timeout_counter;
192 CommandInterface::SharedPtr command_interface_;
193 std::string interface_name_;
197 struct HandleRTStatistics
199 unsigned int total_counter = 0;
200 unsigned int failed_counter = 0;
201 unsigned int timeout_counter = 0;
203 mutable HandleRTStatistics get_value_statistics_;
204 HandleRTStatistics set_value_statistics_;