Skip to content

Commit

Permalink
Remove filtering from realtime factor (RTF) calculation (#1942)
Browse files Browse the repository at this point in the history
Filtering has been transferred to WorldStats plugin in gz-gui

Signed-off-by: Addisu Z. Taddese <[email protected]>
  • Loading branch information
azeey authored Apr 12, 2023
1 parent 9a9de36 commit f06d37a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 46 deletions.
2 changes: 1 addition & 1 deletion examples/worlds/camera_sensor.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<plugin
filename="gz-sim-sensors-system"
name="gz::sim::systems::Sensors">
<render_engine>ogre</render_engine>
<render_engine>ogre2</render_engine>
</plugin>
<plugin
filename="gz-sim-user-commands-system"
Expand Down
53 changes: 13 additions & 40 deletions src/SimulationRunner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,6 @@ void SimulationRunner::UpdateCurrentInfo()
if (this->requestedRewind)
{
gzdbg << "Rewinding simulation back to initial time." << std::endl;
this->realTimes.clear();
this->simTimes.clear();
this->realTimeFactor = 0;

this->currentInfo.dt = this->simTimeEpoch - this->currentInfo.simTime;
Expand All @@ -301,8 +299,6 @@ void SimulationRunner::UpdateCurrentInfo()
gzdbg << "Seeking to " << std::chrono::duration_cast<std::chrono::seconds>(
this->requestedSeek.value()).count() << "s." << std::endl;

this->realTimes.clear();
this->simTimes.clear();
this->realTimeFactor = 0;

this->currentInfo.dt = this->requestedSeek.value() -
Expand All @@ -319,41 +315,11 @@ void SimulationRunner::UpdateCurrentInfo()

// Regular time flow

// Store the real time and sim time only if not paused.
if (this->realTimeWatch.Running())
{
this->realTimes.push_back(this->realTimeWatch.ElapsedRunTime());
this->simTimes.push_back(this->currentInfo.simTime);
}

// Maintain a window size of 20 for realtime and simtime.
if (this->realTimes.size() > 20)
this->realTimes.pop_front();
if (this->simTimes.size() > 20)
this->simTimes.pop_front();

// Compute the average sim and real times.
std::chrono::steady_clock::duration simAvg{0}, realAvg{0};
std::list<std::chrono::steady_clock::duration>::iterator simIter,
realIter;

simIter = ++(this->simTimes.begin());
realIter = ++(this->realTimes.begin());
while (simIter != this->simTimes.end() && realIter != this->realTimes.end())
{
simAvg += ((*simIter) - this->simTimes.front());
realAvg += ((*realIter) - this->realTimes.front());
++simIter;
++realIter;
}
const double simTimeCount =
static_cast<double>(this->currentInfo.simTime.count());
const double realTimeCount =
static_cast<double>(this->currentInfo.realTime.count());

// RTF, only compute this if the realTime count is greater than zero. The
// realtTime count could be zero if simulation was started paused.
if (realAvg.count() > 0)
{
this->realTimeFactor = math::precision(
static_cast<double>(simAvg.count()) / realAvg.count(), 4);
}

// Fill the current update info
this->currentInfo.realTime = this->realTimeWatch.ElapsedRunTime();
Expand All @@ -368,6 +334,15 @@ void SimulationRunner::UpdateCurrentInfo()
++this->currentInfo.iterations;
this->currentInfo.dt = this->stepSize;
}
const double simTimeDiff =
static_cast<double>(this->currentInfo.simTime.count()) - simTimeCount;
const double realTimeDiff =
static_cast<double>(this->currentInfo.realTime.count()) - realTimeCount;

if (realTimeDiff > 0)
{
this->realTimeFactor = simTimeDiff / realTimeDiff;
}
}

/////////////////////////////////////////////////
Expand Down Expand Up @@ -413,8 +388,6 @@ void SimulationRunner::UpdatePhysicsParams()
}
if (updated)
{
this->simTimes.clear();
this->realTimes.clear();
// Set as OneTimeChange to make sure the update is not missed
this->entityCompMgr.SetChanged(worldEntity, components::Physics::typeId,
ComponentState::OneTimeChange);
Expand Down
5 changes: 0 additions & 5 deletions src/SimulationRunner.hh
Original file line number Diff line number Diff line change
Expand Up @@ -440,11 +440,6 @@ namespace gz
/// All simulation times will be larger than the epoch. It defaults to 0.
private: std::chrono::steady_clock::duration simTimeEpoch{0};

/// \brief List of simulation times used to compute averages.
private: std::list<std::chrono::steady_clock::duration> simTimes;

/// \brief List of real times used to compute averages.
private: std::list<std::chrono::steady_clock::duration> realTimes;

/// \brief Node for communication.
private: std::unique_ptr<transport::Node> node{nullptr};
Expand Down

0 comments on commit f06d37a

Please sign in to comment.