2015-05-13 03:09:36 -03:00
|
|
|
#include "Plane.h"
|
2015-08-28 03:01:32 -03:00
|
|
|
#include <AP_RSSI/AP_RSSI.h>
|
2019-02-13 22:25:10 -04:00
|
|
|
#include <AP_OpticalFlow/AP_OpticalFlow.h>
|
2015-05-13 03:09:36 -03:00
|
|
|
|
2014-08-26 08:17:47 -03:00
|
|
|
/*
|
|
|
|
read the rangefinder and update height estimate
|
|
|
|
*/
|
2015-05-13 03:09:36 -03:00
|
|
|
void Plane::read_rangefinder(void)
|
2013-10-30 19:23:21 -03:00
|
|
|
{
|
2015-10-15 18:50:06 -03:00
|
|
|
|
|
|
|
// notify the rangefinder of our approximate altitude above ground to allow it to power on
|
|
|
|
// during low-altitude flight when configured to power down during higher-altitude flight
|
|
|
|
float height;
|
|
|
|
#if AP_TERRAIN_AVAILABLE
|
|
|
|
if (terrain.status() == AP_Terrain::TerrainStatusOK && terrain.height_above_terrain(height, true)) {
|
|
|
|
rangefinder.set_estimated_terrain_height(height);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
// use the best available alt estimate via baro above home
|
2017-01-11 01:29:03 -04:00
|
|
|
if (flight_stage == AP_Vehicle::FixedWing::FLIGHT_LAND) {
|
2015-10-15 18:50:06 -03:00
|
|
|
// ensure the rangefinder is powered-on when land alt is higher than home altitude.
|
|
|
|
// This is done using the target alt which we know is below us and we are sinking to it
|
|
|
|
height = height_above_target();
|
|
|
|
} else {
|
|
|
|
// otherwise just use the best available baro estimate above home.
|
2017-01-30 15:48:22 -04:00
|
|
|
height = relative_altitude;
|
2015-10-15 18:50:06 -03:00
|
|
|
}
|
|
|
|
rangefinder.set_estimated_terrain_height(height);
|
|
|
|
}
|
|
|
|
|
2014-08-26 08:17:47 -03:00
|
|
|
rangefinder.update();
|
|
|
|
|
2014-08-26 22:50:07 -03:00
|
|
|
rangefinder_height_update();
|
2013-10-30 19:23:21 -03:00
|
|
|
}
|
|
|
|
|
2015-10-21 18:11:52 -03:00
|
|
|
/*
|
|
|
|
Accel calibration
|
|
|
|
*/
|
|
|
|
void Plane::accel_cal_update() {
|
|
|
|
if (hal.util->get_soft_armed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ins.acal_update();
|
|
|
|
float trim_roll, trim_pitch;
|
|
|
|
if(ins.get_new_trim(trim_roll, trim_pitch)) {
|
|
|
|
ahrs.set_trim(Vector3f(trim_roll, trim_pitch, 0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-28 09:37:07 -03:00
|
|
|
/*
|
|
|
|
ask airspeed sensor for a new value
|
|
|
|
*/
|
2015-05-13 03:09:36 -03:00
|
|
|
void Plane::read_airspeed(void)
|
2011-09-08 22:29:39 -03:00
|
|
|
{
|
2018-11-16 12:15:54 -04:00
|
|
|
airspeed.update(should_log(MASK_LOG_IMU));
|
2014-11-11 22:35:34 -04:00
|
|
|
|
2017-07-31 06:58:19 -03:00
|
|
|
// we calculate airspeed errors (and thus target_airspeed_cm) even
|
|
|
|
// when airspeed is disabled as TECS may be using synthetic
|
|
|
|
// airspeed for a quadplane transition
|
|
|
|
calc_airspeed_errors();
|
|
|
|
|
2014-11-11 22:35:34 -04:00
|
|
|
// update smoothed airspeed estimate
|
|
|
|
float aspeed;
|
2020-01-06 20:45:27 -04:00
|
|
|
if (ahrs.airspeed_estimate(aspeed)) {
|
2014-11-11 22:35:34 -04:00
|
|
|
smoothed_airspeed = smoothed_airspeed * 0.8f + aspeed * 0.2f;
|
|
|
|
}
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
2015-09-24 07:58:18 -03:00
|
|
|
/*
|
|
|
|
update RPM sensors
|
|
|
|
*/
|
|
|
|
void Plane::rpm_update(void)
|
|
|
|
{
|
|
|
|
rpm_sensor.update();
|
2017-02-21 08:20:01 -04:00
|
|
|
if (rpm_sensor.enabled(0) || rpm_sensor.enabled(1)) {
|
2015-09-24 07:58:18 -03:00
|
|
|
if (should_log(MASK_LOG_RC)) {
|
2019-01-18 00:24:08 -04:00
|
|
|
logger.Write_RPM(rpm_sensor);
|
2015-09-24 07:58:18 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|