Browse Source

fix - removed prototype static and replaced with a member (#89)

Signed-off-by: Adam Dąbrowski <[email protected]>
Adam Dąbrowski 3 years ago
parent
commit
4d09a05ff4

+ 4 - 5
Gems/ROS2/Code/Source/Sensor/ROS2SensorComponent.cpp

@@ -78,15 +78,14 @@ namespace ROS2
         // TODO - add range validation (Attributes?)
         auto frameTime = frequency == 0 ? 1 : 1 / frequency;
 
-        static float elapsed = 0;
-        elapsed += deltaTime;
-        if (elapsed < frameTime)
+        m_timeElapsedSinceLastTick += deltaTime;
+        if (m_timeElapsedSinceLastTick < frameTime)
             return;
 
-        elapsed -= frameTime;
+        m_timeElapsedSinceLastTick -= frameTime;
         if (deltaTime > frameTime)
         {   // Frequency higher than possible, not catching up, just keep going with each frame.
-            elapsed = 0;
+            m_timeElapsedSinceLastTick = 0.0f;
         }
 
         // Note that sensor frequency can be limited by simulation tick rate (if higher sensor Hz is desired).

+ 2 - 0
Gems/ROS2/Code/Source/Sensor/ROS2SensorComponent.h

@@ -47,5 +47,7 @@ namespace ROS2
         //! For example, draw points or rays for a lidar, viewport for a camera, etc.
         //! Visualisation can be turned on or off in SensorConfiguration.
         virtual void Visualise() { };
+
+        float m_timeElapsedSinceLastTick = 0.0f;
     };
 }  // namespace ROS2