2018-05-23 07:55:54 -03:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
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>
|
2018-07-13 01:03:53 -03:00
|
|
|
#include <GCS_MAVLink/GCS_Dummy.h>
|
2021-02-08 10:05:31 -04:00
|
|
|
#include <AP_ExternalAHRS/AP_ExternalAHRS.h>
|
2018-07-13 01:03:53 -03:00
|
|
|
|
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
|
|
|
|
2018-05-23 07:55:54 -03:00
|
|
|
// create barometer object
|
2017-12-12 21:06:11 -04:00
|
|
|
static AP_Baro barometer;
|
2021-02-08 10:05:31 -04:00
|
|
|
#if HAL_EXTERNAL_AHRS_ENABLED
|
2021-02-09 10:09:51 -04:00
|
|
|
static AP_ExternalAHRS eAHRS;
|
2021-02-08 10:05:31 -04:00
|
|
|
#endif // HAL_EXTERNAL_AHRS_ENABLED
|
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
|
|
|
|
2020-09-16 15:50:16 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
|
|
|
#include <SITL/SITL.h>
|
2021-07-30 07:12:00 -03:00
|
|
|
SITL::SIM sitl;
|
2020-09-16 15:50:16 -03:00
|
|
|
#endif
|
|
|
|
|
2017-02-06 15:10:54 -04:00
|
|
|
void setup();
|
|
|
|
void loop();
|
|
|
|
|
2018-05-23 07:55:54 -03:00
|
|
|
// to be called only once on boot for initializing objects
|
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);
|
|
|
|
|
2018-05-23 07:55:54 -03:00
|
|
|
// initialize the barometer
|
2014-07-07 05:12:45 -03:00
|
|
|
barometer.init();
|
|
|
|
barometer.calibrate();
|
|
|
|
|
2018-05-23 07:55:54 -03:00
|
|
|
// set up timer to count time in microseconds
|
2015-11-19 23:08:07 -04:00
|
|
|
timer = AP_HAL::micros();
|
2014-07-07 05:12:45 -03:00
|
|
|
}
|
|
|
|
|
2018-05-23 07:55:54 -03:00
|
|
|
// loop
|
2014-07-07 05:12:45 -03:00
|
|
|
void loop()
|
|
|
|
{
|
2018-05-23 07:55:54 -03:00
|
|
|
// terminate program if console fails to initialize
|
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();
|
2018-05-23 07:55:54 -03:00
|
|
|
|
|
|
|
//calculate time taken for barometer readings to 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;
|
|
|
|
}
|
2018-05-23 07:55:54 -03:00
|
|
|
|
|
|
|
//output barometer readings to console
|
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(),
|
2018-05-03 22:41:35 -03:00
|
|
|
(unsigned)read_time);
|
2015-09-28 06:50:14 -03:00
|
|
|
} else {
|
2018-05-23 07:55:54 -03:00
|
|
|
// if stipulated time has not passed between two distinct readings, delay the program for a millisecond
|
2015-09-28 06:50:14 -03:00
|
|
|
hal.scheduler->delay(1);
|
2014-07-07 05:12:45 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-19 21:44:11 -03:00
|
|
|
const struct AP_Param::GroupInfo GCS_MAVLINK_Parameters::var_info[] = {
|
2018-07-13 01:03:53 -03:00
|
|
|
AP_GROUPEND
|
|
|
|
};
|
|
|
|
GCS_Dummy _gcs;
|
|
|
|
|
|
|
|
|
2014-07-07 05:12:45 -03:00
|
|
|
AP_HAL_MAIN();
|