-
Notifications
You must be signed in to change notification settings - Fork 569
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: ensure attached objects update during motion execution #3327
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -283,34 +283,70 @@ bool plan_execution::PlanExecution::isRemainingPathValid(const ExecutableMotionP | |
collision_detection::CollisionRequest req; | ||
req.group_name = t.getGroupName(); | ||
req.pad_environment_collisions = false; | ||
auto getAttachedObjects = [](const moveit::core::RobotState& state) { | ||
std::vector<const moveit::core::AttachedBody*> attached_bodies; | ||
state.getAttachedBodies(attached_bodies); | ||
std::map<std::string, const moveit::core::AttachedBody*> attached_objects; | ||
for (const auto& ab : attached_bodies) | ||
{ | ||
attached_objects[ab->getName()] = ab; | ||
} | ||
return attached_objects; | ||
}; | ||
|
||
moveit::core::RobotState state = plan.planning_scene->getCurrentState(); | ||
std::map<std::string, const moveit::core::AttachedBody*> current_attached_objects = getAttachedObjects(state); | ||
for (std::size_t i = std::max(path_segment.second - 1, 0); i < wpc; ++i) | ||
{ | ||
state = t.getWayPoint(i); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for this! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only simplification I could think of is that, under the assumption that "attached objects are set to the waypoint's robot state at planning time" (which actually holds) we could query sample_attached_object only once. However, I proposed updating it for each waypoint to ensure robustness, even if this assumption doesn't hold. Do you see any potential issues or improvements with this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah thanks for asking. I guess I would be thinking about:
Is it worth maybe adding a flag to this function for whether one wants to prioritize current state vs. planned states? And elevate this up to the config/parameter level? |
||
collision_detection::CollisionResult res; | ||
std::map<std::string, const moveit::core::AttachedBody*> sample_attached_object = getAttachedObjects(state); | ||
|
||
// If sample state has attached objects that are not in the current state, remove them from the sample state | ||
for (const auto& [name, object] : sample_attached_object) | ||
{ | ||
if (current_attached_objects.find(name) == current_attached_objects.end()) | ||
{ | ||
RCLCPP_DEBUG(logger_, "Attached object '%s' is not in the current scene. Removing it.", name.c_str()); | ||
state.clearAttachedBody(name); | ||
} | ||
} | ||
|
||
// If current state has attached objects that are not in the sample state, add them to the sample state | ||
for (const auto& [name, object] : current_attached_objects) | ||
{ | ||
if (sample_attached_object.find(name) == sample_attached_object.end()) | ||
{ | ||
RCLCPP_DEBUG(logger_, "Attached object '%s' is not in the robot state. Adding it.", name.c_str()); | ||
state.attachBody(std::make_unique<moveit::core::AttachedBody>(*object)); | ||
} | ||
} | ||
|
||
if (acm) | ||
{ | ||
plan.planning_scene->checkCollision(req, res, t.getWayPoint(i), *acm); | ||
plan.planning_scene->checkCollision(req, res, state, *acm); | ||
} | ||
else | ||
{ | ||
plan.planning_scene->checkCollision(req, res, t.getWayPoint(i)); | ||
plan.planning_scene->checkCollision(req, res, state); | ||
} | ||
|
||
if (res.collision || !plan.planning_scene->isStateFeasible(t.getWayPoint(i), false)) | ||
if (res.collision || !plan.planning_scene->isStateFeasible(state, false)) | ||
{ | ||
RCLCPP_INFO(logger_, "Trajectory component '%s' is invalid for waypoint %ld out of %ld", | ||
plan.plan_components[path_segment.first].description.c_str(), i, wpc); | ||
|
||
// call the same functions again, in verbose mode, to show what issues have been detected | ||
plan.planning_scene->isStateFeasible(t.getWayPoint(i), true); | ||
plan.planning_scene->isStateFeasible(state, true); | ||
req.verbose = true; | ||
res.clear(); | ||
if (acm) | ||
{ | ||
plan.planning_scene->checkCollision(req, res, t.getWayPoint(i), *acm); | ||
plan.planning_scene->checkCollision(req, res, state, *acm); | ||
} | ||
else | ||
{ | ||
plan.planning_scene->checkCollision(req, res, t.getWayPoint(i)); | ||
plan.planning_scene->checkCollision(req, res, state); | ||
} | ||
return false; | ||
} | ||
|
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.
Does it make sense to add this function to
RobotState
itself instead? Like agetAttachedBodiedMap()
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.
That sounds like a good idea! Adding a
getAttachedBodiesMap()
function to RobotState could make it more reusable and improve clarity. Would you like to propose this as a separate PR, or do you plan to integrate it into your current changes?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 was suggesting including this in your PR, if you would be up for it?
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 have just created the
getAttachedBodies
version that returns a map instead of a vector and updated the PR accordingly. Let me know if this aligns with your ideas!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.
It looks good, though I would consider not having it call the other one since it seems inefficient to create a vector, then loop through that to create a map. Maybe just go straight by looping through and putting together the map?