From 282efe2d570b94f249d46fab3112aea9b3dcf13a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 10 Jul 2015 09:59:35 +1000 Subject: [PATCH] AP_Baro: fixed example to run accumulate at 50Hz --- libraries/AP_Baro/examples/BARO_generic/BARO_generic.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libraries/AP_Baro/examples/BARO_generic/BARO_generic.cpp b/libraries/AP_Baro/examples/BARO_generic/BARO_generic.cpp index 4ae6c22a08..d672f9dd96 100644 --- a/libraries/AP_Baro/examples/BARO_generic/BARO_generic.cpp +++ b/libraries/AP_Baro/examples/BARO_generic/BARO_generic.cpp @@ -41,6 +41,7 @@ const AP_HAL::HAL& hal = AP_HAL_BOARD_DRIVER; static AP_Baro barometer; static uint32_t timer; +static uint8_t counter; void setup() { @@ -62,8 +63,14 @@ void setup() void loop() { - if((hal.scheduler->micros() - timer) > 100000UL) { + // run accumulate() at 50Hz and update() at 10Hz + if((hal.scheduler->micros() - timer) > 20*1000UL) { timer = hal.scheduler->micros(); + barometer.accumulate(); + if (counter++ < 5) { + return; + } + counter = 0; barometer.update(); uint32_t read_time = hal.scheduler->micros() - timer; float alt = barometer.get_altitude();