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

Log Message:
-----------
 * update rate control for Sensor.

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

Modified: code/gazebo/branches/ogre-1.4.9/server/sensors/Sensor.cc
===================================================================
--- code/gazebo/branches/ogre-1.4.9/server/sensors/Sensor.cc    2009-03-17 
01:37:53 UTC (rev 7520)
+++ code/gazebo/branches/ogre-1.4.9/server/sensors/Sensor.cc    2009-03-17 
01:38:53 UTC (rev 7521)
@@ -33,6 +33,9 @@
 #include "ControllerFactory.hh"
 #include "Simulator.hh"
 #include "Sensor.hh"
+#include "Simulator.hh"
+#include "PhysicsEngine.hh"
+#include "Global.hh"
 
 using namespace gazebo;
 
@@ -71,6 +74,14 @@
 
   this->LoadController( node->GetChildByNSPrefix("controller") );
   this->LoadChild(node);
+
+  double updateRate  = node->GetDouble("updateRate", 0, 0);
+  if (updateRate == 0)
+    this->updatePeriod = 0.0; // no throttling if updateRate is 0
+  else
+    this->updatePeriod = 1.0 / updateRate;
+  this->lastUpdate   = Simulator::Instance()->GetSimTime();
+
 }
 
 
////////////////////////////////////////////////////////////////////////////////
@@ -104,14 +115,29 @@
 /// Update the sensor
 void Sensor::Update()
 {
-  if (this->lastUpdate + this->updatePeriod <= 
Simulator::Instance()->GetSimTime())
+
+#ifdef TIMING
+  double tmpT4 = Simulator::Instance()->GetWallTime();
+#endif
+
+
+
+  double physics_dt = World::Instance()->GetPhysicsEngine()->GetStepTime();
+  if 
(round((Simulator::Instance()->GetSimTime()-this->lastUpdate-this->updatePeriod)/physics_dt)
 >= 0)
   {
     this->UpdateChild();
     this->lastUpdate = Simulator::Instance()->GetSimTime();
   }
 
+  // update any controllers that are children of sensors, e.g. ros_bumper
   if (this->controller)
     this->controller->Update();
+
+#ifdef TIMING
+  double tmpT5 = Simulator::Instance()->GetWallTime();
+  std::cout << "               Sensor::Update (" << this->GetName() << ") dt 
(" << tmpT5-tmpT4 << ")" << std::endl;
+#endif
+
 }
 
 
////////////////////////////////////////////////////////////////////////////////
@@ -185,4 +211,11 @@
   this->active = value;
 }
 
+////////////////////////////////////////////////////////////////////////////////
+/// \brief Set whether the sensor is active or not
+bool Sensor::IsActive()
+{
+  return this->active;
+}
 
+

Modified: code/gazebo/branches/ogre-1.4.9/server/sensors/Sensor.hh
===================================================================
--- code/gazebo/branches/ogre-1.4.9/server/sensors/Sensor.hh    2009-03-17 
01:37:53 UTC (rev 7520)
+++ code/gazebo/branches/ogre-1.4.9/server/sensors/Sensor.hh    2009-03-17 
01:38:53 UTC (rev 7521)
@@ -70,6 +70,7 @@
 
     /// \brief Set whether the sensor is active or not
     public: void SetActive(bool value);
+    public: bool IsActive();
 
     /// \brief  Load the child sensor
     protected: virtual void LoadChild(XMLConfigNode * /*node*/) {};
@@ -101,7 +102,6 @@
     protected: double lastUpdate;
     protected: std::string typeName;
   };
-  
   /// \}
 }
 #endif


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