Revision: 7503
          http://playerstage.svn.sourceforge.net/playerstage/?rev=7503&view=rev
Author:   hsujohnhsu
Date:     2009-03-17 01:10:29 +0000 (Tue, 17 Mar 2009)

Log Message:
-----------
added more function calls for getting sim and wall clock time.

Modified Paths:
--------------
    code/gazebo/branches/ogre-1.4.9/server/World.cc
    code/gazebo/branches/ogre-1.4.9/server/World.hh

Modified: code/gazebo/branches/ogre-1.4.9/server/World.cc
===================================================================
--- code/gazebo/branches/ogre-1.4.9/server/World.cc     2009-03-17 01:06:00 UTC 
(rev 7502)
+++ code/gazebo/branches/ogre-1.4.9/server/World.cc     2009-03-17 01:10:29 UTC 
(rev 7503)
@@ -27,6 +27,7 @@
 #include <assert.h>
 #include <sstream>
 #include <fstream>
+#include <sys/time.h> //gettimeofday
 
 #include "Global.hh"
 #include "GazeboError.hh"
@@ -57,6 +58,10 @@
   this->server = NULL;
   this->simIface = NULL;
 
+  this->simTime = 0.0;
+  this->pauseTime = 0.0;
+  this->startTime = 0.0;
+
 }
 
 
////////////////////////////////////////////////////////////////////////////////
@@ -172,6 +177,7 @@
 
   this->physicsEngine->Init();
 
+  this->startTime = this->GetWallTime();
   this->toAddModels.clear();
   this->toDeleteModels.clear();
 
@@ -182,10 +188,15 @@
 // Update the world
 int World::Update()
 {
-  std::vector< Model* >::iterator miter;
-  std::vector< Model* >::iterator miter2;
 
+  this->simTime += this->physicsEngine->GetStepTime();
+
+#ifdef TIMING
+  double tmpT1 = this->GetWallTime();
+#endif
+
   // Update all the models
+  std::vector< Model* >::iterator miter;
   for (miter=this->models.begin(); miter!=this->models.end(); miter++)
   {
     if (*miter)
@@ -194,14 +205,47 @@
     }
   }
 
+#ifdef TIMING
+  double tmpT2 = this->GetWallTime();
+  std::cout << " World::Update() ALL Models update DT(" << tmpT2-tmpT1 << ")" 
<< std::endl;
+#endif
+// if using threads, the sim time is actually a bit slower,
+// with pr2_wg, the collision time is roughly 1ms, so is the time it takes to 
setup a new thread
+// models update takes about 1.7ms, not much gain here by making them into 2 
threads.
+
+  // if (!Simulator::Instance()->IsPaused() &&
+  //      Simulator::Instance()->GetPhysicsEnabled())
+  // {
+  //   this->physicsEngine->UpdateCollision();
+  // }
+
+#ifdef TIMING
+  double tmpT3 = this->GetWallTime();
+  std::cout << " World::Update() Collision DT(" << tmpT3-tmpT2 << ")" << 
std::endl;
+#endif
+
   if (!Simulator::Instance()->IsPaused() &&
        Simulator::Instance()->GetPhysicsEnabled())
   {
-    this->physicsEngine->Update();
+    this->physicsEngine->UpdatePhysics();
   }
+  else
+  {
+    this->pauseTime += this->physicsEngine->GetStepTime();
+  }
 
+#ifdef TIMING
+  double tmpT4 = this->GetWallTime();
+  std::cout << " World::Update() Physics engine DT(" << tmpT4-tmpT3 << ")" << 
std::endl;
+#endif
+
   this->UpdateSimulationIface();
 
+#ifdef TIMING
+  double tmpT5 = this->GetWallTime();
+  std::cout << " World::Update() Iface DT(" << tmpT5-tmpT4 << ")" << std::endl;
+#endif
+
   // Copy the newly created models into the main model vector
   std::copy(this->toAddModels.begin(), this->toAddModels.end(),
             std::back_inserter(this->models));
@@ -219,6 +263,12 @@
 
   this->toDeleteModels.clear();
 
+#ifdef TIMING
+  double tmpT6 = this->GetWallTime();
+  std::cout << " World::Update() add/del models dt(" << tmpT6-tmpT5 << ")" << 
std::endl;
+#endif
+
+
   return 0;
 }
 
@@ -273,6 +323,41 @@
   return this->physicsEngine;
 }
 
+////////////////////////////////////////////////////////////////////////////////
+// Get the simulation time
+double World::GetSimTime() const
+{
+  return this->simTime;
+}
+////////////////////////////////////////////////////////////////////////////////
+// Get the pause time
+double World::GetPauseTime() const
+{
+  return this->pauseTime;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Get the start time
+double World::GetStartTime() const
+{
+  return this->startTime;
+}
+////////////////////////////////////////////////////////////////////////////////
+/// Get the real time (elapsed time)
+double World::GetRealTime() const
+{
+  return this->GetWallTime() - this->startTime;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Get the wall clock time
+double World::GetWallTime() const
+{
+  struct timeval tv;
+  gettimeofday(&tv, NULL);
+  return tv.tv_sec + tv.tv_usec * 1e-6;
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 // Load a model
 int World::LoadEntities(XMLConfigNode *node, Model *parent)

Modified: code/gazebo/branches/ogre-1.4.9/server/World.hh
===================================================================
--- code/gazebo/branches/ogre-1.4.9/server/World.hh     2009-03-17 01:06:00 UTC 
(rev 7502)
+++ code/gazebo/branches/ogre-1.4.9/server/World.hh     2009-03-17 01:10:29 UTC 
(rev 7503)
@@ -92,6 +92,26 @@
   /// \return Pointer to the physics engine
   public: PhysicsEngine *GetPhysicsEngine() const;
 
+  /// Get the simulation time
+  /// \return The simulation time
+  public: double GetSimTime() const;
+
+  /// Get the pause time
+  /// \return The pause time
+  public: double GetPauseTime() const;
+
+  /// Get the start time
+  /// \return The start time
+  public: double GetStartTime() const;
+
+  /// Get the real time (elapsed time)
+  /// \return The real time
+  public: double GetRealTime() const;
+
+  /// \brief Get the wall clock time
+  /// \return The wall clock time
+  public: double GetWallTime() const;
+
   /// \brief Load all entities
   /// \param node XMLConfg node pointer
   /// \param parent Parent of the model to load
@@ -186,8 +206,12 @@
   /// Simulation interface
   private: SimulationIface *simIface;
 
+  /// Current simulation time
+  private: double simTime, pauseTime, startTime;
+
   private: friend class DestroyerT<World>;
   private: friend class SingletonT<World>;
+
 };
 
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to