-
Notifications
You must be signed in to change notification settings - Fork 532
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
Convert OMPL status to MoveItErrorCode in the OMPL interface #1606
Conversation
dcc778b
to
20d986b
Compare
20d986b
to
31bd8db
Compare
Codecov ReportBase: 51.13% // Head: 51.09% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #1606 +/- ##
==========================================
- Coverage 51.13% 51.09% -0.03%
==========================================
Files 381 381
Lines 31711 31738 +27
==========================================
+ Hits 16211 16213 +2
- Misses 15500 15525 +25
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.
This is great, thanks for adding it! After reviewing it, I felt like we should maybe extend the existing MoveItError codes, so we loose even fewer information during the translation OMPLStatus -> MoveItError code. But this can be done in a follow up PR
moveit_planners/ompl/ompl_interface/src/model_based_planning_context.cpp
Outdated
Show resolved
Hide resolved
moveit_planners/ompl/ompl_interface/src/model_based_planning_context.cpp
Outdated
Show resolved
Hide resolved
moveit_planners/ompl/ompl_interface/src/model_based_planning_context.cpp
Outdated
Show resolved
Hide resolved
31bd8db
to
4a8c16c
Compare
if (ompl_simple_setup_->getProblemDefinition()->hasApproximateSolution()) | ||
{ | ||
RCLCPP_WARN(LOGGER, "Computed solution is approximate"); | ||
} |
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.
Deleted this bit of code because the "approximate" warning will be printed later
ebdbf17
to
c1de19b
Compare
c1de19b
to
39d1408
Compare
@@ -959,6 +968,54 @@ void ompl_interface::ModelBasedPlanningContext::unregisterTerminationCondition() | |||
ptc_ = nullptr; | |||
} | |||
|
|||
void ompl_interface::ModelBasedPlanningContext::omplPlannerStatusToMoveItErrorCode( |
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.
Why does this use an output parameter and why does it log?
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'll get rid of the output parameter.
As far as logging goes, this seems like a pretty good place to do it. We are already handling all possible cases with switch
, so... that code would have to be duplicated if the logging moved elsewhere. Maybe the function name just needs to be changed to indicate it logs? Like, logPlannerStatus()
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.
Maybe do something like this and then the call site can decide what they want:
// convert ompl status into moveit error code
moveit_msgs::msg::MoveItErrorCodes toMoveItError(ompl::base::PlannerStatus status);
// test if ompl status or moveit error code is success
bool isSuccess(ompl::base::PlannerStatus status);
bool isSuccess(moveit_msgs::msg::MoveItErrorCodes error_code);
// convert ompl status or moveit code into string, used in logging
std::string toString(ompl::base::PlannerStatus status);
std::string toString(moveit_msgs::msg::MoveItErrorCodes error_code);
// log warning if ompl status or moveit code is error
void logWarningIfError(ompl::base::PlannerStatus status);
void logWarningIfError(moveit_msgs::msg::MoveItErrorCodes error_code);
At the call site where you need to create a moveit error and log the ompl status you can do this:
auto ompl_status = ompl_simple_setup_->getLastPlannerStatus();
logWarningIfError(ompl_status);
result.val = toMoveItError(ompl_status);
In model_based_planning_context.cpp it can make the code simpler if you use a using
statement for success and failure. This is fine to do because it is not in a header and won't propagate into other files.
using SUCCESS = moveit_msgs::msg::MoveItErrorCodes::SUCCESS;
using FAILURE = moveit_msgs::msg::MoveItErrorCodes::FAILURE;
Then, combined with the isSuccess functions you can make those lines where you need to test if both the moveit error code and the ompl status are good results and return a success/failure moveit code can become a bit less verbose:
result.val = (isSuccess(result.val) && isSuccess(ompl_status)) ? SUCCESS : FAILURE;
These are just ideas for how you can make some smaller functions you can combine to make the error types easier to use in various places. The important idea here is just separating the function of converting the types from the function that logs.
Another small detail of the above code is you can make the function names simpler because the type of the parameter you pass in determines which function is called.
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.
Thank you for getting rid of the output parameter and using a return type. Above are just some suggestions on how we could maybe make this code a bit more flexible and easy to understand at the call site of the function.
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.
@AndyZe I'm also happy to accept this change as is and try to make the change I described above myself. Would you rather that?
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.
Give me a couple days. I want to try what you've suggested but prob won't get to it today
0160f60
to
f2556b3
Compare
1323ec0
to
b2fa0a8
Compare
c2e330e
to
f3e66d7
Compare
(cherry picked from commit baba9b0)
Description
Get better detail from planning errors by converting OMPL codes to MoveItErrorCode and returning them.
OMPL code documentation: https://github.com/ompl/ompl/blob/main/src/ompl/base/PlannerStatus.h
MoveItErrorCode documentation: https://github.com/ros-planning/moveit_msgs/blob/master/msg/MoveItErrorCodes.msg