From 0c230bf78e6cc17ef00c5a55d72e7f5c6a2ec359 Mon Sep 17 00:00:00 2001 From: Atsushi Watanabe Date: Tue, 23 Apr 2024 21:36:55 +0900 Subject: [PATCH] Detect system time jump back --- src/control_vehicle.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/control_vehicle.c b/src/control_vehicle.c index cc26c78..8f3a5ad 100644 --- a/src/control_vehicle.c +++ b/src/control_vehicle.c @@ -560,6 +560,15 @@ void control_loop(void) const double dt = now - last_time; const double dt_error = dt - expected_dt; last_time = now; + if (dt < 0) + { + yprintf( + OUTPUT_LV_ERROR, + "Detected system time jump back, monotonic time diff: %0.5fs, system time diff: %0.5fs\n", + expected_dt, dt); + static int status = EXIT_FAILURE; + pthread_exit(&status); + } if (dt_error < -p(YP_PARAM_MAX_TIME_JUMP_NEG, 0) || p(YP_PARAM_MAX_TIME_JUMP, 0) < dt_error) { yprintf(