2013-08-29 02:34:34 -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/>.
|
|
|
|
*/
|
|
|
|
|
2012-07-15 22:21:20 -03:00
|
|
|
/*
|
2016-01-29 07:38:33 -04:00
|
|
|
* Airspeed.cpp - airspeed example sketch
|
2012-08-17 03:08:43 -03:00
|
|
|
*
|
|
|
|
*/
|
2012-07-15 22:21:20 -03:00
|
|
|
|
2019-11-07 17:08:54 -04:00
|
|
|
#include <AP_AHRS/AP_AHRS.h>
|
2015-08-11 03:28:42 -03:00
|
|
|
#include <AP_Airspeed/AP_Airspeed.h>
|
2016-01-29 07:38:33 -04:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2016-10-04 05:07:21 -03:00
|
|
|
#include <AP_BoardConfig/AP_BoardConfig.h>
|
2017-12-24 15:53:02 -04:00
|
|
|
#include <GCS_MAVLink/GCS_Dummy.h>
|
2012-07-15 22:21:20 -03:00
|
|
|
|
2017-04-13 08:29:53 -03:00
|
|
|
void setup();
|
|
|
|
void loop();
|
|
|
|
|
2015-10-16 17:22:11 -03:00
|
|
|
const AP_HAL::HAL& hal = AP_HAL::get_HAL();
|
2012-07-15 22:21:20 -03:00
|
|
|
|
2016-03-27 22:09:37 -03:00
|
|
|
float temperature;
|
2018-05-23 07:48:40 -03:00
|
|
|
|
2019-11-07 17:08:54 -04:00
|
|
|
// create an AHRS object for get_airspeed_max
|
2021-07-23 09:06:58 -03:00
|
|
|
AP_AHRS ahrs;
|
2019-11-07 17:08:54 -04:00
|
|
|
|
2018-05-23 07:48:40 -03:00
|
|
|
// create airspeed object
|
2016-08-08 00:29:50 -03:00
|
|
|
AP_Airspeed airspeed;
|
2018-05-23 07:48:40 -03:00
|
|
|
|
2017-12-12 21:06:11 -04:00
|
|
|
static AP_BoardConfig board_config;
|
2012-07-15 22:21:20 -03:00
|
|
|
|
2016-10-04 05:07:21 -03:00
|
|
|
namespace {
|
|
|
|
// try to set the object value but provide diagnostic if it failed
|
|
|
|
void set_object_value(const void *object_pointer,
|
|
|
|
const struct AP_Param::GroupInfo *group_info,
|
|
|
|
const char *name, float value)
|
|
|
|
{
|
|
|
|
if (!AP_Param::set_object_value(object_pointer, group_info, name, value)) {
|
|
|
|
hal.console->printf("WARNING: AP_Param::set object value \"%s::%s\" Failed.\n",
|
|
|
|
group_info->name, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-23 07:48:40 -03:00
|
|
|
// to be called only once on boot for initializing objects
|
2012-07-15 22:21:20 -03:00
|
|
|
void setup()
|
|
|
|
{
|
2017-01-21 00:51:20 -04:00
|
|
|
hal.console->printf("ArduPilot Airspeed library test\n");
|
2012-07-15 22:21:20 -03:00
|
|
|
|
2018-05-23 07:48:40 -03:00
|
|
|
// set airspeed pin to 65, enable and use to true
|
2016-10-04 05:07:21 -03:00
|
|
|
set_object_value(&airspeed, airspeed.var_info, "PIN", 65);
|
|
|
|
set_object_value(&airspeed, airspeed.var_info, "ENABLE", 1);
|
|
|
|
set_object_value(&airspeed, airspeed.var_info, "USE", 1);
|
|
|
|
|
2017-08-28 21:45:57 -03:00
|
|
|
board_config.init();
|
2014-07-25 04:08:01 -03:00
|
|
|
|
2018-05-23 07:48:40 -03:00
|
|
|
// initialize airspeed
|
2022-01-03 17:16:22 -04:00
|
|
|
// Note airspeed.set_log_bit(LOG_BIT) would need to be called in order to enable logging
|
2013-06-25 10:45:30 -03:00
|
|
|
airspeed.init();
|
2018-05-23 07:48:40 -03:00
|
|
|
|
2014-11-13 06:12:37 -04:00
|
|
|
airspeed.calibrate(false);
|
2012-07-15 22:21:20 -03:00
|
|
|
}
|
|
|
|
|
2018-05-23 07:48:40 -03:00
|
|
|
// loop
|
2012-07-15 22:21:20 -03:00
|
|
|
void loop(void)
|
|
|
|
{
|
2012-08-17 03:08:43 -03:00
|
|
|
static uint32_t timer;
|
2018-05-23 07:48:40 -03:00
|
|
|
|
|
|
|
// run read() and get_temperature() in 10Hz
|
2016-10-04 05:07:21 -03:00
|
|
|
if ((AP_HAL::millis() - timer) > 100) {
|
2018-05-23 07:48:40 -03:00
|
|
|
|
|
|
|
// current system time in milliseconds
|
2015-11-19 23:07:16 -04:00
|
|
|
timer = AP_HAL::millis();
|
2022-01-03 17:16:22 -04:00
|
|
|
airspeed.update();
|
2016-03-27 22:09:37 -03:00
|
|
|
airspeed.get_temperature(temperature);
|
|
|
|
|
2018-05-23 07:48:40 -03:00
|
|
|
// print temperature and airspeed to console
|
2016-10-04 05:07:21 -03:00
|
|
|
hal.console->printf("airspeed %5.2f temperature %6.2f healthy = %u\n",
|
2017-04-13 08:29:53 -03:00
|
|
|
(double)airspeed.get_airspeed(), (double)temperature, airspeed.healthy());
|
2012-08-17 03:08:43 -03:00
|
|
|
}
|
2013-09-28 05:40:29 -03:00
|
|
|
hal.scheduler->delay(1);
|
2012-07-15 22:21:20 -03:00
|
|
|
}
|
2012-10-09 21:01:22 -03:00
|
|
|
|
2019-06-19 21:43:59 -03:00
|
|
|
const struct AP_Param::GroupInfo GCS_MAVLINK_Parameters::var_info[] = {
|
2017-12-24 15:53:02 -04:00
|
|
|
AP_GROUPEND
|
|
|
|
};
|
|
|
|
GCS_Dummy _gcs;
|
|
|
|
|
2012-10-09 21:01:22 -03:00
|
|
|
AP_HAL_MAIN();
|