I have solved this issue using the code fragment from older incarnation of
Gazebo (patch attached).

On Wed, Mar 25, 2009 at 09:54, iche033 <[email protected]> wrote:

>
> Hi
>
> You can try force the physics engine to step in real time. Note that this
> method requires modifying the gazebo source code, so use with care. It
> works
> quite well for me.
>
> in Simulator.cc, function MainLoop()
> //declare 2 variables at the beginning
> bool syncTime = false;
> double cache = 0;
> ..
> //and replace the following line in the while loop
>
> World::Instance()->Update();
>
> //with
>
> this->step = World::Instance()->GetPhysicsEngine()->GetStepTime(); //resets
> the step amount
> if ( !syncTime){
>        this->startTime = this->GetWallTime() - simTime; // init real time
> to be
> the same as sim time
>        syncTime = true;
> }
> double elapsed = this->GetRealTime() - this->simTime;
> cache += elapsed;
> // steps the ODE by time elapsed in real world since last update using
> fixed
> time step
> while(cache >= step)
> {
>        World::Instance()->Update();
>        cache -= this->step;
> }
> this->step = elapsed - cache; // changes step amount so simTime gets
> incremented correctly
>
> cheers
> Ian
>
>
> ucamel wrote:
> >
> >
> >
> > Hello:
> > This post is a bit old but it could help some people...
> > I had the same proble and i fixed it changing the step time in the .cfg
> > that you load to gazebo.
> >
> >
> >
> > Séverin Lemaignan wrote:
> >>
> >> I've more or less the same question in a wider context (hybrid
> >> simulation): how can we constraint the simulator to stick to real time?
> >>
> >> Regards,
> >> Severin Lemaignan
> >>
> >> Ziathon a écrit :
> >>> Hello,
> >>>
> >>> I've been experimenting with turning the p2 robot.  I've been trying to
> >>> time
> >>> it such that it stops exactly once it's done a 90 degree turn.  The
> >>> problem
> >>> is calling sleep doesn't work because the simulation time rate is often
> >>> different than the rate time really passes.  Any recommendations on how
> >>> to
> >>> get around this?
> >>>
> >>> Thanks
> >>
> >>
> -------------------------------------------------------------------------
> >> This SF.Net email is sponsored by the Moblin Your Move Developer's
> >> challenge
> >> Build the coolest Linux based applications with Moblin SDK & win great
> >> prizes
> >> Grand prize is a trip for two to an Open Source event anywhere in the
> >> world
> >> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> >> _______________________________________________
> >> Playerstage-gazebo mailing list
> >> [email protected]
> >> https://lists.sourceforge.net/lists/listinfo/playerstage-gazebo
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/simulation-vs-real-time-tp19772617p22696684.html
> Sent from the playerstage-gazebo mailing list archive at Nabble.com.
>
>
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by:
> High Quality Requirements in a Collaborative Environment.
> Download a free trial of Rational Requirements Composer Now!
> http://p.sf.net/sfu/www-ibm-com
> _______________________________________________
> Playerstage-gazebo mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/playerstage-gazebo
>



-- 
Piotr Trojanek
Index: server/Simulator.cc
===================================================================
--- server/Simulator.cc (revision 7557)
+++ server/Simulator.cc (working copy)
@@ -594,7 +594,15 @@
         boost::recursive_mutex::scoped_lock lock(*this->mutex);
         world->Update();
       }
-      usleep(1);
+      //usleep(1);
+      if ((this->GetSimTime() + this->GetPauseTime()) > this->GetRealTime()) {
+        double diffTime = (this->GetSimTime() + this->GetPauseTime()) - 
this->GetRealTime();
+        struct timespec req, rem;
+        req.tv_sec  = (int) floor(diffTime);
+        req.tv_nsec = (int) (fmod(diffTime, 1.0) * 1e9);
+        nanosleep(&req, &rem);
+      }
+         
     }
 
     // Process all incoming messages from simiface
------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
Playerstage-gazebo mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-gazebo

Reply via email to