From 02a590024dee87916bb0047d10dc3d4ed40d7f6b Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Sun, 30 Jul 2017 15:11:22 +1000 Subject: [PATCH] Copter: base loop time remaining on variable loop rate --- ArduCopter/ArduCopter.cpp | 5 +++-- ArduCopter/config.h | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ArduCopter/ArduCopter.cpp b/ArduCopter/ArduCopter.cpp index 233cd212c9..54c4799cc6 100644 --- a/ArduCopter/ArduCopter.cpp +++ b/ArduCopter/ArduCopter.cpp @@ -238,8 +238,9 @@ void Copter::loop() // in multiples of the main loop tick. So if they don't run on // the first call to the scheduler they won't run on a later // call until scheduler.tick() is called again - uint32_t time_available = (timer + MAIN_LOOP_MICROS) - micros(); - scheduler.run(time_available > MAIN_LOOP_MICROS ? 0u : time_available); + const uint32_t loop_us = scheduler.get_loop_period_us(); + const uint32_t time_available = (timer + loop_us) - micros(); + scheduler.run(time_available > loop_us ? 0u : time_available); } diff --git a/ArduCopter/config.h b/ArduCopter/config.h index daf6f1398d..360a50515c 100644 --- a/ArduCopter/config.h +++ b/ArduCopter/config.h @@ -51,7 +51,6 @@ // run at 400Hz on all systems # define MAIN_LOOP_RATE 400 # define MAIN_LOOP_SECONDS 0.0025f -# define MAIN_LOOP_MICROS 2500 #ifndef ARMING_DELAY_SEC # define ARMING_DELAY_SEC 2.0f