Skip to content

Commit

Permalink
Don't destroy objects on attach (#3205) (#3214)
Browse files Browse the repository at this point in the history
(cherry picked from commit 639e214)

Co-authored-by: Marq Rasmussen <[email protected]>
  • Loading branch information
mergify[bot] and MarqRazz authored Jan 9, 2025
1 parent ac64688 commit f820ea4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
6 changes: 5 additions & 1 deletion moveit_core/planning_scene/src/planning_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,11 @@ void PlanningScene::pushDiffs(const PlanningScenePtr& scene)
scene->world_->removeObject(it.first);
scene->removeObjectColor(it.first);
scene->removeObjectType(it.first);
scene->getAllowedCollisionMatrixNonConst().removeEntry(it.first);
// if object is attached, it should not be removed from the ACM
if (!scene->getCurrentState().hasAttachedBody(it.first))
{
scene->getAllowedCollisionMatrixNonConst().removeEntry(it.first);
}
}
else
{
Expand Down
19 changes: 19 additions & 0 deletions moveit_core/planning_scene/test/test_planning_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,20 @@ TEST(PlanningScene, UpdateACMAfterObjectRemoval)
EXPECT_EQ(getCollisionObjectsNames(*ps), (std::set<std::string>{ object_name }));
};

// Helper function to attach the object to the robot
auto attach_object = [&] {
const auto ps1 = createPlanningSceneDiff(*ps, object_name, moveit_msgs::msg::CollisionObject::ADD, true);
ps->usePlanningSceneMsg(ps1);
EXPECT_EQ(getAttachedCollisionObjectsNames(*ps), (std::set<std::string>{ object_name }));
};

// Helper function to detach the object from the robot
auto detach_object = [&] {
const auto ps1 = createPlanningSceneDiff(*ps, object_name, moveit_msgs::msg::CollisionObject::REMOVE, true);
ps->usePlanningSceneMsg(ps1);
EXPECT_EQ(getAttachedCollisionObjectsNames(*ps), (std::set<std::string>{}));
};

// Modify the allowed collision matrix and make sure it is updated
auto modify_acm = [&] {
collision_detection::AllowedCollisionMatrix& acm = ps->getAllowedCollisionMatrixNonConst();
Expand All @@ -627,6 +641,11 @@ TEST(PlanningScene, UpdateACMAfterObjectRemoval)
EXPECT_TRUE(check_collision());
modify_acm();
EXPECT_FALSE(check_collision());
// Attach and detach the object from the robot to make sure that collision are still allowed
attach_object();
EXPECT_FALSE(check_collision());
detach_object();
EXPECT_FALSE(check_collision());
{
const auto ps1 = createPlanningSceneDiff(*ps, object_name, moveit_msgs::msg::CollisionObject::REMOVE);
ps->usePlanningSceneMsg(ps1);
Expand Down
7 changes: 3 additions & 4 deletions moveit_ros/planning/plan_execution/src/plan_execution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ plan_execution::PlanExecution::PlanExecution(
: node_(node)
, planning_scene_monitor_(planning_scene_monitor)
, trajectory_execution_manager_(trajectory_execution)
, logger_(moveit::getLogger("moveit.ros.add_time_optimal_parameterization"))
, logger_(moveit::getLogger("moveit.ros.plan_execution"))
{
if (!trajectory_execution_manager_)
{
Expand Down Expand Up @@ -297,9 +297,8 @@ bool plan_execution::PlanExecution::isRemainingPathValid(const ExecutableMotionP

if (res.collision || !plan.planning_scene->isStateFeasible(t.getWayPoint(i), false))
{
// Dave's debacle
RCLCPP_INFO(logger_, "Trajectory component '%s' is invalid",
plan.plan_components[path_segment.first].description.c_str());
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);
Expand Down

0 comments on commit f820ea4

Please sign in to comment.