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>
|
2017-11-03 01:47:32 -03:00
|
|
|
#include <AP_Baro/AP_Baro.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
|
|
|
|
2017-11-03 03:17:34 -03:00
|
|
|
#define AIRSPEED_MAX_SENSORS 2
|
|
|
|
|
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);
|
|
|
|
|
2017-11-03 03:17:34 -03:00
|
|
|
// read the analog source and update airspeed
|
|
|
|
void read(void);
|
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 {
|
|
|
|
return param[i].type.get() != TYPE_NONE;
|
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
|
|
|
|
2013-07-19 19:14:58 -03:00
|
|
|
// return the differential pressure in Pascal for the last
|
|
|
|
// airspeed reading. Used by the calibration code
|
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
|
|
|
|
2015-11-30 02:27:20 -04:00
|
|
|
// return the current calibration offset
|
2017-11-03 03:17:34 -03:00
|
|
|
float get_offset(uint8_t i) const {
|
|
|
|
return param[i].offset;
|
2014-11-13 02:49:04 -04:00
|
|
|
}
|
2018-03-09 17:12:05 -04:00
|
|
|
float get_offset(void) const { return get_offset(primary); }
|
2014-11-13 02:49:04 -04:00
|
|
|
|
2016-05-24 01:22:40 -03:00
|
|
|
// return the current corrected pressure
|
2017-11-03 03:17:34 -03:00
|
|
|
float get_corrected_pressure(uint8_t i) const {
|
|
|
|
return state[i].corrected_pressure;
|
2013-07-19 19:14:58 -03:00
|
|
|
}
|
2018-03-09 17:12:05 -04:00
|
|
|
float get_corrected_pressure(void) const { return get_corrected_pressure(primary); }
|
2013-07-19 19:14:58 -03:00
|
|
|
|
2013-07-19 22:11:04 -03:00
|
|
|
// set the apparent to true airspeed ratio
|
2017-11-03 03:17:34 -03:00
|
|
|
void set_EAS2TAS(uint8_t i, float v) {
|
|
|
|
state[i].EAS2TAS = v;
|
2013-07-19 22:11:04 -03:00
|
|
|
}
|
2018-03-09 17:12:05 -04:00
|
|
|
void set_EAS2TAS(float v) { set_EAS2TAS(primary, v); }
|
2013-07-19 22:11:04 -03:00
|
|
|
|
|
|
|
// get the apparent to true airspeed ratio
|
2017-11-03 03:17:34 -03:00
|
|
|
float get_EAS2TAS(uint8_t i) const {
|
|
|
|
return state[i].EAS2TAS;
|
2013-07-19 22:11:04 -03:00
|
|
|
}
|
2018-03-09 17:12:05 -04:00
|
|
|
float get_EAS2TAS(void) const { return get_EAS2TAS(primary); }
|
2013-07-19 22:11:04 -03: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
|
|
|
|
|
|
|
// log data to MAVLink
|
|
|
|
void log_mavlink_send(mavlink_channel_t chan, const Vector3f &vground);
|
2013-07-19 19:14:58 -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 {
|
|
|
|
return state[i].healthy && (fabsf(param[i].offset) > 0 || state[i].use_zero_offset) && enabled(i);
|
|
|
|
}
|
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
|
|
|
|
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,
|
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-09 17:12:05 -04:00
|
|
|
|
2018-03-09 04:07:34 -04:00
|
|
|
private:
|
2018-03-09 17:12:05 -04:00
|
|
|
|
2017-11-03 03:17:34 -03:00
|
|
|
AP_Int8 primary_sensor;
|
|
|
|
|
|
|
|
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 EAS2TAS;
|
|
|
|
bool healthy:1;
|
|
|
|
bool hil_set:1;
|
|
|
|
float hil_pressure;
|
|
|
|
uint32_t last_update_ms;
|
|
|
|
bool use_zero_offset;
|
|
|
|
|
|
|
|
// state of runtime calibration
|
|
|
|
struct {
|
|
|
|
uint32_t start_ms;
|
|
|
|
uint16_t count;
|
|
|
|
float sum;
|
|
|
|
uint16_t read_count;
|
|
|
|
} cal;
|
|
|
|
|
|
|
|
Airspeed_Calibration calibration;
|
|
|
|
float last_saved_ratio;
|
|
|
|
uint8_t counter;
|
|
|
|
} state[AIRSPEED_MAX_SENSORS];
|
2018-03-09 17:12:05 -04:00
|
|
|
|
2017-11-03 03:17:34 -03:00
|
|
|
// current primary sensor
|
|
|
|
uint8_t primary;
|
|
|
|
|
|
|
|
void read(uint8_t i);
|
|
|
|
float get_pressure(uint8_t i);
|
|
|
|
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-03-09 17:12:05 -04:00
|
|
|
|
2017-11-03 03:17:34 -03:00
|
|
|
AP_Airspeed_Backend *sensor[AIRSPEED_MAX_SENSORS];
|
2012-07-15 22:21:20 -03:00
|
|
|
};
|