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__
|
|
|
|
|
2012-06-19 23:25:19 -03:00
|
|
|
#include <AP_Param.h>
|
|
|
|
#include <Filter.h>
|
2012-07-04 19:08:16 -03:00
|
|
|
#include <DerivativeFilter.h>
|
2011-12-09 02:33:00 -04:00
|
|
|
|
2011-11-05 22:11:25 -03:00
|
|
|
class AP_Baro
|
|
|
|
{
|
2012-08-17 03:09:24 -03:00
|
|
|
public:
|
2014-08-14 01:14:41 -03:00
|
|
|
AP_Baro() :
|
|
|
|
_last_update(0),
|
|
|
|
_pressure_samples(0),
|
|
|
|
_altitude(0.0f),
|
|
|
|
_last_altitude_EAS2TAS(0.0f),
|
|
|
|
_EAS2TAS(0.0f),
|
|
|
|
_last_altitude_t(0)
|
|
|
|
{
|
2014-08-13 09:42:14 -03:00
|
|
|
// initialise flags
|
|
|
|
_flags.healthy = false;
|
|
|
|
_flags.alt_ok = false;
|
|
|
|
|
2012-12-12 17:43:00 -04:00
|
|
|
AP_Param::setup_object_defaults(this, var_info);
|
2012-08-17 03:09:24 -03:00
|
|
|
}
|
2012-12-12 17:43:00 -04:00
|
|
|
|
2014-08-13 09:42:14 -03:00
|
|
|
// healthy - returns true if sensor and derived altitude are good
|
|
|
|
bool healthy() const { return _flags.healthy && _flags.alt_ok; }
|
|
|
|
|
2012-10-11 14:53:21 -03:00
|
|
|
virtual bool init()=0;
|
2012-08-17 03:09:24 -03:00
|
|
|
virtual uint8_t read() = 0;
|
2013-09-21 08:30:41 -03:00
|
|
|
|
|
|
|
// pressure in Pascal. Divide by 100 for millibars or hectopascals
|
2012-08-17 03:09:24 -03:00
|
|
|
virtual float get_pressure() = 0;
|
|
|
|
|
2013-09-21 08:30:41 -03:00
|
|
|
// temperature in degrees C
|
|
|
|
virtual float get_temperature() = 0;
|
2012-06-19 23:25:19 -03:00
|
|
|
|
2013-01-09 08:05:17 -04:00
|
|
|
// accumulate a reading - overridden in some drivers
|
|
|
|
virtual void accumulate(void) {}
|
|
|
|
|
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
|
|
|
|
// the callback is a delay() like routine
|
2012-10-11 14:53:21 -03:00
|
|
|
void calibrate();
|
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
|
|
|
|
void update_calibration();
|
|
|
|
|
2012-06-19 23:25:19 -03:00
|
|
|
// get current altitude in meters relative to altitude at the time
|
|
|
|
// of the last calibrate() call
|
2012-08-17 03:09:24 -03:00
|
|
|
float get_altitude(void);
|
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
|
|
|
|
float get_EAS2TAS(void);
|
|
|
|
|
2012-07-05 03:26:56 -03:00
|
|
|
// return how many pressure samples were used to obtain
|
|
|
|
// the last pressure reading
|
2012-08-17 03:09:24 -03:00
|
|
|
uint8_t get_pressure_samples(void) {
|
|
|
|
return _pressure_samples;
|
|
|
|
}
|
2012-07-05 03:26:56 -03:00
|
|
|
|
2012-06-19 23:25:19 -03:00
|
|
|
// get current climb rate in meters/s. A positive number means
|
|
|
|
// going up
|
2012-08-17 03:09:24 -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
|
2012-08-17 03:09:24 -03:00
|
|
|
float get_ground_temperature(void) {
|
|
|
|
return _ground_temperature.get();
|
|
|
|
}
|
2013-09-21 08:30:41 -03:00
|
|
|
|
|
|
|
// ground pressure in Pascal
|
|
|
|
// the ground values are only valid after calibration
|
2012-08-17 03:09:24 -03:00
|
|
|
float get_ground_pressure(void) {
|
|
|
|
return _ground_pressure.get();
|
|
|
|
}
|
2012-06-19 23:25:19 -03:00
|
|
|
|
2013-08-08 10:33:53 -03:00
|
|
|
// get last time sample was taken (in ms)
|
2014-04-11 03:34:02 -03:00
|
|
|
uint32_t get_last_update() const { return _last_update; };
|
2012-11-07 05:58:36 -04:00
|
|
|
|
2012-08-17 03:09:24 -03:00
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
2012-06-27 02:59:52 -03:00
|
|
|
|
2012-06-19 23:25:19 -03:00
|
|
|
protected:
|
2014-08-13 09:42:14 -03:00
|
|
|
|
|
|
|
struct Baro_flags {
|
|
|
|
uint8_t healthy :1; // true if sensor is healthy
|
|
|
|
uint8_t alt_ok :1; // true if calculated altitude is ok
|
|
|
|
} _flags;
|
|
|
|
|
2013-08-08 10:33:53 -03:00
|
|
|
uint32_t _last_update; // in ms
|
2012-08-17 03:09:24 -03:00
|
|
|
uint8_t _pressure_samples;
|
2012-06-19 23:25:19 -03:00
|
|
|
|
|
|
|
private:
|
2012-08-17 03:09:24 -03:00
|
|
|
AP_Float _ground_temperature;
|
|
|
|
AP_Float _ground_pressure;
|
2013-07-10 01:38:57 -03:00
|
|
|
AP_Int8 _alt_offset;
|
2012-08-17 03:09:24 -03:00
|
|
|
float _altitude;
|
2013-06-26 05:32:37 -03:00
|
|
|
float _last_altitude_EAS2TAS;
|
|
|
|
float _EAS2TAS;
|
2012-08-17 03:09:24 -03:00
|
|
|
uint32_t _last_altitude_t;
|
|
|
|
DerivativeFilterFloat_Size7 _climb_rate_filter;
|
2011-11-05 22:11:25 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
#include "AP_Baro_MS5611.h"
|
2011-11-27 01:34:51 -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"
|
2014-03-31 14:45:34 -03:00
|
|
|
#include "AP_Baro_VRBRAIN.h"
|
2011-11-05 22:11:25 -03:00
|
|
|
|
|
|
|
#endif // __AP_BARO_H__
|