Unpause / Pause Service doesn't work via python

asked 2023-01-19 03:50:21 -0600

berni025 gravatar image

Hey together,

I'm new to ros and gazebo. I'm tryin to (un)pause gazebo with python. Attached you find my code I'm using with ros-noetic und ubuntu 20.04.

By starting my code just nothing happens. No error but also no unpausing... What am I doing wrong?

If I use rosservice call in a terminal everything works as expected.

Hope you can help me! Thanks, Berni

#!/usr/bin/env python 

import rospy
from std_srvs.srv import Empty

def change_gazebo_pause_state(state):
  if state == "unpause":
    rospy.wait_for_service("/gazebo/unpause_physics")
    unpause_gazebo = rospy.ServiceProxy('/gazebo/unpause_physics', Empty)

  if state == "pause":
    rospy.wait_for_service("/gazebo/pause_physics")
    pause_gazebo = rospy.ServiceProxy("/gazebo/pause_physics", Empty)


if __name__ == '__main__':
    rospy.init_node("main")

    try:
        ####### Step 1: Unpause simulation #######
        change_gazebo_pause_state("unpause")

    except rospy.ROSInterruptException as e:
        print(e)
edit retag flag offensive close merge delete