@@ -27,26 +27,34 @@ namespace robot_dart {
27
27
// / returns the real-time (in seconds)
28
28
double step ();
29
29
30
- void reset (double dt, bool sync = false , double current_time = 0 .);
30
+ void reset (double dt, bool sync = false , double current_time = 0 ., double real_time = 0 . );
31
31
32
+ // / synchronize the simulation clock with the wall clock
33
+ // / (when possible, i.e. when the simulation is faster than real time)
32
34
void set_sync (bool enable) { _sync = enable; }
33
- bool sync () { return _sync; }
35
+ bool sync () const { return _sync; }
34
36
35
- // / current time according to the simulation
37
+ // / current time according to the simulation (simulation clock)
36
38
double current_time () const { return _simu_start_time + _current_time; }
37
- // / next time according to the simulation
39
+ // / next time according to the simulation (simulation clock)
38
40
double next_time () const { return _simu_start_time + _current_time + _dt; }
39
- // / time according to the clock's computer
40
- double real_time () const { return _real_time; }
41
+ // / time according to the clock's computer (wall clock)
42
+ double real_time () const { return _real_start_time + _real_time; }
43
+ // / dt used by the simulation (simulation clock)
41
44
double dt () const { return _dt; }
45
+ // 0.8x => we are simulating at 80% of real time
46
+ double real_time_factor () const { return _dt / it_duration (); }
47
+ // time for a single iteration (wall-clock)
48
+ double it_duration () const { return _it_duration * 1e-6 ; }
42
49
43
50
protected:
44
- double _current_time = 0 ., _simu_start_time = 0 ., _real_time = 0 ;
51
+ double _current_time = 0 ., _simu_start_time = 0 ., _real_time = 0 ., _real_start_time = 0 ., _it_duration = 0 . ;
45
52
double _dt;
46
53
int _current_step = 0 ;
47
54
bool _sync;
48
55
int _max_frequency = -1 ;
49
- clock_t ::time_point _start;
56
+ clock_t ::time_point _start_time;
57
+ clock_t ::time_point _last_iteration_time;
50
58
};
51
59
} // namespace robot_dart
52
60
0 commit comments