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>
|
2016-10-04 05:07:21 -03:00
|
|
|
#include <AP_BoardConfig/AP_BoardConfig.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()
|
|
|
|
{
|
2017-01-21 00:51:43 -04:00
|
|
|
hal.console->printf("Barometer library test\n");
|
2014-07-07 05:12:45 -03:00
|
|
|
|
2016-10-04 05:07:21 -03:00
|
|
|
AP_BoardConfig{}.init();
|
|
|
|
|
2014-07-07 05:12:45 -03:00
|
|
|
hal.scheduler->delay(1000);
|
|
|
|
|
|
|
|
barometer.init();
|
|
|
|
barometer.calibrate();
|
|
|
|
|
2015-11-19 23:08:07 -04:00
|
|
|
timer = AP_HAL::micros();
|
2014-07-07 05:12:45 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
2015-07-09 20:59:35 -03:00
|
|
|
// run accumulate() at 50Hz and update() at 10Hz
|
2015-11-19 23:08:07 -04:00
|
|
|
if((AP_HAL::micros() - timer) > 20*1000UL) {
|
|
|
|
timer = AP_HAL::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();
|
2015-11-19 23:08:07 -04:00
|
|
|
uint32_t read_time = AP_HAL::micros() - timer;
|
2014-08-13 10:51:56 -03:00
|
|
|
float alt = barometer.get_altitude();
|
|
|
|
if (!barometer.healthy()) {
|
2017-01-21 00:51:43 -04:00
|
|
|
hal.console->printf("not healthy\n");
|
2014-07-07 05:12:45 -03:00
|
|
|
return;
|
|
|
|
}
|
2017-01-21 00:51:43 -04:00
|
|
|
hal.console->printf("Pressure:");
|
|
|
|
hal.console->printf(barometer.get_pressure());
|
|
|
|
hal.console->printf(" Temperature:");
|
|
|
|
hal.console->printf(barometer.get_temperature());
|
|
|
|
hal.console->printf(" Altitude:");
|
|
|
|
hal.console->printf(alt);
|
2014-10-19 16:22:51 -03:00
|
|
|
hal.console->printf(" climb=%.2f t=%u",
|
|
|
|
barometer.get_climb_rate(),
|
|
|
|
(unsigned)read_time);
|
2017-01-21 00:51:43 -04:00
|
|
|
hal.console->print("\n");
|
2015-09-28 06:50:14 -03:00
|
|
|
} else {
|
|
|
|
hal.scheduler->delay(1);
|
2014-07-07 05:12:45 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AP_HAL_MAIN();
|