ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
I don't see a different way. One slight enhancement tho. In the post mentioned, the node waits 2 seconds. You can also write a function that checks the planning scene and makes sure your update got noted. I saw a snippet on the internet with something similar to this:
# Ensuring Collision Updates Are Received
def wait_till_updated(pl_scene, obj_name, attached, known, sleep_duration=0.5):
"""
Wait until the planning scene was updated
:param pl_scene: planning scene
:param obj_name: name of the object to be updated
:param attached: is the object now attached
:param known: is the object now known
:param sleep_duration: sleep between checks
:return: success
"""
start = rospy.get_time()
seconds = rospy.get_time()
timeout = 5
while (seconds - start < timeout) and not rospy.is_shutdown():
# Test if the object is in attached objects
attached_objects = pl_scene.get_attached_objects([obj_name])
is_attached = len(attached_objects.keys()) > 0
rospy.logdebug("[wait_till_updated] Attached Objects: %s" % attached_objects.keys())
# Test if the object is in the scene.
# Note that attaching the box will remove it from known_objects
is_known = obj_name in pl_scene.get_known_object_names()
rospy.logdebug("[wait_till_updated] Known Objects: %s" %
pl_scene.get_known_object_names())
# Test if we are in the expected state
if (attached == is_attached) and (known == is_known):
return True
# Sleep so that we give other threads time on the processor
rospy.logdebug("[wait_till_updated] Waiting ...")
rospy.sleep(sleep_duration)
seconds = rospy.get_time()