From 2be70f68aca817b08e7cc2496e7b24b5e7cfd40f Mon Sep 17 00:00:00 2001 From: Atsushi Watanabe Date: Mon, 29 Apr 2024 11:22:48 +0900 Subject: [PATCH] Detect system time jump back (#208) --- 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(