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(); }
112 template <
typename T>
113 [[nodiscard]]
bool set_value(
const T & value,
unsigned int max_tries = 10)
115 unsigned int nr_tries = 0;
116 ++set_value_statistics_.total_counter;
117 while (!command_interface_.
set_value(value))
119 ++set_value_statistics_.failed_counter;
121 if (nr_tries == max_tries)
123 ++set_value_statistics_.timeout_counter;
126 std::this_thread::yield();
132 "Use std::optional<T> get_optional() instead to retrieve the value. This method will be "
133 "removed by the ROS 2 Kilted Kaiju release.")]]
134 double get_value()
const
136 double value = std::numeric_limits<double>::quiet_NaN();
137 if (get_value(value))
143 return std::numeric_limits<double>::quiet_NaN();
161 template <
typename T =
double>
162 [[nodiscard]] std::optional<T>
get_optional(
unsigned int max_tries = 10)
const
164 unsigned int nr_tries = 0;
167 ++get_value_statistics_.total_counter;
168 const std::optional<T> data = command_interface_.
get_optional<T>();
169 if (data.has_value())
173 ++get_value_statistics_.failed_counter;
175 std::this_thread::yield();
176 }
while (nr_tries < max_tries);
178 ++get_value_statistics_.timeout_counter;
197 template <
typename T>
199 "Use std::optional<T> get_optional() instead to retrieve the value. This method will be "
200 "removed by the ROS 2 Kilted Kaiju release.")]] [[nodiscard]]
bool
203 unsigned int nr_tries = 0;
204 ++get_value_statistics_.total_counter;
205 while (!command_interface_.get_value(value))
207 ++get_value_statistics_.failed_counter;
209 if (nr_tries == max_tries)
211 ++get_value_statistics_.timeout_counter;
214 std::this_thread::yield();
224 struct HandleRTStatistics
226 unsigned int total_counter = 0;
227 unsigned int failed_counter = 0;
228 unsigned int timeout_counter = 0;
230 mutable HandleRTStatistics get_value_statistics_;
231 HandleRTStatistics set_value_statistics_;