2016-01-29 07:38:33 -04:00
|
|
|
#pragma once
|
2012-07-15 22:21:20 -03:00
|
|
|
|
2015-08-11 03:28:42 -03:00
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
#include <AP_Param/AP_Param.h>
|
2016-01-29 07:38:33 -04:00
|
|
|
#include <GCS_MAVLink/GCS_MAVLink.h>
|
2019-06-26 23:38:33 -03:00
|
|
|
#include <AP_Math/AP_Math.h>
|
2020-11-16 06:35:15 -04:00
|
|
|
#include <AP_MSP/msp.h>
|
2016-01-29 07:38:33 -04:00
|
|
|
|
2017-11-03 01:47:32 -03:00
|
|
|
class AP_Airspeed_Backend;
|
2012-07-15 22:21:20 -03:00
|
|
|
|
2019-10-03 08:02:07 -03:00
|
|
|
#ifndef AIRSPEED_MAX_SENSORS
|
2017-11-03 03:17:34 -03:00
|
|
|
#define AIRSPEED_MAX_SENSORS 2
|
2019-10-03 08:02:07 -03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef AP_AIRSPEED_AUTOCAL_ENABLE
|
|
|
|
#define AP_AIRSPEED_AUTOCAL_ENABLE !defined(HAL_BUILD_AP_PERIPH)
|
|
|
|
#endif
|
2017-11-03 03:17:34 -03:00
|
|
|
|
2020-11-16 06:35:15 -04:00
|
|
|
#ifndef HAL_MSP_AIRSPEED_ENABLED
|
|
|
|
#define HAL_MSP_AIRSPEED_ENABLED HAL_MSP_SENSORS_ENABLED
|
|
|
|
#endif
|
2013-07-19 19:14:58 -03:00
|
|
|
class Airspeed_Calibration {
|
|
|
|
public:
|
2013-08-28 09:35:50 -03:00
|
|
|
friend class AP_Airspeed;
|
2013-07-19 19:14:58 -03:00
|
|
|
// constructor
|
2016-08-08 00:29:50 -03:00
|
|
|
Airspeed_Calibration();
|
2013-07-19 19:14:58 -03:00
|
|
|
|
|
|
|
// initialise the calibration
|
|
|
|
void init(float initial_ratio);
|
|
|
|
|
|
|
|
// take current airspeed in m/s and ground speed vector and return
|
|
|
|
// new scaling factor
|
2016-08-08 00:28:24 -03:00
|
|
|
float update(float airspeed, const Vector3f &vg, int16_t max_airspeed_allowed_during_cal);
|
2013-07-19 19:14:58 -03:00
|
|
|
|
|
|
|
private:
|
|
|
|
// state of kalman filter for airspeed ratio estimation
|
|
|
|
Matrix3f P; // covarience matrix
|
|
|
|
const float Q0; // process noise matrix top left and middle element
|
|
|
|
const float Q1; // process noise matrix bottom right element
|
|
|
|
Vector3f state; // state vector
|
|
|
|
const float DT; // time delta
|
|
|
|
};
|
|
|
|
|
2012-07-15 22:21:20 -03:00
|
|
|
class AP_Airspeed
|
|
|
|
{
|
|
|
|
public:
|
2016-11-30 00:49:19 -04:00
|
|
|
friend class AP_Airspeed_Backend;
|
|
|
|
|
2012-08-17 03:08:43 -03:00
|
|
|
// constructor
|
2016-08-08 00:29:50 -03:00
|
|
|
AP_Airspeed();
|
2012-10-09 21:01:22 -03:00
|
|
|
|
2013-06-02 22:40:06 -03:00
|
|
|
void init(void);
|
|
|
|
|
2020-11-24 10:13:10 -04:00
|
|
|
#if AP_AIRSPEED_AUTOCAL_ENABLE
|
|
|
|
// inflight ratio calibration
|
|
|
|
void set_calibration_enabled(bool enable) {calibration_enabled = enable;}
|
|
|
|
#endif //AP_AIRSPEED_AUTOCAL_ENABLE
|
|
|
|
|
2017-11-03 03:17:34 -03:00
|
|
|
// read the analog source and update airspeed
|
2018-11-16 12:16:23 -04:00
|
|
|
void update(bool log);
|
2012-07-15 22:21:20 -03:00
|
|
|
|
2012-08-17 03:08:43 -03:00
|
|
|
// calibrate the airspeed. This must be called on startup if the
|
|
|
|
// altitude/climb_rate/acceleration interfaces are ever used
|
2017-11-03 03:17:34 -03:00
|
|
|
void calibrate(bool in_startup);
|
2012-07-15 22:21:20 -03:00
|
|
|
|
2012-08-17 03:08:43 -03:00
|
|
|
// return the current airspeed in m/s
|
2017-11-03 03:17:34 -03:00
|
|
|
float get_airspeed(uint8_t i) const {
|
|
|
|
return state[i].airspeed;
|
2012-08-17 03:08:43 -03:00
|
|
|
}
|
2018-03-09 17:12:05 -04:00
|
|
|
float get_airspeed(void) const { return get_airspeed(primary); }
|
2012-07-15 22:21:20 -03:00
|
|
|
|
2013-06-02 22:40:06 -03:00
|
|
|
// return the unfiltered airspeed in m/s
|
2017-11-03 03:17:34 -03:00
|
|
|
float get_raw_airspeed(uint8_t i) const {
|
|
|
|
return state[i].raw_airspeed;
|
2012-08-17 03:08:43 -03:00
|
|
|
}
|
2018-03-09 17:12:05 -04:00
|
|
|
float get_raw_airspeed(void) const { return get_raw_airspeed(primary); }
|
2012-07-15 22:21:20 -03:00
|
|
|
|
2013-07-13 08:53:38 -03:00
|
|
|
// return the current airspeed ratio (dimensionless)
|
2017-11-03 03:17:34 -03:00
|
|
|
float get_airspeed_ratio(uint8_t i) const {
|
|
|
|
return param[i].ratio;
|
2013-07-13 08:53:38 -03:00
|
|
|
}
|
2018-03-09 17:12:05 -04:00
|
|
|
float get_airspeed_ratio(void) const { return get_airspeed_ratio(primary); }
|
2013-07-13 08:53:38 -03:00
|
|
|
|
2014-01-27 19:35:35 -04:00
|
|
|
// get temperature if available
|
2017-11-03 03:17:34 -03:00
|
|
|
bool get_temperature(uint8_t i, float &temperature);
|
2018-03-09 17:12:05 -04:00
|
|
|
bool get_temperature(float &temperature) { return get_temperature(primary, temperature); }
|
2014-01-27 19:35:35 -04:00
|
|
|
|
2013-07-13 08:53:38 -03:00
|
|
|
// set the airspeed ratio (dimensionless)
|
2017-11-03 03:17:34 -03:00
|
|
|
void set_airspeed_ratio(uint8_t i, float ratio) {
|
|
|
|
param[i].ratio.set(ratio);
|
2013-07-13 08:53:38 -03:00
|
|
|
}
|
2018-03-09 17:12:05 -04:00
|
|
|
void set_airspeed_ratio(float ratio) { set_airspeed_ratio(primary, ratio); }
|
2013-07-13 08:53:38 -03:00
|
|
|
|
2012-07-15 22:21:20 -03:00
|
|
|
// return true if airspeed is enabled, and airspeed use is set
|
2017-11-03 03:17:34 -03:00
|
|
|
bool use(uint8_t i) const;
|
2018-03-09 17:12:05 -04:00
|
|
|
bool use(void) const { return use(primary); }
|
2012-07-15 22:21:20 -03:00
|
|
|
|
|
|
|
// return true if airspeed is enabled
|
2017-11-03 03:17:34 -03:00
|
|
|
bool enabled(uint8_t i) const {
|
2018-05-28 17:12:26 -03:00
|
|
|
if (i < AIRSPEED_MAX_SENSORS) {
|
|
|
|
return param[i].type.get() != TYPE_NONE;
|
|
|
|
}
|
|
|
|
return false;
|
2013-06-02 22:40:06 -03:00
|
|
|
}
|
2018-03-09 17:12:05 -04:00
|
|
|
bool enabled(void) const { return enabled(primary); }
|
2013-06-02 22:40:06 -03:00
|
|
|
|
2012-07-15 22:21:20 -03:00
|
|
|
// used by HIL to set the airspeed
|
2017-11-03 03:17:34 -03:00
|
|
|
void set_HIL(float airspeed) {
|
|
|
|
state[primary].airspeed = airspeed;
|
2012-08-17 03:08:43 -03:00
|
|
|
}
|
2012-07-15 22:21:20 -03:00
|
|
|
|
2018-05-28 17:12:26 -03:00
|
|
|
// return the differential pressure in Pascal for the last airspeed reading
|
2017-11-03 03:17:34 -03:00
|
|
|
float get_differential_pressure(uint8_t i) const {
|
|
|
|
return state[i].last_pressure;
|
2014-11-13 02:49:04 -04:00
|
|
|
}
|
2018-03-09 17:12:05 -04:00
|
|
|
float get_differential_pressure(void) const { return get_differential_pressure(primary); }
|
2014-11-13 02:49:04 -04:00
|
|
|
|
2013-07-19 19:14:58 -03:00
|
|
|
// update airspeed ratio calibration
|
2016-08-08 00:28:24 -03:00
|
|
|
void update_calibration(const Vector3f &vground, int16_t max_airspeed_allowed_during_cal);
|
2013-08-28 09:35:50 -03:00
|
|
|
|
2013-10-29 19:03:35 -03:00
|
|
|
// return health status of sensor
|
2017-11-03 03:17:34 -03:00
|
|
|
bool healthy(uint8_t i) const {
|
2019-10-03 08:02:07 -03:00
|
|
|
bool ok = state[i].healthy && enabled(i);
|
|
|
|
#ifndef HAL_BUILD_AP_PERIPH
|
|
|
|
ok &= (fabsf(param[i].offset) > 0 || state[i].use_zero_offset);
|
|
|
|
#endif
|
|
|
|
return ok;
|
2017-11-03 03:17:34 -03:00
|
|
|
}
|
2018-03-09 17:12:05 -04:00
|
|
|
bool healthy(void) const { return healthy(primary); }
|
2013-10-29 19:03:35 -03:00
|
|
|
|
2017-11-03 03:17:34 -03:00
|
|
|
// return true if all enabled sensors are healthy
|
|
|
|
bool all_healthy(void) const;
|
|
|
|
|
|
|
|
void setHIL(float pressure) { state[0].healthy=state[0].hil_set=true; state[0].hil_pressure=pressure; }
|
2014-08-10 05:16:53 -03:00
|
|
|
|
2013-12-30 06:23:58 -04:00
|
|
|
// return time in ms of last update
|
2017-11-03 03:17:34 -03:00
|
|
|
uint32_t last_update_ms(uint8_t i) const { return state[i].last_update_ms; }
|
|
|
|
uint32_t last_update_ms(void) const { return last_update_ms(primary); }
|
2013-12-30 06:23:58 -04:00
|
|
|
|
2014-02-17 18:24:14 -04:00
|
|
|
void setHIL(float airspeed, float diff_pressure, float temperature);
|
|
|
|
|
2012-10-09 21:01:22 -03:00
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
2012-07-15 22:21:20 -03:00
|
|
|
|
2016-01-29 07:38:33 -04:00
|
|
|
enum pitot_tube_order { PITOT_TUBE_ORDER_POSITIVE = 0,
|
|
|
|
PITOT_TUBE_ORDER_NEGATIVE = 1,
|
|
|
|
PITOT_TUBE_ORDER_AUTO = 2 };
|
2013-08-28 09:35:50 -03:00
|
|
|
|
2019-01-29 22:02:40 -04:00
|
|
|
enum OptionsMask {
|
2019-02-03 07:55:38 -04:00
|
|
|
ON_FAILURE_AHRS_WIND_MAX_DO_DISABLE = (1<<0), // If set then use airspeed failure check
|
|
|
|
ON_FAILURE_AHRS_WIND_MAX_RECOVERY_DO_REENABLE = (1<<1), // If set then automatically enable the airspeed sensor use when healthy again.
|
2019-01-29 22:02:40 -04:00
|
|
|
};
|
|
|
|
|
2016-11-30 00:49:19 -04:00
|
|
|
enum airspeed_type {
|
|
|
|
TYPE_NONE=0,
|
|
|
|
TYPE_I2C_MS4525=1,
|
|
|
|
TYPE_ANALOG=2,
|
2016-11-30 02:21:48 -04:00
|
|
|
TYPE_I2C_MS5525=3,
|
2017-11-28 15:25:19 -04:00
|
|
|
TYPE_I2C_MS5525_ADDRESS_1=4,
|
|
|
|
TYPE_I2C_MS5525_ADDRESS_2=5,
|
2017-11-03 01:47:32 -03:00
|
|
|
TYPE_I2C_SDP3X=6,
|
2019-07-18 02:19:09 -03:00
|
|
|
TYPE_I2C_DLVR_5IN=7,
|
2018-09-05 03:45:01 -03:00
|
|
|
TYPE_UAVCAN=8,
|
2019-07-18 02:19:09 -03:00
|
|
|
TYPE_I2C_DLVR_10IN=9,
|
2020-08-04 18:53:27 -03:00
|
|
|
TYPE_I2C_DLVR_20IN=10,
|
|
|
|
TYPE_I2C_DLVR_30IN=11,
|
|
|
|
TYPE_I2C_DLVR_60IN=12,
|
2020-07-18 16:49:08 -03:00
|
|
|
TYPE_NMEA_WATER=13,
|
2020-11-16 06:35:15 -04:00
|
|
|
TYPE_MSP=14,
|
2021-03-23 11:18:41 -03:00
|
|
|
TYPE_I2C_ASP5033=15,
|
2016-11-30 00:49:19 -04:00
|
|
|
};
|
2017-11-03 03:17:34 -03:00
|
|
|
|
|
|
|
// get current primary sensor
|
|
|
|
uint8_t get_primary(void) const { return primary; }
|
2018-03-04 20:13:48 -04:00
|
|
|
|
2019-05-03 08:23:58 -03:00
|
|
|
// get number of sensors
|
|
|
|
uint8_t get_num_sensors(void) const { return num_sensors; }
|
|
|
|
|
2018-03-04 20:13:48 -04:00
|
|
|
static AP_Airspeed *get_singleton() { return _singleton; }
|
2020-03-16 02:09:10 -03:00
|
|
|
|
|
|
|
// return the current corrected pressure, public for AP_Periph
|
|
|
|
float get_corrected_pressure(uint8_t i) const {
|
|
|
|
return state[i].corrected_pressure;
|
|
|
|
}
|
|
|
|
float get_corrected_pressure(void) const {
|
|
|
|
return get_corrected_pressure(primary);
|
|
|
|
}
|
2020-11-16 06:35:15 -04:00
|
|
|
|
|
|
|
#if HAL_MSP_AIRSPEED_ENABLED
|
|
|
|
void handle_msp(const MSP::msp_airspeed_data_message_t &pkt);
|
|
|
|
#endif
|
2018-03-09 17:12:05 -04:00
|
|
|
|
2018-03-09 04:07:34 -04:00
|
|
|
private:
|
2018-03-04 20:13:48 -04:00
|
|
|
static AP_Airspeed *_singleton;
|
2018-03-09 17:12:05 -04:00
|
|
|
|
2017-11-03 03:17:34 -03:00
|
|
|
AP_Int8 primary_sensor;
|
2019-01-29 19:03:35 -04:00
|
|
|
AP_Int32 _options; // bitmask options for airspeed
|
2020-10-09 09:38:25 -03:00
|
|
|
AP_Float _wind_max;
|
|
|
|
AP_Float _wind_warn;
|
|
|
|
|
2017-11-03 03:17:34 -03:00
|
|
|
struct {
|
|
|
|
AP_Float offset;
|
|
|
|
AP_Float ratio;
|
|
|
|
AP_Float psi_range;
|
|
|
|
AP_Int8 use;
|
|
|
|
AP_Int8 type;
|
|
|
|
AP_Int8 pin;
|
|
|
|
AP_Int8 bus;
|
|
|
|
AP_Int8 autocal;
|
|
|
|
AP_Int8 tube_order;
|
|
|
|
AP_Int8 skip_cal;
|
|
|
|
} param[AIRSPEED_MAX_SENSORS];
|
2018-03-09 17:12:05 -04:00
|
|
|
|
2017-11-03 03:17:34 -03:00
|
|
|
struct airspeed_state {
|
|
|
|
float raw_airspeed;
|
|
|
|
float airspeed;
|
|
|
|
float last_pressure;
|
|
|
|
float filtered_pressure;
|
|
|
|
float corrected_pressure;
|
|
|
|
float hil_pressure;
|
|
|
|
uint32_t last_update_ms;
|
|
|
|
bool use_zero_offset;
|
2020-05-06 02:07:59 -03:00
|
|
|
bool healthy;
|
|
|
|
bool hil_set;
|
2019-10-03 08:02:07 -03:00
|
|
|
|
2017-11-03 03:17:34 -03:00
|
|
|
// state of runtime calibration
|
|
|
|
struct {
|
|
|
|
uint32_t start_ms;
|
|
|
|
float sum;
|
2020-05-06 02:07:59 -03:00
|
|
|
uint16_t count;
|
2017-11-03 03:17:34 -03:00
|
|
|
uint16_t read_count;
|
|
|
|
} cal;
|
|
|
|
|
2019-10-03 08:02:07 -03:00
|
|
|
#if AP_AIRSPEED_AUTOCAL_ENABLE
|
2017-11-03 03:17:34 -03:00
|
|
|
Airspeed_Calibration calibration;
|
|
|
|
float last_saved_ratio;
|
|
|
|
uint8_t counter;
|
2019-10-03 08:02:07 -03:00
|
|
|
#endif // AP_AIRSPEED_AUTOCAL_ENABLE
|
2019-01-29 19:03:35 -04:00
|
|
|
|
|
|
|
struct {
|
|
|
|
uint32_t last_check_ms;
|
|
|
|
float health_probability;
|
|
|
|
int8_t param_use_backup;
|
2020-10-09 09:38:25 -03:00
|
|
|
uint32_t last_warn_ms;
|
2019-01-29 19:03:35 -04:00
|
|
|
} failures;
|
2017-11-03 03:17:34 -03:00
|
|
|
} state[AIRSPEED_MAX_SENSORS];
|
2018-03-09 17:12:05 -04:00
|
|
|
|
2020-11-24 10:13:10 -04:00
|
|
|
bool calibration_enabled = false;
|
|
|
|
|
2017-11-03 03:17:34 -03:00
|
|
|
// current primary sensor
|
|
|
|
uint8_t primary;
|
2019-05-03 08:23:58 -03:00
|
|
|
uint8_t num_sensors;
|
|
|
|
|
2017-11-03 03:17:34 -03:00
|
|
|
void read(uint8_t i);
|
2018-05-28 17:12:26 -03:00
|
|
|
// return the differential pressure in Pascal for the last airspeed reading for the requested instance
|
|
|
|
// returns 0 if the sensor is not enabled
|
2017-11-03 03:17:34 -03:00
|
|
|
float get_pressure(uint8_t i);
|
2020-03-16 02:09:10 -03:00
|
|
|
|
2019-04-05 23:48:44 -03:00
|
|
|
// get the failure health probability
|
|
|
|
float get_health_failure_probability(uint8_t i) const {
|
|
|
|
return state[i].failures.health_probability;
|
|
|
|
}
|
|
|
|
float get_health_failure_probability(void) const {
|
|
|
|
return get_health_failure_probability(primary);
|
|
|
|
}
|
|
|
|
|
2017-11-03 03:17:34 -03:00
|
|
|
void update_calibration(uint8_t i, float raw_pressure);
|
|
|
|
void update_calibration(uint8_t i, const Vector3f &vground, int16_t max_airspeed_allowed_during_cal);
|
2018-11-22 19:43:22 -04:00
|
|
|
void send_airspeed_calibration(const Vector3f &vg);
|
2019-04-05 23:48:44 -03:00
|
|
|
// return the current calibration offset
|
|
|
|
float get_offset(uint8_t i) const {
|
|
|
|
return param[i].offset;
|
|
|
|
}
|
|
|
|
float get_offset(void) const { return get_offset(primary); }
|
2019-01-29 22:02:40 -04:00
|
|
|
|
|
|
|
void check_sensor_failures();
|
2019-02-03 07:55:38 -04:00
|
|
|
void check_sensor_ahrs_wind_max_failures(uint8_t i);
|
2018-03-09 17:12:05 -04:00
|
|
|
|
2017-11-03 03:17:34 -03:00
|
|
|
AP_Airspeed_Backend *sensor[AIRSPEED_MAX_SENSORS];
|
2018-11-22 19:43:22 -04:00
|
|
|
|
2019-04-05 23:48:44 -03:00
|
|
|
void Log_Airspeed();
|
2012-07-15 22:21:20 -03:00
|
|
|
};
|
2019-04-05 22:10:17 -03:00
|
|
|
|
|
|
|
namespace AP {
|
|
|
|
AP_Airspeed *airspeed();
|
|
|
|
};
|