Skip to content

Commit

Permalink
thread safety in clear octomap & only update geometry (moveit#2500)
Browse files Browse the repository at this point in the history
The method used UPDATE_SCENE which caused a full scene to be transmitted.
But only the octomap is modified, so UPDATE_GEOMETRY suffices.

Also add comment about necessary scoping of non-recursive lock.
  • Loading branch information
simonschmeisser authored and tylerjw committed Apr 29, 2021
1 parent b969b07 commit ac0ac4b
Showing 1 changed file with 17 additions and 10 deletions.
Expand Up @@ -537,18 +537,25 @@ void PlanningSceneMonitor::newPlanningSceneCallback(const moveit_msgs::PlanningS

void PlanningSceneMonitor::clearOctomap()
{
if (scene_->getWorldNonConst()->removeObject(scene_->OCTOMAP_NS))
triggerSceneUpdateEvent(UPDATE_SCENE);
if (octomap_monitor_)
{
octomap_monitor_->getOcTreePtr()->lockWrite();
octomap_monitor_->getOcTreePtr()->clear();
octomap_monitor_->getOcTreePtr()->unlockWrite();
}
else
bool removed = false;
{
ROS_WARN_NAMED(LOGNAME, "Unable to clear octomap since no octomap monitor has been initialized");
boost::unique_lock<boost::shared_mutex> ulock(scene_update_mutex_);
removed = scene_->getWorldNonConst()->removeObject(scene_->OCTOMAP_NS);

if (octomap_monitor_)
{
octomap_monitor_->getOcTreePtr()->lockWrite();
octomap_monitor_->getOcTreePtr()->clear();
octomap_monitor_->getOcTreePtr()->unlockWrite();
}
else
{
ROS_WARN_NAMED(LOGNAME, "Unable to clear octomap since no octomap monitor has been initialized");
} // Lift the scoped lock before calling triggerSceneUpdateEvent to avoid deadlock
}

if (removed)
triggerSceneUpdateEvent(UPDATE_GEOMETRY);
}

bool PlanningSceneMonitor::newPlanningSceneMessage(const moveit_msgs::PlanningScene& scene)
Expand Down

0 comments on commit ac0ac4b

Please sign in to comment.