mirror of
https://github.com/nasa/trick.git
synced 2024-12-24 07:16:41 +00:00
* Repurpose the "Sim/Real Time" field on the sim control panel #1626 Added calculations in the realtime sync monitor job to calculate the average sim/realtime ratio for the past 100 frames. This is saved to a new variable, actual_run_ratio. Changed the sim control panel to display the actual_run_ratio value. * Repurpose the "Sim/Real Time" field on the sim control panel #1626 how does this compile locally but not in CI? Didn't include cmath.
This commit is contained in:
parent
dad8e3b872
commit
7547d36ab4
@ -110,6 +110,9 @@ namespace Trick {
|
||||
/** The clock time when the sim ended. Used for total actual time calculation.\n */
|
||||
long long sim_end_time ; /**< trick_units(--) */
|
||||
|
||||
/** The actual simulation time/wall clock time ratio\n */
|
||||
double actual_run_ratio ; /**< trick_units(--) */
|
||||
|
||||
/**
|
||||
@brief This is the constructor of the RealtimeSync class. It starts the RealtimeSync as
|
||||
disabled and sets the maximum overrun parameters to basically infinity.
|
||||
|
@ -788,7 +788,7 @@ public class SimControlApplication extends TrickApplication implements PropertyC
|
||||
|
||||
status_vars = "trick.var_add(\"trick_sys.sched.time_tics\") \n" +
|
||||
"trick.var_add(\"trick_sys.sched.mode\") \n" +
|
||||
"trick.var_add(\"trick_real_time.gtod_clock.rt_clock_ratio\") \n" +
|
||||
"trick.var_add(\"trick_real_time.rt_sync.actual_run_ratio\") \n" +
|
||||
"trick.var_add(\"trick_real_time.rt_sync.active\") \n";
|
||||
|
||||
if ( debug_present != 0 ) {
|
||||
@ -1673,7 +1673,7 @@ public class SimControlApplication extends TrickApplication implements PropertyC
|
||||
ii++ ;
|
||||
}
|
||||
|
||||
// "real_time.gtod_clock.rt_clock_ratio"
|
||||
// "real_time.rt_sync.actual_run_ratio"
|
||||
if (results.length > ii && results[ii] != null && results[ii] != "") {
|
||||
simState.setSimRealtimeRatio(Float.parseFloat(results[ii]));
|
||||
ii++ ;
|
||||
|
@ -9,6 +9,7 @@ PROGRAMMERS:
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <cmath>
|
||||
#include "trick/RealtimeSync.hh"
|
||||
#include "trick/exec_proto.h"
|
||||
#include "trick/sim_mode.h"
|
||||
@ -48,6 +49,8 @@ Trick::RealtimeSync::RealtimeSync( Trick::Clock * in_clock , Trick::Timer * in_t
|
||||
sim_end_init_time = 0 ;
|
||||
sim_end_time = 0 ;
|
||||
|
||||
actual_run_ratio = 0.0;
|
||||
|
||||
the_rts = this ;
|
||||
|
||||
}
|
||||
@ -250,6 +253,33 @@ int Trick::RealtimeSync::start_realtime(double in_frame_time , long long ref_tim
|
||||
return(0) ;
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
class Run_Ratio {
|
||||
public:
|
||||
Run_Ratio() : num_samples(0) {}
|
||||
Run_Ratio& operator()(long long sample, double in_rt_ratio)
|
||||
{
|
||||
samples[num_samples++ % N] = sample;
|
||||
rt_ratio = in_rt_ratio;
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator double() const {
|
||||
if ( num_samples <= 1 ) {
|
||||
return 0.0 ;
|
||||
} else if ( num_samples < N ) {
|
||||
return round(exec_get_software_frame() * (num_samples-1) * exec_get_time_tic_value() * rt_ratio / (double)(samples[num_samples - 1] - samples[0])*100.0)/100.0 ;
|
||||
} else {
|
||||
return round(exec_get_software_frame() * (N-1) * exec_get_time_tic_value() * rt_ratio / (double)(samples[(num_samples - 1) % N] - samples[num_samples % N])*100.0)/100.0 ;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
long long samples[N];
|
||||
size_t num_samples;
|
||||
double rt_ratio;
|
||||
};
|
||||
|
||||
/**
|
||||
@details
|
||||
-# If real-time is not active:
|
||||
@ -282,6 +312,7 @@ int Trick::RealtimeSync::rt_monitor(long long sim_time_tics) {
|
||||
|
||||
long long curr_clock_time ;
|
||||
char buf[512];
|
||||
static Run_Ratio<100> run_ratio ;
|
||||
|
||||
/* calculate the current underrun/overrun */
|
||||
curr_clock_time = rt_clock->clock_time() ;
|
||||
@ -301,6 +332,8 @@ int Trick::RealtimeSync::rt_monitor(long long sim_time_tics) {
|
||||
if ( disable_flag ) {
|
||||
disable_flag = false ;
|
||||
}
|
||||
/* calculate run ratio in non-realtime mode */
|
||||
actual_run_ratio = run_ratio(curr_clock_time, 1.0);
|
||||
return(0) ;
|
||||
}
|
||||
if ( enable_flag ) {
|
||||
@ -367,6 +400,8 @@ int Trick::RealtimeSync::rt_monitor(long long sim_time_tics) {
|
||||
/* If the timer requires to be reset at the end of each frame, reset it here. */
|
||||
sleep_timer->reset(exec_get_software_frame() / rt_clock->get_rt_clock_ratio()) ;
|
||||
|
||||
/* Calculate the run ratio after sleeping */
|
||||
actual_run_ratio = run_ratio(curr_clock_time, rt_clock->get_rt_clock_ratio());
|
||||
}
|
||||
|
||||
return(0) ;
|
||||
|
Loading…
Reference in New Issue
Block a user