-
Notifications
You must be signed in to change notification settings - Fork 690
Fix findWayPointIndicesForDurationAfterStart method when out of bounds #3626
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
base: main
Are you sure you want to change the base?
Conversation
…s and add unit tests
| double& blend) const | ||
| { | ||
| if (duration < 0.0) | ||
| if (duration < 0.0 || waypoints_.empty()) |
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 change in line 539 is not enough to handle the case that waypoints is empty. i.e. index an empty deque with [0]
|
Hey @nbbrooks , this pr is ready for review. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3626 +/- ##
==========================================
+ Coverage 46.19% 46.27% +0.09%
==========================================
Files 720 720
Lines 59181 59208 +27
Branches 7594 7596 +2
==========================================
+ Hits 27333 27394 +61
+ Misses 31681 31647 -34
Partials 167 167 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
nbbrooks
left a comment
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.
This is looking good considering the unclear intended behavior from the original function description and the current [old] error handling patterns in the codebase. As I see it, the expected output with edge cases should be:
// If waypoints are empty: before == 0, after == 0, blend == 0 (invalid - empty trajectory)
// If target duration < 0: before == 0, after == 0, blend == 0 (invalid - before trajectory has started)
// If target duration > total duration of waypoints, before == size() - 1, after == size() - 1, blend == 1 (after trajectory has completed)
// If 1 waypoint and target duration == total duration of waypoints, before == 0, after == 0, blend == 1 (at single point trajectory completion)
// Else before == last waypoint index with total duration < target duration, after == before + 1, blend == fraction of target duration between total duration @ before and total duration @ after
// Therefore, if 2 waypoints and target duration == total duration of waypoints, before == 0, after == 1, blend == 1 (at trajectory completion)
Since you are being so thorough, here are the last changes I suggest:
- Change access to use at() as you noted. I would not expect this to be in a real-time loop or have significant impact.
- Consider updating your test names to be more descriptive of the corner case they are checking (my suggestions are
RobotTrajectoryFindWayPointIndicesBetweenWaypoints,RobotTrajectoryFindWayPointIndicesAtLastOfManyWaypoints,RobotTrajectoryFindWayPointIndicesAfterLastWaypoint, andRobotTrajectoryFindWayPointIndicesEmptyWaypoints) - Add two more tests to check the remaining cases:
RobotTrajectoryFindWayPointIndicesBeforeFirstWaypointandRobotTrajectoryFindWayPointIndicesAtLastOfSingleWaypointor something to that effect.
|
Nice! Then I change the unit test to use |
Description
The fix is to address the bug raised in issue #3612 which causes UB. The change has been
moveit/moveit2:rolling-cimoveit_core/robot_trajectory/test/test_robot_trajectory.cppChecklist
Misc.
Actually, the wording "Create tests, which fail without this PR" is not strictly correct. Without the fix, the unit tests will "pass", but it passes with undefined behavior. Meaning, all the
EXPECT_xxafter the callfindWayPointIndicesForDurationAfterStartwill be omitted and the google test doesn't actually check it. I once plan to use theEXPECT_EXITbut UB doesn't always result in a SIGSEGV.In my perspective, I prefer the
.at()over[index]. See the guideline. But I guess using.at(might cause a little bit performance degrade in real time control of robot? If we use the[index]approach, then the unit test should run with AddressSanitizer or something. Since I am not quite familiar with the CI/CD of moveit2, therefore I defer whether to keep current implementation or change to.at()to @nbbrooks .