Skip to content

Commit

Permalink
Optimize MOVE_SHAPE operations for FCL (#3601)
Browse files Browse the repository at this point in the history
Don't recreate the FCL object when moving shapes, but just update its transforms.
  • Loading branch information
captain-yoshi authored and rhaschke committed Jul 19, 2024
1 parent 2b8a067 commit a0a5a63
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,24 @@ TYPED_TEST_P(CollisionDetectorPandaTest, RobotWorldCollision_1)
ASSERT_TRUE(res.collision);
res.clear();

pos1.translation().z() = 0.25;
this->cenv_->getWorld()->moveObject("box", pos1);
this->cenv_->checkRobotCollision(req, res, *this->robot_state_, *this->acm_);
ASSERT_FALSE(res.collision);
res.clear();

pos1.translation().z() = 0.05;
this->cenv_->getWorld()->moveObject("box", pos1);
this->cenv_->checkRobotCollision(req, res, *this->robot_state_, *this->acm_);
ASSERT_TRUE(res.collision);
res.clear();

pos1.translation().z() = 0.25;
this->cenv_->getWorld()->moveObject("box", pos1);
this->cenv_->checkRobotCollision(req, res, *this->robot_state_, *this->acm_);
ASSERT_FALSE(res.collision);
res.clear();

this->cenv_->getWorld()->moveObject("box", pos1);
ASSERT_FALSE(res.collision);
}
Expand Down
32 changes: 32 additions & 0 deletions moveit_core/collision_detection_fcl/src/collision_env_fcl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,38 @@ void CollisionEnvFCL::notifyObjectChange(const ObjectConstPtr& obj, World::Actio
}
cleanCollisionGeometryCache();
}
else if (action == World::MOVE_SHAPE)
{
auto it = fcl_objs_.find(obj->id_);
if (it == fcl_objs_.end())
{
RCLCPP_ERROR(getLogger(), "Cannot move shapes of unknown FCL object: '%s'", obj->id_.c_str());
return;
}

if (obj->global_shape_poses_.size() != it->second.collision_objects_.size())
{
RCLCPP_ERROR(getLogger(),
"Cannot move shapes, shape size mismatch between FCL object and world object: '%s'. Respectively "
"%zu and %zu.",
obj->id_.c_str(), it->second.collision_objects_.size(), it->second.collision_objects_.size());
return;
}

for (std::size_t i = 0; i < it->second.collision_objects_.size(); ++i)
{
it->second.collision_objects_[i]->setTransform(transform2fcl(obj->global_shape_poses_[i]));

// compute AABB, order matters
it->second.collision_geometry_[i]->collision_geometry_->computeLocalAABB();
it->second.collision_objects_[i]->computeAABB();
}

// update AABB in the FCL broadphase manager tree
// see https://github.com/moveit/moveit/pull/3601 for benchmarks
it->second.unregisterFrom(manager_.get());
it->second.registerTo(manager_.get());
}
else
{
updateFCLObject(obj->id_);
Expand Down

0 comments on commit a0a5a63

Please sign in to comment.