-
Notifications
You must be signed in to change notification settings - Fork 310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[HW_IF] Prepare the handles for async operations #1750
Changes from all commits
59c642a
f0847f3
f1cd924
466a107
efd8cbf
132c821
0e3416e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,10 +16,13 @@ | |
#define HARDWARE_INTERFACE__LOANED_COMMAND_INTERFACE_HPP_ | ||
|
||
#include <functional> | ||
#include <limits> | ||
#include <string> | ||
#include <thread> | ||
#include <utility> | ||
|
||
#include "hardware_interface/handle.hpp" | ||
saikishor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#include "rclcpp/logging.hpp" | ||
|
||
namespace hardware_interface | ||
{ | ||
|
@@ -51,6 +54,27 @@ class LoanedCommandInterface | |
|
||
virtual ~LoanedCommandInterface() | ||
{ | ||
auto logger = rclcpp::get_logger(command_interface_.get_name()); | ||
RCLCPP_WARN_EXPRESSION( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we put this to "DEBUG" mode? Or do we always want output when switching controllers? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is only when we deactivate the controller, i think it's good to have this statistical information. Moreover, as it is conditioned it should only print for async cases and that too if you have some misses. This should give us some information of the functionality of the system There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we have reported issues about this, we can put this to debug in future |
||
rclcpp::get_logger(get_name()), | ||
(get_value_statistics_.failed_counter > 0 || get_value_statistics_.timeout_counter > 0), | ||
"LoanedCommandInterface %s has %u (%.4f %%) timeouts and %u (~ %.4f %%) missed calls out of " | ||
"%u get_value calls", | ||
get_name().c_str(), get_value_statistics_.timeout_counter, | ||
(get_value_statistics_.timeout_counter * 100.0) / get_value_statistics_.total_counter, | ||
get_value_statistics_.failed_counter, | ||
(get_value_statistics_.failed_counter * 10.0) / get_value_statistics_.total_counter, | ||
get_value_statistics_.total_counter); | ||
RCLCPP_WARN_EXPRESSION( | ||
rclcpp::get_logger(get_name()), | ||
(set_value_statistics_.failed_counter > 0 || set_value_statistics_.timeout_counter > 0), | ||
"LoanedCommandInterface %s has %u (%.4f %%) timeouts and %u (~ %.4f %%) missed calls out of " | ||
"%u set_value calls", | ||
get_name().c_str(), set_value_statistics_.timeout_counter, | ||
(set_value_statistics_.timeout_counter * 100.0) / set_value_statistics_.total_counter, | ||
set_value_statistics_.failed_counter, | ||
(set_value_statistics_.failed_counter * 10.0) / set_value_statistics_.total_counter, | ||
set_value_statistics_.total_counter); | ||
if (deleter_) | ||
{ | ||
deleter_(); | ||
|
@@ -70,13 +94,70 @@ class LoanedCommandInterface | |
|
||
const std::string & get_prefix_name() const { return command_interface_.get_prefix_name(); } | ||
|
||
void set_value(double val) { command_interface_.set_value(val); } | ||
template <typename T> | ||
[[nodiscard]] bool set_value(T value, unsigned int max_tries = 10) | ||
{ | ||
unsigned int nr_tries = 0; | ||
++set_value_statistics_.total_counter; | ||
while (!command_interface_.set_value(value)) | ||
{ | ||
++set_value_statistics_.failed_counter; | ||
++nr_tries; | ||
if (nr_tries == max_tries) | ||
{ | ||
++set_value_statistics_.timeout_counter; | ||
return false; | ||
} | ||
std::this_thread::yield(); | ||
} | ||
return true; | ||
} | ||
|
||
double get_value() const { return command_interface_.get_value(); } | ||
double get_value() const | ||
{ | ||
double value; | ||
if (get_value(value)) | ||
{ | ||
return value; | ||
} | ||
else | ||
{ | ||
return std::numeric_limits<double>::quiet_NaN(); | ||
} | ||
} | ||
|
||
template <typename T> | ||
[[nodiscard]] bool get_value(T & value, unsigned int max_tries = 10) const | ||
{ | ||
unsigned int nr_tries = 0; | ||
++get_value_statistics_.total_counter; | ||
while (!command_interface_.get_value(value)) | ||
{ | ||
++get_value_statistics_.failed_counter; | ||
++nr_tries; | ||
if (nr_tries == max_tries) | ||
{ | ||
++get_value_statistics_.timeout_counter; | ||
return false; | ||
} | ||
std::this_thread::yield(); | ||
} | ||
return true; | ||
} | ||
|
||
protected: | ||
CommandInterface & command_interface_; | ||
Deleter deleter_; | ||
|
||
private: | ||
struct HandleRTStatistics | ||
{ | ||
unsigned int total_counter = 0; | ||
unsigned int failed_counter = 0; | ||
unsigned int timeout_counter = 0; | ||
}; | ||
mutable HandleRTStatistics get_value_statistics_; | ||
HandleRTStatistics set_value_statistics_; | ||
}; | ||
|
||
} // namespace hardware_interface | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mamueluth please check this. This is how we can template the access to variables. This should simplify test changes.