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
Servo: Check frames are known before getting their TFs #612
Conversation
Codecov ReportBase: 50.95% // Head: 54.24% // Increases project coverage by
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
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. |
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.
Looks good, I approved and merged your other PR that would throw an exception. Handling it nicer here is good too.
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 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?
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 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.
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.
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); |
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.
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.
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.
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, |
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 too can be simplified by rewriting: RCLCPP_WARN_STREAM_THROTTLE(LOGGER, *node_->get_clock(), ROS_LOG_THROTTLE_PERIOD, 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.
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
@tylerjw This change was indeed causing the tests to fail - because the original change skipped commands with an empty Fixed it, but I noticed just the servo tests ( |
986c77c
to
e497736
Compare
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? |
e497736
to
ea39227
Compare
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