I want to reset the position of robot under certain circumstances. I am trying to do it with python node. I know we call '/reset_world" service to to this but i am unable to call it with python. What I have done so far:

from gazebo_msgs.srv import ResetWorld

class WorldResetter:
    def __init__(self):
        self.node = rclpy.create_node('world_resetter_node')
        self.client = self.node.create_client(ResetWorld, '/reset_world')

        while not self.client.wait_for_service(timeout_sec=1.0):
            self.node.get_logger().info('Service not available, waiting again...')

    def reset_world(self):
        request = ResetWorld.Request()

        future = self.client.call_async(request)
        rclpy.spin_until_future_complete(self.node, future)

        if future.result() is not None:
            self.node.get_logger().info('Simulation world reset successfully')
            self.node.get_logger().error('Failed to reset simulation world')

Error: ImportError: cannot import name 'ResetWorld' from 'gazebo_msgs.srv'.




Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.