33 using Deleter = std::function<void(
void)>;
43 : command_interface_(command_interface),
44 deleter_(std::forward<Deleter>(deleter)),
45 interface_name_(command_interface.get_name())
50 : command_interface_(*command_interface),
51 interface_name_(command_interface->get_name()),
52 deleter_(std::forward<Deleter>(deleter))
62 auto logger = rclcpp::get_logger(interface_name_);
63 RCLCPP_WARN_EXPRESSION(
65 (get_value_statistics_.failed_counter > 0 || get_value_statistics_.timeout_counter > 0),
66 "LoanedCommandInterface %s has %u (%.4f %%) timeouts and %u (~ %.4f %%) missed calls out of "
68 interface_name_.c_str(), get_value_statistics_.timeout_counter,
69 (get_value_statistics_.timeout_counter * 100.0) / get_value_statistics_.total_counter,
70 get_value_statistics_.failed_counter,
71 (get_value_statistics_.failed_counter * 100.0) / get_value_statistics_.total_counter,
72 get_value_statistics_.total_counter);
73 RCLCPP_WARN_EXPRESSION(
75 (set_value_statistics_.failed_counter > 0 || set_value_statistics_.timeout_counter > 0),
76 "LoanedCommandInterface %s has %u (%.4f %%) timeouts and %u (~ %.4f %%) missed calls out of "
78 interface_name_.c_str(), set_value_statistics_.timeout_counter,
79 (set_value_statistics_.timeout_counter * 100.0) / set_value_statistics_.total_counter,
80 set_value_statistics_.failed_counter,
81 (set_value_statistics_.failed_counter * 100.0) / set_value_statistics_.total_counter,
82 set_value_statistics_.total_counter);
89 const std::string & get_name()
const {
return command_interface_.get_name(); }
91 const std::string & get_interface_name()
const {
return command_interface_.get_interface_name(); }
94 "Replaced by get_name method, which is semantically more correct")]]
const std::string
97 return command_interface_.get_name();
100 const std::string & get_prefix_name()
const {
return command_interface_.get_prefix_name(); }
117 template <
typename T>
118 [[nodiscard]]
bool set_value(
const T & value,
unsigned int max_tries = 10)
120 unsigned int nr_tries = 0;
121 ++set_value_statistics_.total_counter;
124 ++set_value_statistics_.failed_counter;
126 if (nr_tries == max_tries)
128 ++set_value_statistics_.timeout_counter;
131 std::this_thread::yield();
137 "Use std::optional<T> get_optional() instead to retrieve the value. This method will be "
138 "removed by the ROS 2 Kilted Kaiju release.")]]
139 double get_value()
const
142 if (opt_value.has_value())
144 return opt_value.value();
148 return std::numeric_limits<double>::quiet_NaN();
166 template <
typename T =
double>
167 [[nodiscard]] std::optional<T>
get_optional(
unsigned int max_tries = 10)
const
169 unsigned int nr_tries = 0;
172 ++get_value_statistics_.total_counter;
173 const std::optional<T> data = command_interface_.
get_optional<T>();
174 if (data.has_value())
178 ++get_value_statistics_.failed_counter;
180 std::this_thread::yield();
181 }
while (nr_tries < max_tries);
183 ++get_value_statistics_.timeout_counter;
202 template <
typename T>
204 "Use std::optional<T> get_optional() instead to retrieve the value. This method will be "
205 "removed by the ROS 2 Kilted Kaiju release.")]] [[nodiscard]]
bool
208 const auto opt_value = get_optional<T>(max_tries);
209 if (opt_value.has_value())
211 value = opt_value.value();
226 std::string interface_name_;
229 struct HandleRTStatistics
231 unsigned int total_counter = 0;
232 unsigned int failed_counter = 0;
233 unsigned int timeout_counter = 0;
235 mutable HandleRTStatistics get_value_statistics_;
236 HandleRTStatistics set_value_statistics_;