Skip to content

Commit ac71c94

Browse files
authored
Merge pull request #144 from resibots/fix_rt_factor
Fix real-time factor reporting
2 parents 38e6560 + 5b5631c commit ac71c94

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/robot_dart/scheduler.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ namespace robot_dart {
3030
_real_start_time = real_time;
3131
_current_step = 0;
3232
_max_frequency = -1;
33+
_average_it_duration = 0.;
3334

3435
_dt = dt;
3536
_sync = sync;
@@ -43,6 +44,7 @@ namespace robot_dart {
4344
auto end = clock_t::now();
4445
_it_duration = std::chrono::duration<double, std::micro>(end - _last_iteration_time).count();
4546
_last_iteration_time = end;
47+
_average_it_duration = _average_it_duration + (_it_duration - _average_it_duration) / _current_step;
4648
std::chrono::duration<double, std::micro> real = end - _start_time;
4749
if (_sync) {
4850
auto expected = std::chrono::microseconds(int(_current_time * 1e6));

src/robot_dart/scheduler.hpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ namespace robot_dart {
4545
// 0.8x => we are simulating at 80% of real time
4646
double real_time_factor() const { return _dt / it_duration(); }
4747
// time for a single iteration (wall-clock)
48-
double it_duration() const { return _it_duration * 1e-6; }
48+
double it_duration() const { return _average_it_duration * 1e-6; }
49+
// time of the last iteration (wall-clock)
50+
double last_it_duration() const { return _it_duration * 1e-6; }
4951

5052
protected:
5153
double _current_time = 0., _simu_start_time = 0., _real_time = 0., _real_start_time = 0., _it_duration = 0.;
54+
double _average_it_duration = 0.;
5255
double _dt;
5356
int _current_step = 0;
5457
bool _sync;

0 commit comments

Comments
 (0)