From a94687bd561ac058b4f966549f57e979ff9cff8c Mon Sep 17 00:00:00 2001 From: Oleg Kalachev Date: Wed, 23 Oct 2024 06:15:18 +0300 Subject: [PATCH] Keep the t variable monotonic in the simulation Otherwise it causes stopping sending MAVLink and other bugs --- gazebo/Arduino.h | 3 ++- gazebo/simulator.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/gazebo/Arduino.h b/gazebo/Arduino.h index b902257..7ea6f90 100644 --- a/gazebo/Arduino.h +++ b/gazebo/Arduino.h @@ -134,7 +134,8 @@ void delay(uint32_t ms) { } unsigned long __micros; +unsigned long __resetTime = 0; unsigned long micros() { - return __micros; + return __micros + __resetTime; // keep the time monotonic } diff --git a/gazebo/simulator.cpp b/gazebo/simulator.cpp index d789bf0..e67ea10 100644 --- a/gazebo/simulator.cpp +++ b/gazebo/simulator.cpp @@ -55,6 +55,7 @@ public: void OnReset() { attitude = Quaternion(); // reset estimated attitude + __resetTime += __micros; gzmsg << "Flix plugin reset" << endl; }