simulation vs real time

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

simulation vs real time

Ziathon
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
Reply | Threaded
Open this post in threaded view
|

Re: simulation vs real time

Séverin Lemaignan
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/playerstage-gazebo
Reply | Threaded
Open this post in threaded view
|

Re: simulation vs real time

John Hsu-2
The way it's done for PR2 simulation is by building a mechanism controller
plugin that is called once per simulation time tick.  The rate can be
throttled by checking sim-time elapsed since last plugin update call.  In
effect, exact 'real-time' loop in simulation is achieved.  Please see
http://pr.willowgarage.com/wiki/gazebo_plugin
and
http://pr.willowgarage.com/pr-docs/ros-packages/gazebo_plugin/html/index.html
for reference.  For more details on mechanism controller plugin, follow the
link
http://pr.willowgarage.com/pr-docs/ros-packages/gazebo_plugin/html/classgazebo_1_1GazeboMechanismControl.html

some sample tutorials exist in
http://pr.willowgarage.com/wiki/Simulator/Tutorial

Hope this helps,
John


On Mon, Oct 6, 2008 at 11:41 PM, Séverin Lemaignan <
[hidden email]> 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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/playerstage-gazebo
>



--
John Hsu
Willow Garage
650-475-2809
510-326-2816
-------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/playerstage-gazebo
Reply | Threaded
Open this post in threaded view
|

Re: simulation vs real time

ucamel
In reply to this post by Séverin Lemaignan


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
Playerstage-gazebo@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/playerstage-gazebo
Reply | Threaded
Open this post in threaded view
|

Re: simulation vs real time

iche033

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
>> [hidden email]
>> 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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/playerstage-gazebo
Reply | Threaded
Open this post in threaded view
|

Re: simulation vs real time

Piotr Trojanek
In reply to this post by ucamel
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 <[hidden email]> 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
> >> [hidden email]
> >> 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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/playerstage-gazebo
>


--
Piotr Trojanek

------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/playerstage-gazebo

gazebo-realtime_physics.diff (1K) Download Attachment