Skip to content
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

Fix trajectory unwind bug #1772

Merged
merged 13 commits into from
Dec 21, 2022
Merged

Conversation

mechwiz
Copy link
Contributor

@mechwiz mechwiz commented Dec 1, 2022

Description

This PR fixes some unwinding/bounds issues for continuous joints.

  1. If a trajectory that is being unwound from a reference-state starts (i.e. has an initial waypoint) where the continuous joint has a value above 2PI or below -2PI as could be the case when a trajectory from MTC is generated, I have noticed in a project that I was working on that the running_offset can be off by a multiple of 2PI leading to 2PI jumps in the command for that continous joint. This occurs because in the current implementation, the running_offset is not only being calculated using the offset between the reference state and the unwound reference state but also the offset between the initial waypoint (which may not be unwound) and the unwound current state which is not valid and is like comparing apples and oranges. To fix this, the initial waypoint of the trajectory also has its bounds enforced so that when it's being compared to the reference value, it's comparing apples to apples. Furthermore, I added logic to ensure that the running_offset takes into account when the unwound reference state and the unwound initial waypoint are not on the same side of PI by adding 2PI or subtracting 2PI accordingly.
  2. When executeAndMonitor is called, unwinding is not handled properly if there are multiple trajectories within the plan as would happen when executing a task or a serial container from MTC. The way unwinding should work is that the current plan_component's trajectory (item i) should be unwound based on any group-matching previous plan_component's trajectory (item j). The current implementation for some unknown reason is starting at index zero and working up (which is not valid since there could be a matching group plan-component but it might not be the one that precedes component "i") instead of starting at the previous plan compoment and working down.

Fixes #1777

@AndyZe

Checklist

  • Required by CI: Code is auto formatted using clang-format
  • Extend the tutorials / documentation reference
  • Document API changes relevant to the user in the MIGRATION.md notes
  • Create tests, which fail without this PR reference
  • Include a screenshot if changing a GUI
  • While waiting for someone to review your request, please help review another open pull request to support the maintainers

@mechwiz mechwiz changed the title Fix bounds enforcement bug Fix trajectory unwind bug Dec 1, 2022
@codecov
Copy link

codecov bot commented Dec 1, 2022

Codecov Report

Base: 50.32% // Head: 50.36% // Increases project coverage by +0.04% 🎉

Coverage data is based on head (c0bcb27) compared to base (fff361b).
Patch coverage: 86.67% of modified lines in pull request are covered.

❗ Current head c0bcb27 differs from pull request most recent head 6afb74f. Consider uploading reports for the commit 6afb74f to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1772      +/-   ##
==========================================
+ Coverage   50.32%   50.36%   +0.04%     
==========================================
  Files         374      374              
  Lines       31329    31283      -46     
==========================================
- Hits        15762    15751      -11     
+ Misses      15567    15532      -35     
Impacted Files Coverage Δ
...include/moveit/robot_trajectory/robot_trajectory.h 98.67% <ø> (ø)
...eit_core/robot_trajectory/src/robot_trajectory.cpp 66.48% <86.67%> (+9.83%) ⬆️
...rajectory_processing/src/ruckig_traj_smoothing.cpp 90.97% <0.00%> (-0.61%) ⬇️
...veit_core/robot_model/src/revolute_joint_model.cpp 90.08% <0.00%> (-0.57%) ⬇️
...ics_plugin_loader/src/kinematics_plugin_loader.cpp 82.76% <0.00%> (-0.57%) ⬇️
...bot_model/include/moveit/robot_model/joint_model.h 82.44% <0.00%> (-0.46%) ⬇️
...nning_scene_monitor/src/planning_scene_monitor.cpp 45.26% <0.00%> (-0.43%) ⬇️
...bot_model/include/moveit/robot_model/robot_model.h 90.39% <0.00%> (-0.35%) ⬇️
moveit_core/robot_model/src/joint_model_group.cpp 65.12% <0.00%> (-0.24%) ⬇️
...mpl_interface/src/model_based_planning_context.cpp 50.57% <0.00%> (ø)
... and 2 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@JafarAbdi JafarAbdi self-assigned this Dec 1, 2022
@JafarAbdi
Copy link
Contributor

Do you mind adding a test that reproduces the fixed issue?

@AndyZe
Copy link
Member

AndyZe commented Dec 2, 2022

I can write a couple tests, as part of reviewing this anyway.

@mechwiz
Copy link
Contributor Author

mechwiz commented Dec 2, 2022

Thanks Andy!
Sorry haven't gotten to the test writing part yet.

@AndyZe
Copy link
Member

AndyZe commented Dec 2, 2022

Started writing a test, got distracted by other bugs :/ Will come back to this. Or maybe we merge it as it is, then fix the other bugs and write tests.

@AndyZe AndyZe force-pushed the fix_bounds_enforcement_bug branch 2 times, most recently from 261b900 to 02e95fc Compare December 2, 2022 19:48
Copy link
Member

@AndyZe AndyZe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK merging this without tests. unwind() clearly has some other bugs that need to be fixed, anyway. See #1778

We need to wait for one more review, though.

@mechwiz
Copy link
Contributor Author

mechwiz commented Dec 2, 2022

I'm cool with merging as is as well!

@mechwiz mechwiz force-pushed the fix_bounds_enforcement_bug branch 2 times, most recently from aeb1793 to a3e26a2 Compare December 11, 2022 05:15
@mechwiz
Copy link
Contributor Author

mechwiz commented Dec 11, 2022

Okedoke, I think I fixed up the other unwind bugs and got the unwind test case to be successful

@AndyZe AndyZe self-requested a review December 12, 2022 23:01
@mechwiz mechwiz force-pushed the fix_bounds_enforcement_bug branch 2 times, most recently from d67d8aa to a9bebe1 Compare December 15, 2022 03:10
@mechwiz mechwiz force-pushed the fix_bounds_enforcement_bug branch 2 times, most recently from 3b71654 to 5d213b6 Compare December 21, 2022 04:51
@sjahr
Copy link
Contributor

sjahr commented Dec 21, 2022

@mechwiz Can you please rebase this branch, so we can merge it

@mechwiz
Copy link
Contributor Author

mechwiz commented Dec 21, 2022

Done

@sjahr sjahr requested a review from AndyZe December 21, 2022 17:32
@sjahr sjahr merged commit ca68be3 into moveit:main Dec 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RobotTrajectory unwind() functions only account for one extra "wrap"
4 participants