Fix planning_scene_monitor sync when passed empty robot state (backport #3187) #3204
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes issue #3174.
When motion planning and executing solutions with MTC I have stages where objects are attached/removed and deleted from the scene at the beginning or end of a task. I have been having issues with the planning scene not updating correctly and the final state of the robot in the planning scene having offsets compared to the final state of trajectory given.
When executing an MTC solution that contains changes to the planning scene they are sent to the
planning_scene_monitor_
with no robot_state information. When MoveIt receives thisnewPlanningSceneMessage
that is not marked as a scene_diff (because things are being added or removed from the scene) the first thing is does is clear out the maintained diffscene_
. The problem with this approach is that theplanning_scene_monitor_
is only updating it'sparent_scene_
at a 2Hz rate. Depending on when the trajectory finishes vs the last time theparent_scene_
was updated it could contain stale robot state information and by calling scene_->clearDiffs() we throw all of our updated robot state information away before wesetPlanningSceneMsg
with a message that does not contain robot_state so it uses the old values it had from the last sync.To fix the issue this PR checks if the
newPlanningSceneMessage
contains a robot_state. If it does not it updates theparent_scene_
with the latest information from thecurrent_state_monitor_
before callingsetPlanningSceneMsg(scene)
to ensure that the new scene is applied with the most up to date robot_state information.This is an automatic backport of pull request #3187 done by Mergify.