-
Notifications
You must be signed in to change notification settings - Fork 505
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
Wait for complete state duration fix #590
Conversation
Codecov Report
@@ Coverage Diff @@
## main #590 +/- ##
==========================================
+ Coverage 46.89% 46.98% +0.09%
==========================================
Files 185 185
Lines 19656 19657 +1
==========================================
+ Hits 9216 9234 +18
+ Misses 10440 10423 -17
Continue to review full report at Codecov.
|
double slept_time = 0.0; | ||
double sleep_step_s = std::min(0.05, wait_time / 10.0); | ||
rclcpp::Duration sleep_step(sleep_step_s); | ||
while (!haveCompleteState() && slept_time < wait_time) | ||
const double sleep_step_s = std::min(0.05, wait_time / 10.0); | ||
const auto sleep_step_duration = rclcpp::Duration::from_seconds(sleep_step_s * 1e9); | ||
double slept_time_s = 0.0; | ||
while (!haveCompleteState() && slept_time_s < wait_time) | ||
{ | ||
rclcpp::sleep_for(sleep_step.to_chrono<std::chrono::nanoseconds>()); | ||
slept_time += sleep_step_s; | ||
rclcpp::sleep_for(sleep_step_duration.to_chrono<std::chrono::nanoseconds>()); | ||
slept_time_s += sleep_step_s; | ||
} | ||
return haveCompleteState(); | ||
} |
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.
What happens with the old logic (on rolling):
wait_time = 10 (seconds)
slept_time = 0.0
sleep_time_s = 1
sleep_step = 1ns (constructor for double seconds is gone and the single argument constructor for Duration is now nanoseconds, there is a compiler warning that prints saying this is deprecated)
sleeps for 10 1ns amounts and returns...
As a result servo never hasCompleteState and calls exit(EXIT_FAILURE);
in the constructor of Servo. I moved the wait for complete state into the start function.
As an aside I really wish I had colorized ros2 output. Has anyone figured out how to get that? It would have been much quicker to debug if the error it printed was red.
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.
As an aside I really wish I had colorized ros2 output. Has anyone figured out how to get that? It would have been much quicker to debug if the error it printed was red.
You could do it with export RCUTILS_COLORIZED_OUTPUT=1
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.
^Thanks @JafarAbdi! Adding to my bashrc
moveit_ros/planning/planning_scene_monitor/src/current_state_monitor.cpp
Outdated
Show resolved
Hide resolved
This now comes with a test, restoring the old code in waitForCompleteState fails like I'd expect:
|
efa77f1
to
e7af397
Compare
rclcpp::sleep_for(sleep_step.to_chrono<std::chrono::nanoseconds>()); | ||
slept_time += sleep_step_s; | ||
rclcpp::sleep_for(sleep_step_duration.to_chrono<std::chrono::nanoseconds>()); | ||
slept_time_s += sleep_step_s; |
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.
Nit about variable naming. I know ROS is "by default" SI units and the base unit for time is second and that should always be the implicit default. Yet, I find it much easier to read code and API if the units are documented as part of the variable names. In this case, it would mean that wait_time
would be wait_time_s
and sleep_step_duration
would be sleep_step_duration_s
. Thoughts?
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.
I didn't thought this before but really liked it 10/10 will use next time I write something with durations
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.
sleep_step_duration is a Duration object and is not specifically in the unit seconds, it is in whatever unit you want. I will change wait_time though.
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.
+1, Google style is to include units
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.
Should this (and all this DI stuff) be backported to foxy, or we don't care about that?
}; | ||
|
||
// WHEN it is constructed | ||
// THEN we expect haveCompleteState to be false |
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.
nit: this capitalization is weird/hard to read. Not sure it adds anything. WHEN, THEN, etc.
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.
Does Doxygen support pulling out GWT conditions in some format? That would be a nice motivation for this explicit formatting.
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.
The given-when-then comes from BDD (https://en.wikipedia.org/wiki/Behavior-driven_development) and is a practice of testing. I'll be the first to admit I don't fully understand BDD but that it does seem to provide helpful patterns for writing nice tests.
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.
Approving assuming you update variable names like Jere suggested
8e36d6c
to
ec8e470
Compare
I don't really care to backport it to foxy, but we can if we are using foxy for some project that uses servo. I think the issue with the constructor for Duration no longer taking double seconds is a rolling/galactic problem. In foxy I think this code still works the way we think it does (because you can construct a duration with double seconds). |
Co-authored-by: Jafar Abdi <cafer.abdi@gmail.com>
ec8e470
to
ceb2a99
Compare
So exciting to see test coverage growing! |
Co-authored-by: Jafar Abdi <cafer.abdi@gmail.com>
Co-authored-by: Jafar Abdi <cafer.abdi@gmail.com>
Description
This fixes a bug I found while trying to use the servo demo on rolling.