4
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ 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 $\endgroup$ – N. Staub Aug 20 '18 at 18:45
  • $\begingroup$ Thanks N. Staub, your solution is not perfect, but good enougth $\endgroup$ – kNo Aug 22 '18 at 12:18
0
$\begingroup$

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

$\endgroup$
  • $\begingroup$ How can make my python script sleep for 5 simulation time seconds using ros::Time and /clock? $\endgroup$ – kNo Aug 23 '18 at 9:30
  • $\begingroup$ wiki.ros.org/rospy/Overview/Time#Sleeping_and_Rates : rospy.sleep(5.) (Assuming your simulator is publishing the simulation time on /clock) $\endgroup$ – al-dev Aug 23 '18 at 10:28
  • $\begingroup$ 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: 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. $\endgroup$ – kNo Aug 24 '18 at 7:42
  • $\begingroup$ @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? $\endgroup$ – al-dev Aug 24 '18 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.