Revision: 6426
http://playerstage.svn.sourceforge.net/playerstage/?rev=6426&view=rev
Author: robotos
Date: 2008-05-11 18:22:45 -0700 (Sun, 11 May 2008)
Log Message:
-----------
Negative numbers in update rate will make the rendering or physics update rate
dependent
one of each other.
Change default behaviour of Gazebo from a 1:1 physics:rendering update to a 3:1
In most hardware this makes the simulation feel faster.
Modified Paths:
--------------
code/gazebo/trunk/doc/config_syntax.html
code/gazebo/trunk/server/Simulator.cc
code/gazebo/trunk/server/rendering/OgreAdaptor.cc
Modified: code/gazebo/trunk/doc/config_syntax.html
===================================================================
--- code/gazebo/trunk/doc/config_syntax.html 2008-05-12 00:09:57 UTC (rev
6425)
+++ code/gazebo/trunk/doc/config_syntax.html 2008-05-12 01:22:45 UTC (rev
6426)
@@ -183,6 +183,7 @@
\verbatim
<physics:ode>
+ <updateRate>0</updateRate>
<stepTime>0.03</stepTime>
<gravity>0 0 -9.8</gravity>
<cfm>0.008</cfm>
@@ -193,7 +194,13 @@
- gravity : Vector that describes the direction and magnitude of gravity.
- cfm : The global constraint force mixing.
- erp : The global error reduction parameter.
+- updateRate: number of times per second the physics simulation will try to
update. This value is interpreted as:
+- 0 : as fast as possible
+- more than 0 : Maximum number of times the simulator will update physics each
second (limit speed, save CPU, etc.)
+- less than 0 : How many rendering update cycles we will wait till we update
one physic cycle
+The defaults are 0 physics updateRate (as fast as possible) and -3 render
updateRate (update 3 times physics prior updating rendering)
+
\section worldfile_gui GUI Syntax
This declaration indicates what GUI to use, and some basic parameters such as
size and position of the GUI.
@@ -265,6 +272,18 @@
- linearStart : Distance from the camera to begin rendering fog
- linearEnd : Distance from the camera to stop rendering fog
+The update rate (Frames Per Second) is specified using:
+\verbatim
+ <updateRate>0</updateRate>
+\endverbatim
+updateRate: number of times per second the rendering will try to update. This
value is interpreted as:
+- 0 : as fast as possible
+- more than 0 : Maximum number of times the simulator will render each second
(maximum Framerate)
+- less than 0 : How many physics update cycles we will wait till we update one
render cycle
+The defaults are 0 physics updateRate (as fast as possible) and -3 render
updateRate (update 3 times physics updates prior updating rendering)
+
+Note that if the limits of physics and rendering updating rates are not
related, no lineal behaviour can be seen even when the simulation is lineal.
+
OGRE resources are specified using the following (most people should only
change the path information to match where they installed Gazebo):
\verbatim
<plugins path="/usr/local/lib/OGRE">
Modified: code/gazebo/trunk/server/Simulator.cc
===================================================================
--- code/gazebo/trunk/server/Simulator.cc 2008-05-12 00:09:57 UTC (rev
6425)
+++ code/gazebo/trunk/server/Simulator.cc 2008-05-12 01:22:45 UTC (rev
6426)
@@ -211,19 +211,23 @@
/// Main simulation loop, when this loop ends the simulation finish
void Simulator::MainLoop()
{
- double maxPhysicsUpdateRate =
World::Instance()->GetPhysicsEngine()->GetUpdateRate();
- double maxRenderUpdateRate = OgreAdaptor::Instance()->GetUpdateRate();
+ double maxPhysicsUpdateTime =
World::Instance()->GetPhysicsEngine()->GetUpdateRate();
+ double maxRenderUpdateTime = OgreAdaptor::Instance()->GetUpdateRate();
double step = World::Instance()->GetPhysicsEngine()->GetStepTime();
- if (maxPhysicsUpdateRate == 0)
+ if (maxPhysicsUpdateTime == 0)
gzmsg(2) << "updating the physics at full speed";
+ else if (maxPhysicsUpdateTime > 0)
+ gzmsg(2) << "updating the physics " << 1/maxPhysicsUpdateTime << " times
per second";
else
- gzmsg(2) << "updating the physics " << 1/maxPhysicsUpdateRate << "
times/seconds";
+ gzmsg(2) << "updating the physics after " << -1/maxPhysicsUpdateTime << "
visualization updates";
- if (maxRenderUpdateRate == 0)
+ if (maxRenderUpdateTime == 0)
gzmsg(2) << "updating the visualization at full speed";
+ else if (maxRenderUpdateTime > 0)
+ gzmsg(2) << "updating the visualization " << 1/maxRenderUpdateTime << "
times per second";
else
- gzmsg(2) << "updating the visualization " << 1/maxRenderUpdateRate << "
times/seconds";
+ gzmsg(2) << "updating the visualization " << -1/maxRenderUpdateTime << "
times per each physics updates";
std::cout.flush();
while (!this->userQuit)
@@ -231,7 +235,8 @@
bool updated=false;
//During 3 seconds we want to keep balance between how time pass and
update limits
- //this is a time slot
+ //this is a time slot. We don't want to make this too big so we keep
changing behaviour
+ // in new circunstances, nor too small so we have a good measure.
if ((this->checkpoint + 3 )< this->GetRealTime())
{
this->checkpoint = this->GetRealTime();
@@ -239,11 +244,15 @@
this->renderUpdates = 0;
}
- // Update the physics engine
- // maxPhysicsUpdateRate * physicsUpdates means how much we have
_advanced_ in this time slot so far.
- // getRealTime - ckeckpoint means our +current point_ in the slot, we
only update if our current point has
+ // Update the physics engine
+ // If maxPhysicsUpdateTime is positive, we will update when our time has
come
+ // maxPhysicsUpdateTime * physicsUpdates means how much we have
_advanced_ in this time slot so far.
+ // getRealTime - ckeckpoint means our _current point_ in the slot, we
only update if our current point has
// surpassed what we have already advanced.
- if ((this->GetRealTime() - this->checkpoint) > (maxPhysicsUpdateRate *
this->physicsUpdates))
+ // If maxPhysicsUpdateTime is negative, we update if we are below the times
rendering was updated * the multiplier of the userPause
+ // note that the multiplier defined in the file is inverted when read so
for instance -2 will become -0.5
+ if ((maxPhysicsUpdateTime >= 0) && ((this->GetRealTime() -
this->checkpoint) > (maxPhysicsUpdateTime * this->physicsUpdates)) || \
+ ((maxPhysicsUpdateTime < 0) && (this->physicsUpdates <
(-maxPhysicsUpdateTime * this->renderUpdates))))
{
if (!this->GetUserPause() && !this->GetUserStep() ||
@@ -265,9 +274,10 @@
this->physicsUpdates++;
updated=true;
}
-
+
// Update the rendering and gui
- if ((this->GetRealTime() - this->checkpoint) > (maxRenderUpdateRate *
this->renderUpdates))
+ if (((maxRenderUpdateTime >= 0) && ((this->GetRealTime() -
this->checkpoint) > (maxRenderUpdateTime * this->renderUpdates))) || \
+ ((maxRenderUpdateTime < 0) && (this->renderUpdates <
(-maxRenderUpdateTime * this->physicsUpdates))))
{
gazebo::OgreAdaptor::Instance()->Render();
this->gui->Update();
@@ -278,12 +288,15 @@
if (!updated)
{
double nextUpdate;
- nextUpdate=MIN(this->renderUpdates+maxRenderUpdateRate,
this->renderUpdates+maxPhysicsUpdateRate);
- int realStep = static_cast<int>(nextUpdate - this->GetRealTime());
- struct timespec waiting;
- waiting.tv_sec=0;
- waiting.tv_nsec=realStep *1000000000; //nanoseconds to seconds
- //nanosleep(&waiting,0);
+ nextUpdate=MIN(this->renderUpdates * maxRenderUpdateTime,
this->renderUpdates * maxPhysicsUpdateTime);
+ double realStep = this->checkpoint + nextUpdate - this->GetRealTime();
+ if (realStep > 0)
+ {
+ struct timespec waiting;
+ waiting.tv_sec=0;
+ waiting.tv_nsec=static_cast<long int>(realStep *1000000000);
//nanoseconds to seconds
+ nanosleep(&waiting,0);
+ }
}
}
}
Modified: code/gazebo/trunk/server/rendering/OgreAdaptor.cc
===================================================================
--- code/gazebo/trunk/server/rendering/OgreAdaptor.cc 2008-05-12 00:09:57 UTC
(rev 6425)
+++ code/gazebo/trunk/server/rendering/OgreAdaptor.cc 2008-05-12 01:22:45 UTC
(rev 6426)
@@ -125,7 +125,7 @@
gzthrow( "missing OGRE Rendering information" );
}
- int maxFPS = node->GetInt("updateRate", 0);
+ int maxFPS = node->GetInt("updateRate", -3);
if (maxFPS == 0)
this->updateRate=0;
else
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit