2011-12-28 05:32:21 -04:00
|
|
|
/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
2011-11-05 22:11:25 -03:00
|
|
|
|
|
|
|
#ifndef __AP_BARO_H__
|
|
|
|
#define __AP_BARO_H__
|
|
|
|
|
2015-08-11 03:28:42 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
#include <AP_Param/AP_Param.h>
|
|
|
|
#include <Filter/Filter.h>
|
|
|
|
#include <Filter/DerivativeFilter.h>
|
2011-12-09 02:33:00 -04:00
|
|
|
|
2014-10-19 16:22:51 -03:00
|
|
|
// maximum number of sensor instances
|
|
|
|
#if HAL_CPU_CLASS == HAL_CPU_CLASS_16
|
|
|
|
#define BARO_MAX_INSTANCES 1
|
|
|
|
#else
|
|
|
|
#define BARO_MAX_INSTANCES 2
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// maximum number of drivers. Note that a single driver can provide
|
|
|
|
// multiple sensor instances
|
|
|
|
#if HAL_CPU_CLASS == HAL_CPU_CLASS_16
|
|
|
|
#define BARO_MAX_DRIVERS 1
|
|
|
|
#else
|
|
|
|
#define BARO_MAX_DRIVERS 2
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class AP_Baro_Backend;
|
|
|
|
|
2011-11-05 22:11:25 -03:00
|
|
|
class AP_Baro
|
|
|
|
{
|
2014-10-19 16:22:51 -03:00
|
|
|
friend class AP_Baro_Backend;
|
|
|
|
|
2012-08-17 03:09:24 -03:00
|
|
|
public:
|
2014-10-19 16:22:51 -03:00
|
|
|
// constructor
|
|
|
|
AP_Baro();
|
2012-12-12 17:43:00 -04:00
|
|
|
|
2014-10-19 16:22:51 -03:00
|
|
|
// initialise the barometer object, loading backend drivers
|
|
|
|
void init(void);
|
2014-08-13 09:42:14 -03:00
|
|
|
|
2014-10-19 16:22:51 -03:00
|
|
|
// update the barometer object, asking backends to push data to
|
|
|
|
// the frontend
|
|
|
|
void update(void);
|
|
|
|
|
|
|
|
// healthy - returns true if sensor and derived altitude are good
|
|
|
|
bool healthy(void) const { return healthy(_primary); }
|
2015-01-08 21:59:01 -04:00
|
|
|
bool healthy(uint8_t instance) const { return sensors[instance].healthy && sensors[instance].alt_ok && sensors[instance].calibrated; }
|
2013-09-21 08:30:41 -03:00
|
|
|
|
2015-01-06 21:45:01 -04:00
|
|
|
// check if all baros are healthy - used for SYS_STATUS report
|
|
|
|
bool all_healthy(void) const;
|
|
|
|
|
2013-09-21 08:30:41 -03:00
|
|
|
// pressure in Pascal. Divide by 100 for millibars or hectopascals
|
2014-10-19 16:22:51 -03:00
|
|
|
float get_pressure(void) const { return get_pressure(_primary); }
|
|
|
|
float get_pressure(uint8_t instance) const { return sensors[instance].pressure; }
|
2012-08-17 03:09:24 -03:00
|
|
|
|
2013-09-21 08:30:41 -03:00
|
|
|
// temperature in degrees C
|
2014-10-19 16:22:51 -03:00
|
|
|
float get_temperature(void) const { return get_temperature(_primary); }
|
|
|
|
float get_temperature(uint8_t instance) const { return sensors[instance].temperature; }
|
2012-06-19 23:25:19 -03:00
|
|
|
|
2014-10-19 16:22:51 -03:00
|
|
|
// accumulate a reading on sensors. Some backends without their
|
|
|
|
// own thread or a timer may need this.
|
|
|
|
void accumulate(void);
|
2013-01-09 08:05:17 -04:00
|
|
|
|
2012-06-19 23:25:19 -03:00
|
|
|
// calibrate the barometer. This must be called on startup if the
|
|
|
|
// altitude/climb_rate/acceleration interfaces are ever used
|
2014-10-19 16:22:51 -03:00
|
|
|
void calibrate(void);
|
2012-06-19 23:25:19 -03:00
|
|
|
|
2013-10-05 05:44:00 -03:00
|
|
|
// update the barometer calibration to the current pressure. Can
|
|
|
|
// be used for incremental preflight update of baro
|
2014-10-19 16:22:51 -03:00
|
|
|
void update_calibration(void);
|
2013-10-05 05:44:00 -03:00
|
|
|
|
2012-06-19 23:25:19 -03:00
|
|
|
// get current altitude in meters relative to altitude at the time
|
|
|
|
// of the last calibrate() call
|
2014-10-19 16:22:51 -03:00
|
|
|
float get_altitude(void) const { return get_altitude(_primary); }
|
|
|
|
float get_altitude(uint8_t instance) const { return sensors[instance].altitude; }
|
2012-06-19 23:25:19 -03:00
|
|
|
|
2014-04-11 03:34:02 -03:00
|
|
|
// get altitude difference in meters relative given a base
|
|
|
|
// pressure in Pascal
|
2014-08-13 03:21:52 -03:00
|
|
|
float get_altitude_difference(float base_pressure, float pressure) const;
|
2014-04-11 03:34:02 -03:00
|
|
|
|
2013-06-26 05:32:37 -03:00
|
|
|
// get scale factor required to convert equivalent to true airspeed
|
2014-10-19 16:22:51 -03:00
|
|
|
float get_EAS2TAS(void);
|
2012-07-05 03:26:56 -03:00
|
|
|
|
2015-04-29 02:12:41 -03:00
|
|
|
// get air density / sea level density - decreases as altitude climbs
|
2015-04-28 15:15:49 -03:00
|
|
|
float get_air_density_ratio(void);
|
|
|
|
|
2012-06-19 23:25:19 -03:00
|
|
|
// get current climb rate in meters/s. A positive number means
|
|
|
|
// going up
|
2014-10-19 16:22:51 -03:00
|
|
|
float get_climb_rate(void);
|
2012-06-19 23:25:19 -03:00
|
|
|
|
2013-09-21 08:30:41 -03:00
|
|
|
// ground temperature in degrees C
|
2012-06-19 23:25:19 -03:00
|
|
|
// the ground values are only valid after calibration
|
2014-10-19 16:22:51 -03:00
|
|
|
float get_ground_temperature(void) const { return get_ground_temperature(_primary); }
|
|
|
|
float get_ground_temperature(uint8_t i) const { return sensors[i].ground_temperature.get(); }
|
2013-09-21 08:30:41 -03:00
|
|
|
|
|
|
|
// ground pressure in Pascal
|
|
|
|
// the ground values are only valid after calibration
|
2014-10-19 16:22:51 -03:00
|
|
|
float get_ground_pressure(void) const { return get_ground_pressure(_primary); }
|
|
|
|
float get_ground_pressure(uint8_t i) const { return sensors[i].ground_pressure.get(); }
|
2012-06-19 23:25:19 -03:00
|
|
|
|
2014-11-11 20:26:28 -04:00
|
|
|
// set the temperature to be used for altitude calibration. This
|
|
|
|
// allows an external temperature source (such as a digital
|
|
|
|
// airspeed sensor) to be used as the temperature source
|
|
|
|
void set_external_temperature(float temperature);
|
|
|
|
|
2013-08-08 10:33:53 -03:00
|
|
|
// get last time sample was taken (in ms)
|
2014-10-19 16:22:51 -03:00
|
|
|
uint32_t get_last_update(void) const { return get_last_update(_primary); }
|
|
|
|
uint32_t get_last_update(uint8_t instance) const { return sensors[_primary].last_update_ms; }
|
2012-11-07 05:58:36 -04:00
|
|
|
|
2014-10-19 16:22:51 -03:00
|
|
|
// settable parameters
|
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
2012-06-27 02:59:52 -03:00
|
|
|
|
2014-10-19 16:22:51 -03:00
|
|
|
float get_calibration_temperature(void) const { return get_calibration_temperature(_primary); }
|
|
|
|
float get_calibration_temperature(uint8_t instance) const;
|
2014-08-13 09:42:14 -03:00
|
|
|
|
2014-10-19 16:22:51 -03:00
|
|
|
// HIL (and SITL) interface, setting altitude
|
|
|
|
void setHIL(float altitude_msl);
|
2014-08-13 09:42:14 -03:00
|
|
|
|
2014-10-19 16:22:51 -03:00
|
|
|
// HIL (and SITL) interface, setting pressure and temperature
|
|
|
|
void setHIL(uint8_t instance, float pressure, float temperature);
|
2012-06-19 23:25:19 -03:00
|
|
|
|
2014-10-19 16:22:51 -03:00
|
|
|
// register a new sensor, claiming a sensor slot. If we are out of
|
|
|
|
// slots it will panic
|
|
|
|
uint8_t register_sensor(void);
|
2014-11-11 20:26:28 -04:00
|
|
|
|
2015-01-05 07:29:01 -04:00
|
|
|
// return number of registered sensors
|
|
|
|
uint8_t num_instances(void) const { return _num_sensors; }
|
|
|
|
|
2015-02-09 16:39:48 -04:00
|
|
|
// enable HIL mode
|
|
|
|
void set_hil_mode(void) { _hil_mode = true; }
|
|
|
|
|
2014-10-19 16:22:51 -03:00
|
|
|
private:
|
|
|
|
// how many drivers do we have?
|
|
|
|
uint8_t _num_drivers;
|
|
|
|
AP_Baro_Backend *drivers[BARO_MAX_DRIVERS];
|
|
|
|
|
|
|
|
// how many sensors do we have?
|
|
|
|
uint8_t _num_sensors;
|
|
|
|
|
|
|
|
// what is the primary sensor at the moment?
|
|
|
|
uint8_t _primary;
|
|
|
|
|
|
|
|
struct sensor {
|
|
|
|
uint32_t last_update_ms; // last update time in ms
|
|
|
|
bool healthy:1; // true if sensor is healthy
|
|
|
|
bool alt_ok:1; // true if calculated altitude is ok
|
2015-01-08 21:59:01 -04:00
|
|
|
bool calibrated:1; // true if calculated calibrated successfully
|
2014-10-19 16:22:51 -03:00
|
|
|
float pressure; // pressure in Pascal
|
|
|
|
float temperature; // temperature in degrees C
|
|
|
|
float altitude; // calculated altitude
|
|
|
|
AP_Float ground_temperature;
|
|
|
|
AP_Float ground_pressure;
|
|
|
|
} sensors[BARO_MAX_INSTANCES];
|
2014-11-11 20:26:28 -04:00
|
|
|
|
2015-08-25 15:36:58 -03:00
|
|
|
AP_Float _alt_offset;
|
2013-06-26 05:32:37 -03:00
|
|
|
float _last_altitude_EAS2TAS;
|
|
|
|
float _EAS2TAS;
|
2014-11-11 20:26:28 -04:00
|
|
|
float _external_temperature;
|
2014-12-11 00:06:24 -04:00
|
|
|
uint32_t _last_external_temperature_ms;
|
2012-08-17 03:09:24 -03:00
|
|
|
DerivativeFilterFloat_Size7 _climb_rate_filter;
|
2015-02-09 16:39:48 -04:00
|
|
|
bool _hil_mode:1;
|
2014-10-19 16:22:51 -03:00
|
|
|
|
|
|
|
void SimpleAtmosphere(const float alt, float &sigma, float &delta, float &theta);
|
2011-11-05 22:11:25 -03:00
|
|
|
};
|
|
|
|
|
2014-10-19 16:22:51 -03:00
|
|
|
#include "AP_Baro_Backend.h"
|
2011-11-05 22:11:25 -03:00
|
|
|
#include "AP_Baro_MS5611.h"
|
2015-01-05 07:00:32 -04:00
|
|
|
#include "AP_Baro_BMP085.h"
|
2013-05-02 02:08:42 -03:00
|
|
|
#include "AP_Baro_HIL.h"
|
2013-01-03 23:58:24 -04:00
|
|
|
#include "AP_Baro_PX4.h"
|
2011-11-05 22:11:25 -03:00
|
|
|
|
|
|
|
#endif // __AP_BARO_H__
|