32 using Deleter = std::function<void(
void)>;
42 : command_interface_(command_interface),
43 deleter_(std::forward<Deleter>(deleter)),
44 interface_name_(command_interface.get_name())
49 : command_interface_(*command_interface),
50 interface_name_(command_interface->get_name()),
51 deleter_(std::forward<Deleter>(deleter))
61 auto logger = rclcpp::get_logger(interface_name_);
62 RCLCPP_WARN_EXPRESSION(
64 (get_value_statistics_.failed_counter > 0 || get_value_statistics_.timeout_counter > 0),
65 "LoanedCommandInterface %s has %u (%.4f %%) timeouts and %u (~ %.4f %%) missed calls out of "
67 interface_name_.c_str(), get_value_statistics_.timeout_counter,
68 (get_value_statistics_.timeout_counter * 100.0) / get_value_statistics_.total_counter,
69 get_value_statistics_.failed_counter,
70 (get_value_statistics_.failed_counter * 100.0) / get_value_statistics_.total_counter,
71 get_value_statistics_.total_counter);
72 RCLCPP_WARN_EXPRESSION(
74 (set_value_statistics_.failed_counter > 0 || set_value_statistics_.timeout_counter > 0),
75 "LoanedCommandInterface %s has %u (%.4f %%) timeouts and %u (~ %.4f %%) missed calls out of "
77 interface_name_.c_str(), set_value_statistics_.timeout_counter,
78 (set_value_statistics_.timeout_counter * 100.0) / set_value_statistics_.total_counter,
79 set_value_statistics_.failed_counter,
80 (set_value_statistics_.failed_counter * 100.0) / set_value_statistics_.total_counter,
81 set_value_statistics_.total_counter);
88 const std::string & get_name()
const {
return command_interface_.get_name(); }
90 const std::string & get_interface_name()
const {
return command_interface_.get_interface_name(); }
93 "Replaced by get_name method, which is semantically more correct")]]
const std::string
96 return command_interface_.get_name();
99 const std::string & get_prefix_name()
const {
return command_interface_.get_prefix_name(); }
116 template <
typename T>
117 [[nodiscard]]
bool set_value(
const T & value,
unsigned int max_tries = 10)
119 unsigned int nr_tries = 0;
120 ++set_value_statistics_.total_counter;
123 ++set_value_statistics_.failed_counter;
125 if (nr_tries == max_tries)
127 ++set_value_statistics_.timeout_counter;
130 std::this_thread::yield();
136 "Use std::optional<T> get_optional() instead to retrieve the value. This method will be "
137 "removed by the ROS 2 Kilted Kaiju release.")]]
138 double get_value()
const
141 if (opt_value.has_value())
143 return opt_value.value();
147 return std::numeric_limits<double>::quiet_NaN();
165 template <
typename T =
double>
166 [[nodiscard]] std::optional<T>
get_optional(
unsigned int max_tries = 10)
const
168 unsigned int nr_tries = 0;
171 ++get_value_statistics_.total_counter;
172 const std::optional<T> data = command_interface_.
get_optional<T>();
173 if (data.has_value())
177 ++get_value_statistics_.failed_counter;
179 std::this_thread::yield();
180 }
while (nr_tries < max_tries);
182 ++get_value_statistics_.timeout_counter;
201 template <
typename T>
203 "Use std::optional<T> get_optional() instead to retrieve the value. This method will be "
204 "removed by the ROS 2 Kilted Kaiju release.")]] [[nodiscard]]
bool
207 const auto opt_value = get_optional<T>(max_tries);
208 if (opt_value.has_value())
210 value = opt_value.value();
225 std::string interface_name_;
228 struct HandleRTStatistics
230 unsigned int total_counter = 0;
231 unsigned int failed_counter = 0;
232 unsigned int timeout_counter = 0;
234 mutable HandleRTStatistics get_value_statistics_;
235 HandleRTStatistics set_value_statistics_;