# Wait simulation time in a non realtime ROS simulation in Python

I want to control a quadrotor with a Python script and run the simulation as fast as my laptop can, not only in real time. I've modified my world and now the simulation runs with 7-10 real time factor.

My problem is that after acting I want the physics to run for a determinate amount of simulation time, but if I do time.sleep(steptime) the sleep is in real time, which is 7-10 times simulation time. So I need to know the real time factor in Python to divide the sleep time. Is there a way to get it?

• I would suggest to log machine time at begininng of the program and keep track of the simulation time, you can then compare them at each iteration Aug 20 '18 at 18:45
• Thanks N. Staub, your solution is not perfect, but good enougth
– kNo
Aug 22 '18 at 12:18

@kNo the proper way to use time in ROS is generally to use the ros::Time abstraction and the /clock topic. This way you can use the same program with simulated and real time. Your simulator program should be the one publishing on /clock. Trying to access the real time factor is unnecessarily complicated.
• wiki.ros.org/rospy/Overview/Time#Sleeping_and_Rates : rospy.sleep(5.) (Assuming your simulator is publishing the simulation time on /clock) Aug 23 '18 at 10:28
• @kNo sorry I am getting confused. You say: " I want my code to stop for 5 seconds in simulation time. " This is exactly what rospy.sleep(5.) does. Could you give us some sample code to understand what you are trying to achieve? Aug 24 '18 at 10:00
• The pausing of the simulation in the openai gym tutorial is achieved by calling self.gazebo.pauseSim() not by the invocation of the rospy.sleep(). Aug 26 at 21:37