gazebosim / gazebo-classic

Gazebo classic. For the latest version, see https://github.com/gazebosim/gz-sim
http://classic.gazebosim.org/
Other
1.17k stars 476 forks source link

GetRealTime resets with each call to gazebo::runWorld #1216

Open osrf-migration opened 10 years ago

osrf-migration commented 10 years ago

Original report (archived issue) by Steve Peters (Bitbucket: Steven Peters, GitHub: scpeters).


From #1145: the custom_main example calls gazebo::runWorld() repeatedly.

With the following modification, the example will print out sim time and real time:

diff -r 8086bf6d9e7ee1b46bf9e21f90b35456aa881c60 examples/stand_alone/custom_main/custom_main.cc
--- a/examples/stand_alone/custom_main/custom_main.cc   Tue Jun 17 17:35:46 2014 -0700
+++ b/examples/stand_alone/custom_main/custom_main.cc   Tue Jun 24 16:45:04 2014 -0700
@@ -25,15 +25,25 @@
   // Initialize gazebo.
   gazebo::setupServer(_argc, _argv);

+  gazebo::common::Console::SetQuiet(false);
+
   // Load a world
   gazebo::physics::WorldPtr world = gazebo::loadWorld("worlds/empty.world");

   // This is your custom main loop. In this example the main loop is just a
   // for loop with 2 iterations.
-  for (unsigned int i = 0; i < 2; ++i)
+  for (unsigned int i = 0; i < 2000; ++i)
   {
     // Run simulation for 100 steps.
+    gzerr << "world " << i
+          << " sim " << world->GetSimTime()
+          << " real " << world->GetRealTime()
+          << std::endl;
     gazebo::runWorld(world, 100);
+    gzerr << "world " << i
+          << " sim " << world->GetSimTime()
+          << " real " << world->GetRealTime()
+          << std::endl;
   }

   // Close everything.

The sim time accumulates with successive calls to gazebo::runWorld(), but the real time does not accumulate.

This occurs because World::GetRealTime subtracts the value of World::startTime from the current wall time, and World::startTime is reset by each call to World::RunLoop.

For reference, gazebo::runWorld calls World::RunBlocking, which calls World::RunLoop.

osrf-migration commented 7 years ago

Original comment by Nate Koenig (Bitbucket: Nathan Koenig).