Revision: 7760
http://playerstage.svn.sourceforge.net/playerstage/?rev=7760&view=rev
Author: hsujohnhsu
Date: 2009-06-02 21:27:43 +0000 (Tue, 02 Jun 2009)
Log Message:
-----------
Merging from trunk.
Modified Paths:
--------------
code/gazebo/branches/threads/server/Simulator.cc
code/gazebo/branches/threads/server/Simulator.hh
code/gazebo/branches/threads/server/World.cc
code/gazebo/branches/threads/server/physics/PhysicsEngine.cc
code/gazebo/branches/threads/worlds/pioneer2dx.world
code/gazebo/branches/threads/worlds/simpleshapes.world
Property Changed:
----------------
code/gazebo/branches/threads/
code/gazebo/branches/threads/cmake/libgazebo_pkgconfig.cmake
Property changes on: code/gazebo/branches/threads
___________________________________________________________________
Modified: svn:mergeinfo
- /code/branches/federation/gazebo:7371-7550
/code/gazebo/branches/ogre-1.4.9:7137-7636
/code/gazebo/trunk:7723-7753
+ /code/branches/federation/gazebo:7371-7550
/code/gazebo/branches/ogre-1.4.9:7137-7636
/code/gazebo/trunk:7722-7759
Property changes on:
code/gazebo/branches/threads/cmake/libgazebo_pkgconfig.cmake
___________________________________________________________________
Modified: svn:mergeinfo
-
/code/branches/federation/gazebo/cmake/libgazeboshm_pkgconfig.cmake:7371-7550
/code/gazebo/branches/ogre-1.4.9/cmake/libgazeboshm_pkgconfig.cmake:7137-7636
/code/gazebo/trunk/cmake/libgazebo_pkgconfig.cmake:7723-7753
+
/code/branches/federation/gazebo/cmake/libgazeboshm_pkgconfig.cmake:7371-7550
/code/gazebo/branches/ogre-1.4.9/cmake/libgazeboshm_pkgconfig.cmake:7137-7636
/code/gazebo/trunk/cmake/libgazebo_pkgconfig.cmake:7722-7759
Modified: code/gazebo/branches/threads/server/Simulator.cc
===================================================================
--- code/gazebo/branches/threads/server/Simulator.cc 2009-06-02 20:35:01 UTC
(rev 7759)
+++ code/gazebo/branches/threads/server/Simulator.cc 2009-06-02 21:27:43 UTC
(rev 7760)
@@ -60,7 +60,6 @@
gazeboConfig(NULL),
loaded(false),
pause(false),
- iterations(0),
simTime(0.0),
pauseTime(0.0),
startTime(0.0),
@@ -449,13 +448,6 @@
}
////////////////////////////////////////////////////////////////////////////////
-/// Get the number of iterations of this simulation session
-unsigned long Simulator::GetIterations() const
-{
- return this->iterations;
-}
-
-////////////////////////////////////////////////////////////////////////////////
// Get the simulation time
double Simulator::GetSimTime() const
{
@@ -663,11 +655,12 @@
double step = world->GetPhysicsEngine()->GetStepTime();
double physicsUpdateRate = world->GetPhysicsEngine()->GetUpdateRate();
double physicsUpdatePeriod = 1.0 / physicsUpdateRate;
-
+
+ double diffTime;
double currTime;
+ double lastTime = this->GetRealTime();
+ struct timespec req, rem;
- this->prevPhysicsTime = this->GetRealTime();
-
/*************************************************/
/* */
/* thread control */
@@ -720,16 +713,14 @@
currTime = this->GetRealTime();
- if (physicsUpdateRate == 0 ||
- currTime - this->prevPhysicsTime >= physicsUpdatePeriod)
+ //if (physicsUpdateRate == 0 ||
+ //currTime - lastTime >= physicsUpdatePeriod)
{
- this->prevPhysicsTime = this->GetRealTime();
// Update the physics engine
if (!this->IsPaused())
{
this->simTime += step;
- this->iterations++;
this->SetUserStepInc(!this->GetUserStepInc());
}
else
@@ -737,18 +728,42 @@
this->pauseTime += step;
}
+ lastTime = this->GetRealTime();
// lock mutex and update physics
{
world->UpdatePhysics();
}
- // if we are throttling physics update rate
- // if (physicsUpdateRate != 0 &&
- // this->GetRealTime() - this->prevPhysicsTime < physicsUpdatePeriod)
- // {
- // usleep((physicsUpdatePeriod - (currTime - this->prevRenderTime)) *
1e6);
- // }
- usleep(1);
+ currTime = this->GetRealTime();
+
+ // Set a default sleep time
+ req.tv_sec = 0;
+ req.tv_nsec = 10000;
+
+ // If the physicsUpdateRate < 0, then we should try to match the
+ // update rate to real time
+ if ( physicsUpdateRate < 0 &&
+ (this->GetSimTime() + this->GetPauseTime()) >
+ this->GetRealTime())
+ {
+ diffTime = (this->GetSimTime() + this->GetPauseTime()) -
+ this->GetRealTime();
+ req.tv_sec = (int) floor(diffTime);
+ req.tv_nsec = (int) (fmod(diffTime, 1.0) * 1e9);
+ }
+ // Otherwise try to match the update rate to the one specified in
+ // the xml file
+ else if (physicsUpdateRate > 0 &&
+ currTime - lastTime < physicsUpdatePeriod)
+ {
+ diffTime = physicsUpdatePeriod - (currTime - lastTime);
+
+ req.tv_sec = (int) floor(diffTime);
+ req.tv_nsec = (int) (fmod(diffTime, 1.0) * 1e9);
+ }
+
+ nanosleep(&req, &rem);
+
}
// Process all incoming messages from simiface
@@ -759,11 +774,10 @@
this->userQuit = true;
break;
}
-
- // // thread control
#ifdef TIMING
double tmpT2 = this->GetWallTime();
- std::cout << " Simulator::PhysicsLoop() DT(" << tmpT2-tmpT1 << ")" <<
std::endl;
+ std::cout << " Simulator::PhysicsLoop() DT(" << tmpT2-tmpT1
+ << ")" << std::endl;
#endif
}
Modified: code/gazebo/branches/threads/server/Simulator.hh
===================================================================
--- code/gazebo/branches/threads/server/Simulator.hh 2009-06-02 20:35:01 UTC
(rev 7759)
+++ code/gazebo/branches/threads/server/Simulator.hh 2009-06-02 21:27:43 UTC
(rev 7760)
@@ -98,15 +98,6 @@
/// \brief Set whether the simulation is paused
public: void SetPaused(bool p);
- /// \brief Get the number of iterations
- public: unsigned long GetIterations() const;
-/*
- /// \brief Set the number of iterations
- public: static void SetIterations(unsigned long count);
-
- /// \brief Increment the number of iterations
- public: static void IncIterations();
-*/
/// Get the simulation time
/// \return The simulation time
public: double GetSimTime() const;
@@ -204,12 +195,8 @@
/// Flag set if simulation is paused
private: bool pause;
- /// Count of the number of iterations
- private: unsigned long iterations;
-
/// Current simulation time
private: double simTime, pauseTime, startTime;
- private: double prevPhysicsTime, prevRenderTime;
//upper limits on updating
//how many updates we have done in this slot
@@ -293,6 +280,8 @@
public: void CollisionDone();
public: void ModelsDone();
+ private: double prevRenderTime;
+
//Singleton implementation
private: friend class DestroyerT<Simulator>;
private: friend class SingletonT<Simulator>;
Modified: code/gazebo/branches/threads/server/World.cc
===================================================================
--- code/gazebo/branches/threads/server/World.cc 2009-06-02 20:35:01 UTC
(rev 7759)
+++ code/gazebo/branches/threads/server/World.cc 2009-06-02 21:27:43 UTC
(rev 7760)
@@ -572,7 +572,7 @@
this->SetModelPose(model, model->GetInitPose());
// Add the model to our list
- if (Simulator::Instance()->GetIterations() == 0)
+ if (Simulator::Instance()->GetSimTime() == 0)
this->models.push_back(model);
else
{
Modified: code/gazebo/branches/threads/server/physics/PhysicsEngine.cc
===================================================================
--- code/gazebo/branches/threads/server/physics/PhysicsEngine.cc
2009-06-02 20:35:01 UTC (rev 7759)
+++ code/gazebo/branches/threads/server/physics/PhysicsEngine.cc
2009-06-02 21:27:43 UTC (rev 7760)
@@ -36,7 +36,7 @@
{
Param::Begin(&this->parameters);
this->gravityP = new ParamT<Vector3>("gravity",Vector3(0.0, -9.80665, 0.0),
0);
- this->updateRateP = new ParamT<double>("maxUpdateRate", 0.0, 0);
+ this->updateRateP = new ParamT<double>("updateRate", 0.0, 0);
this->stepTimeP = new ParamT<double>("stepTime",0.025,0);
Param::End();
Modified: code/gazebo/branches/threads/worlds/pioneer2dx.world
===================================================================
--- code/gazebo/branches/threads/worlds/pioneer2dx.world 2009-06-02
20:35:01 UTC (rev 7759)
+++ code/gazebo/branches/threads/worlds/pioneer2dx.world 2009-06-02
21:27:43 UTC (rev 7760)
@@ -23,6 +23,10 @@
<gravity>0 0 -9.8</gravity>
<cfm>10e-5</cfm>
<erp>0.3</erp>
+ <!-- updateRate: <0 == throttle simTime to match realTime.
+ 0 == No throttling
+ >0 == Frequency at which to throttle the sim -->
+ <updateRate>-1</updateRate>
</physics:ode>
<rendering:gui>
Modified: code/gazebo/branches/threads/worlds/simpleshapes.world
===================================================================
--- code/gazebo/branches/threads/worlds/simpleshapes.world 2009-06-02
20:35:01 UTC (rev 7759)
+++ code/gazebo/branches/threads/worlds/simpleshapes.world 2009-06-02
21:27:43 UTC (rev 7760)
@@ -19,6 +19,11 @@
<gravity>0 0 -9.8</gravity>
<cfm>10e-2</cfm>
<erp>0.2</erp>
+
+ <!-- updateRate: <0 == throttle simTime to match realTime.
+ 0 == No throttling
+ >0 == Frequency at which to throttle the sim -->
+ <updateRate>-1</updateRate>
</physics:ode>
<rendering:gui>
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises
looking to deploy the next generation of Solaris that includes the latest
innovations from Sun and the OpenSource community. Download a copy and
enjoy capabilities such as Networking, Storage and Virtualization.
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit