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

Servo: Check frames are known before getting their TFs #612

Merged
merged 4 commits into from Nov 15, 2022

Conversation

AdamPettinger
Copy link
Contributor

Description

Noticed this when I was looking at #611 originally. Servo should check the frames it needs to do TF math with exist in the robot state before trying to look them up.

Can test this before/after by: modifying this line to be an unknown frame, then running the servo teleop demo with keyboard (arrow keys) input. After this change, Servo will not crash if the command frame is invalid, but will instead print a warning and skip the command.

Note that this might break the test on checkValidCommand() when it is re-enabled with #603. If that is merged first, I will rebase and make sure the test passes (and add a test case for this invalid frame)

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

@codecov
Copy link

codecov bot commented Aug 14, 2021

Codecov Report

Base: 50.95% // Head: 54.24% // Increases project coverage by +3.29% 🎉

Coverage data is based on head (986c77c) compared to base (2dfdad0).
Patch coverage: 53.34% of modified lines in pull request are covered.

❗ Current head 986c77c differs from pull request most recent head 52b32a9. Consider uploading reports for the commit 52b32a9 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #612      +/-   ##
==========================================
+ Coverage   50.95%   54.24%   +3.29%     
==========================================
  Files         378      191     -187     
  Lines       31643    20099   -11544     
==========================================
- Hits        16122    10900    -5222     
+ Misses      15521     9199    -6322     
Impacted Files Coverage Δ
moveit_ros/moveit_servo/src/servo_calcs.cpp 70.14% <53.34%> (+2.20%) ⬆️
.../planning_scene_monitor/src/trajectory_monitor.cpp 0.00% <0.00%> (-68.33%) ⬇️
...eit_core/robot_trajectory/src/robot_trajectory.cpp 15.75% <0.00%> (-51.30%) ⬇️
moveit_core/exceptions/src/exceptions.cpp 0.00% <0.00%> (-50.00%) ⬇️
moveit_core/robot_state/src/attached_body.cpp 25.93% <0.00%> (-48.74%) ⬇️
moveit_core/robot_state/src/conversions.cpp 28.91% <0.00%> (-34.79%) ⬇️
...veit_servo/include/moveit_servo/servo_parameters.h 69.24% <0.00%> (-30.76%) ⬇️
moveit_ros/planning/rdf_loader/src/rdf_loader.cpp 23.72% <0.00%> (-30.74%) ⬇️
...e/include/moveit/kinematics_base/kinematics_base.h 46.67% <0.00%> (-29.64%) ⬇️
..._core/planning_interface/src/planning_response.cpp 0.00% <0.00%> (-29.62%) ⬇️
... and 364 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.

Copy link
Collaborator

@tylerjw tylerjw left a comment

Choose a reason for hiding this comment

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

Looks good, I approved and merged your other PR that would throw an exception. Handling it nicer here is good too.

Copy link
Member

@henningkayser henningkayser left a comment

Choose a reason for hiding this comment

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

This seems reasonable to me. Out of scope: Wouldn't it make sense to throw the exception from RobotState instead of simply printing an error message and returning an identity transform?

Copy link
Collaborator

@tylerjw tylerjw left a comment

Choose a reason for hiding this comment

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

This is now causing some of the servo tests to fail. Please update the tests to make sure they are either not causing this to happen or test that this error handling works.

Copy link
Contributor

@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.

Greatly support the idea behind this PR! Will approve when CI passes.

if (!current_state_->knowsFrameTransform(frame_name))
{
std::string error_string = "Unknown frame: " + frame_name;
throw std::runtime_error(error_string);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be simplified: throw std::runtime_error{"Unknown frame: " + frame_name}; Also, I take it that changing the frames on the fly might be a possibility? Still, are there any alternatives to simply terminating a process if a frame cannot be found? Is it documented anywhere that start() can suddenly throw an exception? To prevent termination, someone has to catch that exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a callback to change the robot command frame on the fly later.

I added a note about the exception in the header file. However, we might consider a change so start() returns a bool and we can return false instead of throwing?

if (!current_state_->knowsFrameTransform(cmd.header.frame_id))
{
rclcpp::Clock& clock = *node_->get_clock();
RCLCPP_WARN_STREAM_THROTTLE(LOGGER, clock, ROS_LOG_THROTTLE_PERIOD,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: this too can be simplified by rewriting: RCLCPP_WARN_STREAM_THROTTLE(LOGGER, *node_->get_clock(), ROS_LOG_THROTTLE_PERIOD, etc...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This actually does not work. I don't understand exactly how ROS 2 clocks and timing works, but this has weird results:

It will compile, but some timestamps (seen in RCLCPP logging macros) turn into... not quite nullptr ? It is very strange

@AdamPettinger
Copy link
Contributor Author

This is now causing some of the servo tests to fail. Please update the tests to make sure they are either not causing this to happen or test that this error handling works.

@tylerjw This change was indeed causing the tests to fail - because the original change skipped commands with an empty frame_id. So yay 🎉 for enabled integration tests catching problems!

Fixed it, but I noticed just the servo tests (colcon test --packages-select moveit_servo) take 2.5 minutes on my not-wimpy machine. Haven't investigated if this PR causes that (but will), but that seems really excessive

@henningkayser henningkayser removed this from Review in progress in Galactic/Rolling - 2.3.0 - September 10 Oct 25, 2021
@tylerjw tylerjw force-pushed the fix/check_servo_frames_before_using branch from 986c77c to e497736 Compare November 15, 2022 16:14
@tylerjw
Copy link
Collaborator

tylerjw commented Nov 15, 2022

Rebased this change to see if it will pass CI. If it does, I suggest we merge this change, as it fixes a known bug. @AndyZe do you have any opinion on this?

@tylerjw tylerjw self-requested a review November 15, 2022 16:15
@tylerjw tylerjw force-pushed the fix/check_servo_frames_before_using branch from e497736 to ea39227 Compare November 15, 2022 16:50
@AndyZe AndyZe merged commit c1d287e into moveit:main Nov 15, 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.

None yet

5 participants