2014-07-07 05:12:45 -03:00
|
|
|
/*
|
|
|
|
generic Baro driver test
|
|
|
|
*/
|
2015-10-20 10:30:08 -03:00
|
|
|
|
2015-08-11 03:28:42 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
#include <AP_Baro/AP_Baro.h>
|
2014-07-07 05:12:45 -03:00
|
|
|
|
2015-10-16 17:22:11 -03:00
|
|
|
const AP_HAL::HAL& hal = AP_HAL::get_HAL();
|
2014-07-07 05:12:45 -03:00
|
|
|
|
2014-10-19 16:22:51 -03:00
|
|
|
static AP_Baro barometer;
|
2014-07-07 05:12:45 -03:00
|
|
|
|
|
|
|
static uint32_t timer;
|
2015-07-09 20:59:35 -03:00
|
|
|
static uint8_t counter;
|
2014-07-07 05:12:45 -03:00
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
hal.console->println("Barometer library test");
|
|
|
|
|
|
|
|
hal.scheduler->delay(1000);
|
|
|
|
|
|
|
|
barometer.init();
|
|
|
|
barometer.calibrate();
|
|
|
|
|
|
|
|
timer = hal.scheduler->micros();
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
2015-07-09 20:59:35 -03:00
|
|
|
// run accumulate() at 50Hz and update() at 10Hz
|
|
|
|
if((hal.scheduler->micros() - timer) > 20*1000UL) {
|
2014-07-07 05:12:45 -03:00
|
|
|
timer = hal.scheduler->micros();
|
2015-07-09 20:59:35 -03:00
|
|
|
barometer.accumulate();
|
|
|
|
if (counter++ < 5) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
counter = 0;
|
2014-10-19 16:22:51 -03:00
|
|
|
barometer.update();
|
2014-07-07 05:12:45 -03:00
|
|
|
uint32_t read_time = hal.scheduler->micros() - timer;
|
2014-08-13 10:51:56 -03:00
|
|
|
float alt = barometer.get_altitude();
|
|
|
|
if (!barometer.healthy()) {
|
2014-07-07 05:12:45 -03:00
|
|
|
hal.console->println("not healthy");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
hal.console->print("Pressure:");
|
|
|
|
hal.console->print(barometer.get_pressure());
|
|
|
|
hal.console->print(" Temperature:");
|
|
|
|
hal.console->print(barometer.get_temperature());
|
|
|
|
hal.console->print(" Altitude:");
|
2014-08-13 10:51:56 -03:00
|
|
|
hal.console->print(alt);
|
2014-10-19 16:22:51 -03:00
|
|
|
hal.console->printf(" climb=%.2f t=%u",
|
|
|
|
barometer.get_climb_rate(),
|
|
|
|
(unsigned)read_time);
|
2014-07-07 05:12:45 -03:00
|
|
|
hal.console->println();
|
2015-09-28 06:50:14 -03:00
|
|
|
} else {
|
|
|
|
hal.scheduler->delay(1);
|
2014-07-07 05:12:45 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AP_HAL_MAIN();
|