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_Baro/AP_Baro.h>
|
2016-10-04 05:07:21 -03:00
|
|
|
#include <AP_BoardConfig/AP_BoardConfig.h>
|
2017-02-06 15:10:54 -04:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2014-07-07 05:12:45 -03:00
|
|
|
|
2017-02-06 15:10:54 -04:00
|
|
|
const AP_HAL::HAL &hal = AP_HAL::get_HAL();
|
2014-07-07 05:12:45 -03:00
|
|
|
|
2017-12-12 21:06:11 -04: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;
|
2017-12-12 21:06:11 -04:00
|
|
|
static AP_BoardConfig board_config;
|
2014-07-07 05:12:45 -03:00
|
|
|
|
2017-02-06 15:10:54 -04:00
|
|
|
void setup();
|
|
|
|
void loop();
|
|
|
|
|
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
|
|
|
|
2017-08-28 21:45:57 -03:00
|
|
|
board_config.init();
|
2016-10-04 05:07:21 -03:00
|
|
|
|
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()
|
|
|
|
{
|
2017-03-03 22:35:43 -04:00
|
|
|
if (!hal.console->is_initialized()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-09 20:59:35 -03:00
|
|
|
// run accumulate() at 50Hz and update() at 10Hz
|
2017-02-06 15:10:54 -04:00
|
|
|
if ((AP_HAL::micros() - timer) > 20 * 1000UL) {
|
2015-11-19 23:08:07 -04:00
|
|
|
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
|
|
|
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-02-06 16:46:39 -04:00
|
|
|
hal.console->printf(" Pressure: %.2f Pa\n"
|
|
|
|
" Temperature: %.2f degC\n"
|
|
|
|
" Relative Altitude: %.2f m\n"
|
|
|
|
" climb=%.2f m/s\n"
|
|
|
|
" Read + update time: %u usec\n"
|
|
|
|
"\n",
|
|
|
|
(double)barometer.get_pressure(),
|
|
|
|
(double)barometer.get_temperature(),
|
|
|
|
(double)barometer.get_altitude(),
|
|
|
|
(double)barometer.get_climb_rate(),
|
|
|
|
read_time);
|
2015-09-28 06:50:14 -03:00
|
|
|
} else {
|
|
|
|
hal.scheduler->delay(1);
|
2014-07-07 05:12:45 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AP_HAL_MAIN();
|