From b1516cc6e8d1b4e8ea0de2aaa56c73cdddf359bf Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Sun, 30 Jul 2017 15:11:31 +1000 Subject: [PATCH] Sub: base loop time remaining on variable loop rate --- ArduSub/ArduSub.cpp | 5 +++-- ArduSub/config.h | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ArduSub/ArduSub.cpp b/ArduSub/ArduSub.cpp index 6a6303a39a3..830172a4f40 100644 --- a/ArduSub/ArduSub.cpp +++ b/ArduSub/ArduSub.cpp @@ -146,8 +146,9 @@ void Sub::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/ArduSub/config.h b/ArduSub/config.h index 0b01b85e7b0..e477e36a21a 100644 --- a/ArduSub/config.h +++ b/ArduSub/config.h @@ -41,7 +41,6 @@ // run at 400Hz on all systems # define MAIN_LOOP_RATE 400 # define MAIN_LOOP_SECONDS 0.0025f -# define MAIN_LOOP_MICROS 2500 #ifndef SURFACE_DEPTH_DEFAULT # define SURFACE_DEPTH_DEFAULT -10.0f // pressure sensor reading 10cm depth means craft is considered surfaced