move pressure altitude from baros to sensors module

This commit is contained in:
Daniel Agar
2018-04-11 23:26:58 -04:00
parent bdf4f19867
commit 5dc23def2a
22 changed files with 55 additions and 794 deletions
@@ -101,9 +101,6 @@ protected:
/* last report */
struct baro_report report;
/* altitude conversion calibration */
unsigned _msl_pressure; /* in Pa */
orb_advert_t _baro_topic;
int _orb_class_instance;
@@ -136,7 +133,6 @@ BAROSIM::BAROSIM(const char *path) :
VirtDevObj("BAROSIM", path, BARO_BASE_DEVICE_PATH, BAROSIM_MEASURE_INTERVAL_US),
_reports(nullptr),
report{},
_msl_pressure(101325),
_baro_topic(nullptr),
_orb_class_instance(-1),
_sample_perf(perf_alloc(PC_ELAPSED, "barosim_read")),
@@ -202,27 +198,6 @@ out:
int
BAROSIM::devIOCTL(unsigned long cmd, unsigned long arg)
{
//PX4_WARN("baro IOCTL %" PRIu64 , hrt_absolute_time());
switch (cmd) {
case BAROIOCSMSLPRESSURE:
/* range-check for sanity */
if ((arg < 80000) || (arg > 120000)) {
return -EINVAL;
}
_msl_pressure = arg;
return OK;
case BAROIOCGMSLPRESSURE:
return _msl_pressure;
default:
break;
}
/* give it to the bus-specific superclass */
// return bus_ioctl(filp, cmd, arg);
return VirtDevObj::devIOCTL(cmd, arg);
@@ -264,7 +239,6 @@ BAROSIM::collect()
}
report.pressure = raw_baro.pressure;
report.altitude = raw_baro.altitude;
report.temperature = raw_baro.temperature;
/* fake device ID */
@@ -150,40 +150,12 @@ int DfBmp280Wrapper::_publish(struct baro_sensor_data &data)
{
perf_begin(_baro_sample_perf);
baro_report baro_report = {};
baro_report baro_report;
baro_report.timestamp = hrt_absolute_time();
baro_report.pressure = data.pressure_pa / 100.0f; // to mbar
baro_report.temperature = data.temperature_c;
// TODO: verify this, it's just copied from the MS5611 driver.
// Constant for now
const double MSL_PRESSURE_KPA = 101325.0 / 1000.0;
/* tropospheric properties (0-11km) for standard atmosphere */
const double T1 = 15.0 + 273.15; /* temperature at base height in Kelvin */
const double a = -6.5 / 1000; /* temperature gradient in degrees per metre */
const double g = 9.80665; /* gravity constant in m/s/s */
const double R = 287.05; /* ideal gas constant in J/kg/K */
/* current pressure at MSL in kPa */
double p1 = MSL_PRESSURE_KPA;
/* measured pressure in kPa */
double p = static_cast<double>(data.pressure_pa) / 1000.0;
/*
* Solve:
*
* / -(aR / g) \
* | (p / p1) . T1 | - T1
* \ /
* h = ------------------------------- + h1
* a
*/
baro_report.altitude = (((pow((p / p1), (-(a * R) / g))) * T1) - T1) / a;
// TODO: when is this ever blocked?
if (!(m_pub_blocked)) {
@@ -148,40 +148,12 @@ int DfMS5607Wrapper::_publish(struct baro_sensor_data &data)
{
perf_begin(_baro_sample_perf);
baro_report baro_report = {};
baro_report baro_report;
baro_report.timestamp = hrt_absolute_time();
baro_report.pressure = data.pressure_pa;
baro_report.temperature = data.temperature_c;
// TODO: verify this, it's just copied from the MS5611 driver.
// Constant for now
const double MSL_PRESSURE_KPA = 101325.0 / 1000.0;
/* tropospheric properties (0-11km) for standard atmosphere */
const double T1 = 15.0 + 273.15; /* temperature at base height in Kelvin */
const double a = -6.5 / 1000; /* temperature gradient in degrees per metre */
const double g = 9.80665; /* gravity constant in m/s/s */
const double R = 287.05; /* ideal gas constant in J/kg/K */
/* current pressure at MSL in kPa */
double p1 = MSL_PRESSURE_KPA;
/* measured pressure in kPa */
double p = static_cast<double>(data.pressure_pa) / 1000.0;
/*
* Solve:
*
* / -(aR / g) \
* | (p / p1) . T1 | - T1
* \ /
* h = ------------------------------- + h1
* a
*/
baro_report.altitude = (((pow((p / p1), (-(a * R) / g))) * T1) - T1) / a;
// TODO: when is this ever blocked?
if (!(m_pub_blocked)) {
@@ -148,40 +148,12 @@ int DfMS5611Wrapper::_publish(struct baro_sensor_data &data)
{
perf_begin(_baro_sample_perf);
baro_report baro_report = {};
baro_report baro_report;
baro_report.timestamp = hrt_absolute_time();
baro_report.pressure = data.pressure_pa / 100.0f; // convert to mbar
baro_report.temperature = data.temperature_c;
// TODO: verify this, it's just copied from the MS5611 driver.
// Constant for now
const double MSL_PRESSURE_KPA = 101325.0 / 1000.0;
/* tropospheric properties (0-11km) for standard atmosphere */
const double T1 = 15.0 + 273.15; /* temperature at base height in Kelvin */
const double a = -6.5 / 1000; /* temperature gradient in degrees per metre */
const double g = 9.80665; /* gravity constant in m/s/s */
const double R = 287.05; /* ideal gas constant in J/kg/K */
/* current pressure at MSL in kPa */
double p1 = MSL_PRESSURE_KPA;
/* measured pressure in kPa */
double p = static_cast<double>(data.pressure_pa) / 1000.0;
/*
* Solve:
*
* / -(aR / g) \
* | (p / p1) . T1 | - T1
* \ /
* h = ------------------------------- + h1
* a
*/
baro_report.altitude = (((pow((p / p1), (-(a * R) / g))) * T1) - T1) / a;
// TODO: when is this ever blocked?
if (!(m_pub_blocked)) {