5

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?

Benyamin Jafari
  • 242
  • 2
  • 12
kNo
  • 151
  • 2
  • 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 – N. Staub Aug 20 '18 at 18:45
  • Thanks N. Staub, your solution is not perfect, but good enougth – kNo Aug 22 '18 at 12:18

1 Answers1

1

@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.

al-dev
  • 331
  • 1
  • 6
  • How can make my python script sleep for 5 simulation time seconds using ros::Time and /clock? – kNo Aug 23 '18 at 09:30
  • 1
    http://wiki.ros.org/rospy/Overview/Time#Sleeping_and_Rates : rospy.sleep(5.) (Assuming your simulator is publishing the simulation time on /clock) – al-dev Aug 23 '18 at 10:28
  • But this will stop simulation for 5 seconds in simulation time, not my script. I want my code to stop for 5 seconds in simulation time. I'm following this tutorial: https://www.linkedin.com/pulse/using-openai-gym-ros-ricardo-tellez/ There, the controller chooses an action, sends it to ROS, unpauses the simulation, sleeps for a time and pauses ROS again. It only works if ROS works in real time. – kNo Aug 24 '18 at 07:42
  • @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? – al-dev 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(). – Tully Aug 26 '21 at 21:37