mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-22 14:24:21 +08:00
sensors: add baro calibration and cleanup
- sensor_baro.msg use SI (pressure in Pascals) - update all barometer drivers to publish directly and remove PX4Barometer helper - introduce baro cal (offset) mainly as a mechanism to adjust relative priority - commander: add simple baro cal that sets baro offsets to align with GPS altitude (if available) - create new sensors_status.msg to generalize sensor reporting
This commit is contained in:
@@ -705,18 +705,21 @@ void quickCalibrate() {
|
||||
|
||||
sh './Tools/HIL/run_nsh_cmd.py --device `find /dev/serial -name *usb-*` --cmd "gyro_calibration status || true"'
|
||||
|
||||
sh './Tools/HIL/run_nsh_cmd.py --device `find /dev/serial -name *usb-*` --cmd "commander calibrate accel quick"'
|
||||
sh './Tools/HIL/run_nsh_cmd.py --device `find /dev/serial -name *usb-*` --cmd "commander calibrate accel quick; sleep 1"'
|
||||
sh './Tools/HIL/run_nsh_cmd.py --device `find /dev/serial -name *usb-*` --cmd "param show CAL_ACC*"'
|
||||
|
||||
sh './Tools/HIL/run_nsh_cmd.py --device `find /dev/serial -name *usb-*` --cmd "commander calibrate gyro"'
|
||||
sh './Tools/HIL/run_nsh_cmd.py --device `find /dev/serial -name *usb-*` --cmd "commander calibrate gyro; sleep 2"'
|
||||
sh './Tools/HIL/run_nsh_cmd.py --device `find /dev/serial -name *usb-*` --cmd "param show CAL_GYRO*"'
|
||||
|
||||
sh './Tools/HIL/run_nsh_cmd.py --device `find /dev/serial -name *usb-*` --cmd "commander calibrate level"'
|
||||
sh './Tools/HIL/run_nsh_cmd.py --device `find /dev/serial -name *usb-*` --cmd "commander calibrate level; sleep 2"'
|
||||
sh './Tools/HIL/run_nsh_cmd.py --device `find /dev/serial -name *usb-*` --cmd "param show SENS*"'
|
||||
|
||||
sh './Tools/HIL/run_nsh_cmd.py --device `find /dev/serial -name *usb-*` --cmd "commander calibrate mag quick"'
|
||||
sh './Tools/HIL/run_nsh_cmd.py --device `find /dev/serial -name *usb-*` --cmd "commander calibrate mag quick; sleep 1"'
|
||||
sh './Tools/HIL/run_nsh_cmd.py --device `find /dev/serial -name *usb-*` --cmd "param show CAL_MAG*"'
|
||||
|
||||
sh './Tools/HIL/run_nsh_cmd.py --device `find /dev/serial -name *usb-*` --cmd "commander calibrate baro; sleep 5"'
|
||||
sh './Tools/HIL/run_nsh_cmd.py --device `find /dev/serial -name *usb-*` --cmd "param show CAL_BARO*"'
|
||||
|
||||
sh './Tools/HIL/run_nsh_cmd.py --device `find /dev/serial -name *usb-*` --cmd "param show CAL_*"' // parameters after
|
||||
sh './Tools/HIL/run_nsh_cmd.py --device `find /dev/serial -name *usb-*` --cmd "sensors status"'
|
||||
}
|
||||
|
||||
@@ -152,6 +152,7 @@ set(msg_files
|
||||
sensor_preflight_mag.msg
|
||||
sensor_selection.msg
|
||||
sensors_status_imu.msg
|
||||
sensors_status.msg
|
||||
system_power.msg
|
||||
takeoff_status.msg
|
||||
task_stack_info.msg
|
||||
|
||||
+5
-3
@@ -3,8 +3,10 @@ uint64 timestamp_sample
|
||||
|
||||
uint32 device_id # unique device ID for the sensor that does not change between power cycles
|
||||
|
||||
float32 pressure # static pressure measurement in Pascals
|
||||
|
||||
float32 temperature # temperature in degrees Celsius
|
||||
|
||||
uint32 error_count
|
||||
|
||||
float32 pressure # static pressure measurement in millibar
|
||||
|
||||
float32 temperature # static temperature measurement in deg Celsius
|
||||
uint8 ORB_QUEUE_LENGTH = 4
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
#
|
||||
# Sensor check metrics. This will be zero for a sensor that's primary or unpopulated.
|
||||
#
|
||||
uint64 timestamp # time since system start (microseconds)
|
||||
|
||||
uint32 device_id_primary # current primary device id for reference
|
||||
|
||||
uint32[4] device_ids
|
||||
float32[4] inconsistency # magnitude of difference between sensor instance and mean
|
||||
bool[4] healthy # sensor healthy
|
||||
uint8[4] priority
|
||||
bool[4] enabled
|
||||
bool[4] external
|
||||
|
||||
# TOPICS sensors_status sensors_status_baro sensors_status_mag
|
||||
@@ -10,3 +10,5 @@ float32 baro_temp_celcius # Temperature in degrees Celsius
|
||||
float32 baro_pressure_pa # Absolute pressure in Pascals
|
||||
|
||||
float32 rho # air density
|
||||
|
||||
uint8 calibration_count # Calibration changed counter. Monotonically increases whenever calibration changes.
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
|
||||
BMP280::BMP280(const I2CSPIDriverConfig &config, bmp280::IBMP280 *interface) :
|
||||
I2CSPIDriver(config),
|
||||
_px4_baro(interface->get_device_id()),
|
||||
_interface(interface),
|
||||
_sample_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": sample")),
|
||||
_measure_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": measure")),
|
||||
@@ -172,11 +171,15 @@ BMP280::collect()
|
||||
float pf = ((float) p_raw + x1) / x2;
|
||||
const float P = (pf * _fcal.p9 + _fcal.p8) * pf + _fcal.p7;
|
||||
|
||||
_px4_baro.set_error_count(perf_event_count(_comms_errors));
|
||||
_px4_baro.set_temperature(T);
|
||||
|
||||
float pressure = P / 100.0f; // to mbar
|
||||
_px4_baro.update(timestamp_sample, pressure);
|
||||
// publish
|
||||
sensor_baro_s sensor_baro{};
|
||||
sensor_baro.timestamp_sample = timestamp_sample;
|
||||
sensor_baro.device_id = _interface->get_device_id();
|
||||
sensor_baro.pressure = P;
|
||||
sensor_baro.temperature = T;
|
||||
sensor_baro.error_count = perf_event_count(_comms_errors);
|
||||
sensor_baro.timestamp = hrt_absolute_time();
|
||||
_sensor_baro_pub.publish(sensor_baro);
|
||||
|
||||
perf_end(_sample_perf);
|
||||
|
||||
|
||||
@@ -39,7 +39,8 @@
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
#include <px4_platform_common/i2c_spi_buses.h>
|
||||
#include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
|
||||
#include <lib/drivers/barometer/PX4Barometer.hpp>
|
||||
#include <uORB/PublicationMulti.hpp>
|
||||
#include <uORB/topics/sensor_baro.h>
|
||||
#include <lib/perf/perf_counter.h>
|
||||
|
||||
class BMP280 : public I2CSPIDriver<BMP280>
|
||||
@@ -61,7 +62,7 @@ private:
|
||||
int measure(); //start measure
|
||||
int collect(); //get results and publish
|
||||
|
||||
PX4Barometer _px4_baro;
|
||||
uORB::PublicationMulti<sensor_baro_s> _sensor_baro_pub{ORB_ID(sensor_baro)};
|
||||
|
||||
bmp280::IBMP280 *_interface;
|
||||
|
||||
|
||||
@@ -42,6 +42,5 @@ px4_add_module(
|
||||
|
||||
bmp280_main.cpp
|
||||
DEPENDS
|
||||
drivers_barometer
|
||||
px4_work_queue
|
||||
)
|
||||
|
||||
@@ -40,6 +40,5 @@ px4_add_module(
|
||||
bmp388.cpp
|
||||
bmp388_main.cpp
|
||||
DEPENDS
|
||||
drivers_barometer
|
||||
px4_work_queue
|
||||
)
|
||||
|
||||
@@ -43,7 +43,6 @@
|
||||
|
||||
BMP388::BMP388(const I2CSPIDriverConfig &config, IBMP388 *interface) :
|
||||
I2CSPIDriver(config),
|
||||
_px4_baro(interface->get_device_id()),
|
||||
_interface(interface),
|
||||
_sample_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": read")),
|
||||
_measure_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": measure")),
|
||||
@@ -165,14 +164,18 @@ BMP388::collect()
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
_px4_baro.set_error_count(perf_event_count(_comms_errors));
|
||||
|
||||
float temperature = (float)(data.temperature / 100.0f);
|
||||
float pressure = (float)(data.pressure / 100.0f); // to Pascal
|
||||
pressure = pressure / 100.0f; // to mbar
|
||||
|
||||
_px4_baro.set_temperature(temperature);
|
||||
_px4_baro.update(timestamp_sample, pressure);
|
||||
// publish
|
||||
sensor_baro_s sensor_baro{};
|
||||
sensor_baro.timestamp_sample = timestamp_sample;
|
||||
sensor_baro.device_id = _interface->get_device_id();
|
||||
sensor_baro.pressure = pressure;
|
||||
sensor_baro.temperature = temperature;
|
||||
sensor_baro.error_count = perf_event_count(_comms_errors);
|
||||
sensor_baro.timestamp = hrt_absolute_time();
|
||||
_sensor_baro_pub.publish(sensor_baro);
|
||||
|
||||
perf_end(_sample_perf);
|
||||
|
||||
|
||||
@@ -44,7 +44,8 @@
|
||||
#include <perf/perf_counter.h>
|
||||
#include <px4_platform_common/i2c_spi_buses.h>
|
||||
#include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
|
||||
#include <lib/drivers/barometer/PX4Barometer.hpp>
|
||||
#include <uORB/PublicationMulti.hpp>
|
||||
#include <uORB/topics/sensor_baro.h>
|
||||
|
||||
#include "board_config.h"
|
||||
|
||||
@@ -325,7 +326,7 @@ private:
|
||||
static constexpr uint8_t odr{BMP3_ODR_50_HZ}; // output data rate (not used)
|
||||
static constexpr uint8_t iir_coef{BMP3_IIR_FILTER_DISABLE}; // IIR coefficient
|
||||
|
||||
PX4Barometer _px4_baro;
|
||||
uORB::PublicationMulti<sensor_baro_s> _sensor_baro_pub{ORB_ID(sensor_baro)};
|
||||
IBMP388 *_interface{nullptr};
|
||||
|
||||
unsigned _measure_interval{0}; // interval in microseconds needed to measure
|
||||
|
||||
@@ -40,6 +40,5 @@ px4_add_module(
|
||||
DPS310_SPI.cpp
|
||||
dps310_main.cpp
|
||||
DEPENDS
|
||||
drivers_barometer
|
||||
px4_work_queue
|
||||
)
|
||||
|
||||
@@ -48,7 +48,6 @@ static void getTwosComplement(T &raw, uint8_t length)
|
||||
|
||||
DPS310::DPS310(const I2CSPIDriverConfig &config, device::Device *interface) :
|
||||
I2CSPIDriver(config),
|
||||
_px4_barometer(interface->get_device_id()),
|
||||
_interface(interface),
|
||||
_sample_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": read")),
|
||||
_comms_errors(perf_alloc(PC_COUNT, MODULE_NAME": comm errors"))
|
||||
@@ -233,9 +232,15 @@ DPS310::RunImpl()
|
||||
|
||||
const float Tcomp = c0 * 0.5f + c1 * Traw_sc;
|
||||
|
||||
_px4_barometer.set_error_count(perf_event_count(_comms_errors));
|
||||
_px4_barometer.set_temperature(Tcomp);
|
||||
_px4_barometer.update(timestamp_sample, Pcomp / 100.0f); // Pascals -> Millibar
|
||||
// publish
|
||||
sensor_baro_s sensor_baro{};
|
||||
sensor_baro.timestamp_sample = timestamp_sample;
|
||||
sensor_baro.device_id = _interface->get_device_id();
|
||||
sensor_baro.pressure = Pcomp;
|
||||
sensor_baro.temperature = Tcomp;
|
||||
sensor_baro.error_count = perf_event_count(_comms_errors);
|
||||
sensor_baro.timestamp = hrt_absolute_time();
|
||||
_sensor_baro_pub.publish(sensor_baro);
|
||||
|
||||
perf_end(_sample_perf);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <drivers/device/Device.hpp>
|
||||
#include <lib/drivers/barometer/PX4Barometer.hpp>
|
||||
#include <uORB/PublicationMulti.hpp>
|
||||
#include <uORB/topics/sensor_baro.h>
|
||||
#include <lib/perf/perf_counter.h>
|
||||
#include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
|
||||
#include <px4_platform_common/i2c_spi_buses.h>
|
||||
@@ -79,7 +80,7 @@ private:
|
||||
|
||||
static constexpr uint32_t SAMPLE_RATE{32};
|
||||
|
||||
PX4Barometer _px4_barometer;
|
||||
uORB::PublicationMulti<sensor_baro_s> _sensor_baro_pub{ORB_ID(sensor_baro)};
|
||||
|
||||
device::Device *_interface;
|
||||
|
||||
|
||||
@@ -41,6 +41,5 @@ px4_add_module(
|
||||
SPL06_SPI.cpp
|
||||
spl06_main.cpp
|
||||
DEPENDS
|
||||
drivers_barometer
|
||||
px4_work_queue
|
||||
)
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
|
||||
SPL06::SPL06(const I2CSPIDriverConfig &config, spl06::ISPL06 *interface) :
|
||||
I2CSPIDriver(config),
|
||||
_px4_baro(interface->get_device_id()),
|
||||
_interface(interface),
|
||||
_sample_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": sample")),
|
||||
_measure_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": measure")),
|
||||
@@ -224,10 +223,16 @@ SPL06::collect()
|
||||
float fp = (float)_cal.c00 + fpsc * qua2 + ftsc * (float)_cal.c01 + qua3;
|
||||
float temperature = (float)_cal.c0 * 0.5f + (float)_cal.c1 * ftsc;
|
||||
|
||||
_px4_baro.set_error_count(perf_event_count(_comms_errors));
|
||||
_px4_baro.set_temperature(temperature);
|
||||
_px4_baro.update(timestamp_sample, fp / 100.0f); // to millbar
|
||||
//PX4_DEBUG("%d",(int)fp);
|
||||
|
||||
sensor_baro_s sensor_baro{};
|
||||
sensor_baro.timestamp_sample = timestamp_sample;
|
||||
sensor_baro.device_id = _interface->get_device_id();
|
||||
sensor_baro.pressure = fp;
|
||||
sensor_baro.temperature = temperature;
|
||||
sensor_baro.error_count = perf_event_count(_comms_errors);
|
||||
sensor_baro.timestamp = hrt_absolute_time();
|
||||
_sensor_baro_pub.publish(sensor_baro);
|
||||
|
||||
perf_end(_sample_perf);
|
||||
|
||||
return OK;
|
||||
|
||||
@@ -39,8 +39,9 @@
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
#include <px4_platform_common/i2c_spi_buses.h>
|
||||
#include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
|
||||
#include <lib/drivers/barometer/PX4Barometer.hpp>
|
||||
#include <lib/perf/perf_counter.h>
|
||||
#include <uORB/PublicationMulti.hpp>
|
||||
#include <uORB/topics/sensor_baro.h>
|
||||
|
||||
class SPL06 : public I2CSPIDriver<SPL06>
|
||||
{
|
||||
@@ -62,7 +63,7 @@ private:
|
||||
int collect(); //get results and publish
|
||||
int calibrate();
|
||||
|
||||
PX4Barometer _px4_baro;
|
||||
uORB::PublicationMulti<sensor_baro_s> _sensor_baro_pub{ORB_ID(sensor_baro)};
|
||||
|
||||
spl06::ISPL06 *_interface;
|
||||
spl06::data_s _data;
|
||||
|
||||
@@ -41,6 +41,5 @@ px4_add_module(
|
||||
ICP10100.hpp
|
||||
icp10100_main.cpp
|
||||
DEPENDS
|
||||
drivers_barometer
|
||||
px4_work_queue
|
||||
)
|
||||
|
||||
@@ -37,8 +37,7 @@ using namespace time_literals;
|
||||
|
||||
ICP10100::ICP10100(const I2CSPIDriverConfig &config) :
|
||||
I2C(config),
|
||||
I2CSPIDriver(config),
|
||||
_px4_baro(get_device_id())
|
||||
I2CSPIDriver(config)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -236,12 +235,17 @@ ICP10100::RunImpl()
|
||||
|
||||
const hrt_abstime nowx = hrt_absolute_time();
|
||||
float temperature = _temperature_C;
|
||||
float pressure = _pressure_Pa; // to Pascal
|
||||
pressure = pressure / 100.0f; // to mbar
|
||||
float pressure = _pressure_Pa;
|
||||
|
||||
_px4_baro.set_error_count(perf_event_count(_bad_transfer_perf));
|
||||
_px4_baro.set_temperature(temperature);
|
||||
_px4_baro.update(nowx, pressure);
|
||||
// publish
|
||||
sensor_baro_s sensor_baro{};
|
||||
sensor_baro.timestamp_sample = now;
|
||||
sensor_baro.device_id = get_device_id();
|
||||
sensor_baro.pressure = pressure;
|
||||
sensor_baro.temperature = temperature;
|
||||
sensor_baro.error_count = perf_event_count(_bad_transfer_perf);
|
||||
sensor_baro.timestamp = hrt_absolute_time();
|
||||
_sensor_baro_pub.publish(sensor_baro);
|
||||
|
||||
success = true;
|
||||
|
||||
|
||||
@@ -37,7 +37,8 @@
|
||||
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <lib/drivers/device/i2c.h>
|
||||
#include <lib/drivers/barometer/PX4Barometer.hpp>
|
||||
#include <uORB/PublicationMulti.hpp>
|
||||
#include <uORB/topics/sensor_baro.h>
|
||||
#include <lib/perf/perf_counter.h>
|
||||
#include <px4_platform_common/i2c_spi_buses.h>
|
||||
|
||||
@@ -69,7 +70,7 @@ private:
|
||||
int send_command(Cmd cmd);
|
||||
int send_command(Cmd cmd, uint8_t *data, uint8_t len);
|
||||
|
||||
PX4Barometer _px4_baro;
|
||||
uORB::PublicationMulti<sensor_baro_s> _sensor_baro_pub{ORB_ID(sensor_baro)};
|
||||
|
||||
perf_counter_t _reset_perf{perf_alloc(PC_COUNT, MODULE_NAME": reset")};
|
||||
perf_counter_t _sample_perf{perf_alloc(PC_ELAPSED, MODULE_NAME": read")};
|
||||
|
||||
@@ -41,6 +41,5 @@ px4_add_module(
|
||||
ICP10111.hpp
|
||||
icp10111_main.cpp
|
||||
DEPENDS
|
||||
drivers_barometer
|
||||
px4_work_queue
|
||||
)
|
||||
|
||||
@@ -37,8 +37,7 @@ using namespace time_literals;
|
||||
|
||||
ICP10111::ICP10111(const I2CSPIDriverConfig &config) :
|
||||
I2C(config),
|
||||
I2CSPIDriver(config),
|
||||
_px4_baro(get_device_id())
|
||||
I2CSPIDriver(config)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -234,14 +233,18 @@ ICP10111::RunImpl()
|
||||
float b = (_pcal[0] - a) * (s1 + c);
|
||||
float _pressure_Pa = a + b / (c + _raw_p);
|
||||
|
||||
const hrt_abstime nowx = hrt_absolute_time();
|
||||
float temperature = _temperature_C;
|
||||
float pressure = _pressure_Pa; // to Pascal
|
||||
pressure = pressure / 100.0f; // to mbar
|
||||
|
||||
_px4_baro.set_error_count(perf_event_count(_bad_transfer_perf));
|
||||
_px4_baro.set_temperature(temperature);
|
||||
_px4_baro.update(nowx, pressure);
|
||||
// publish
|
||||
sensor_baro_s sensor_baro{};
|
||||
sensor_baro.timestamp_sample = now;
|
||||
sensor_baro.device_id = get_device_id();
|
||||
sensor_baro.pressure = pressure;
|
||||
sensor_baro.temperature = temperature;
|
||||
sensor_baro.error_count = perf_event_count(_bad_transfer_perf);
|
||||
sensor_baro.timestamp = hrt_absolute_time();
|
||||
_sensor_baro_pub.publish(sensor_baro);
|
||||
|
||||
success = true;
|
||||
|
||||
|
||||
@@ -37,7 +37,8 @@
|
||||
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <lib/drivers/device/i2c.h>
|
||||
#include <lib/drivers/barometer/PX4Barometer.hpp>
|
||||
#include <uORB/PublicationMulti.hpp>
|
||||
#include <uORB/topics/sensor_baro.h>
|
||||
#include <lib/perf/perf_counter.h>
|
||||
#include <px4_platform_common/i2c_spi_buses.h>
|
||||
|
||||
@@ -69,7 +70,7 @@ private:
|
||||
int send_command(Cmd cmd);
|
||||
int send_command(Cmd cmd, uint8_t *data, uint8_t len);
|
||||
|
||||
PX4Barometer _px4_baro;
|
||||
uORB::PublicationMulti<sensor_baro_s> _sensor_baro_pub{ORB_ID(sensor_baro)};
|
||||
|
||||
perf_counter_t _reset_perf{perf_alloc(PC_COUNT, MODULE_NAME": reset")};
|
||||
perf_counter_t _sample_perf{perf_alloc(PC_ELAPSED, MODULE_NAME": read")};
|
||||
|
||||
@@ -39,6 +39,5 @@ px4_add_module(
|
||||
LPS22HB_I2C.cpp
|
||||
LPS22HB_SPI.cpp
|
||||
DEPENDS
|
||||
drivers_barometer
|
||||
px4_work_queue
|
||||
)
|
||||
|
||||
@@ -44,7 +44,6 @@
|
||||
|
||||
LPS22HB::LPS22HB(const I2CSPIDriverConfig &config, device::Device *interface) :
|
||||
I2CSPIDriver(config),
|
||||
_px4_baro(interface->get_device_id()),
|
||||
_interface(interface),
|
||||
_sample_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": read")),
|
||||
_comms_errors(perf_alloc(PC_COUNT, MODULE_NAME": comms errors"))
|
||||
@@ -152,14 +151,23 @@ int LPS22HB::collect()
|
||||
|
||||
uint32_t TEMP_OUT = report.TEMP_OUT_L + (report.TEMP_OUT_H << 8);
|
||||
float temperature = 42.5f + (TEMP_OUT / 480.0f);
|
||||
_px4_baro.set_temperature(temperature);
|
||||
|
||||
// To obtain the pressure in hPa, take the two’s complement of the complete word and then divide by 4096 LSB/hPa.
|
||||
uint32_t P = report.PRESS_OUT_XL + (report.PRESS_OUT_L << 8) + (report.PRESS_OUT_H << 16);
|
||||
|
||||
/* Pressure and MSL in mBar */
|
||||
float pressure = P / 4096.0f;
|
||||
_px4_baro.update(timestamp_sample, pressure);
|
||||
float pressure_pa = pressure * 100.f;
|
||||
|
||||
// publish
|
||||
sensor_baro_s sensor_baro{};
|
||||
sensor_baro.timestamp_sample = timestamp_sample;
|
||||
sensor_baro.device_id = _interface->get_device_id();
|
||||
sensor_baro.pressure = pressure_pa;
|
||||
sensor_baro.temperature = temperature;
|
||||
sensor_baro.error_count = perf_event_count(_comms_errors);
|
||||
sensor_baro.timestamp = hrt_absolute_time();
|
||||
_sensor_baro_pub.publish(sensor_baro);
|
||||
|
||||
perf_end(_sample_perf);
|
||||
return PX4_OK;
|
||||
|
||||
@@ -39,7 +39,8 @@
|
||||
#include <lib/perf/perf_counter.h>
|
||||
#include <px4_platform_common/i2c_spi_buses.h>
|
||||
#include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
|
||||
#include <lib/drivers/barometer/PX4Barometer.hpp>
|
||||
#include <uORB/PublicationMulti.hpp>
|
||||
#include <uORB/topics/sensor_baro.h>
|
||||
|
||||
static constexpr uint8_t WHO_AM_I = 0x0F;
|
||||
static constexpr uint8_t LPS22HB_ID_WHO_AM_I = 0xB1;
|
||||
@@ -92,7 +93,8 @@ public:
|
||||
void RunImpl();
|
||||
|
||||
private:
|
||||
PX4Barometer _px4_baro;
|
||||
uORB::PublicationMulti<sensor_baro_s> _sensor_baro_pub{ORB_ID(sensor_baro)};
|
||||
|
||||
device::Device *_interface;
|
||||
|
||||
bool _collect_phase{false};
|
||||
|
||||
@@ -40,6 +40,5 @@ px4_add_module(
|
||||
lps25h_i2c.cpp
|
||||
lps25h_spi.cpp
|
||||
DEPENDS
|
||||
drivers_barometer
|
||||
px4_work_queue
|
||||
)
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
|
||||
LPS25H::LPS25H(const I2CSPIDriverConfig &config, device::Device *interface) :
|
||||
I2CSPIDriver(config),
|
||||
_px4_barometer(interface->get_device_id()),
|
||||
_interface(interface),
|
||||
_sample_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": read")),
|
||||
_comms_errors(perf_alloc(PC_COUNT, MODULE_NAME": comms_errors"))
|
||||
@@ -162,19 +161,25 @@ int LPS25H::collect()
|
||||
return ret;
|
||||
}
|
||||
|
||||
_px4_barometer.set_error_count(perf_event_count(_comms_errors));
|
||||
|
||||
/* get measurements from the device */
|
||||
float temperature = 42.5f + (report.t / 480);
|
||||
_px4_barometer.set_temperature(temperature);
|
||||
|
||||
/* raw pressure */
|
||||
uint32_t raw = report.p_xl + (report.p_l << 8) + (report.p_h << 16);
|
||||
|
||||
/* Pressure and MSL in mBar */
|
||||
float pressure = raw / 4096.0f;
|
||||
float pressure_pa = pressure * 100.f;
|
||||
|
||||
_px4_barometer.update(timestamp_sample, pressure);
|
||||
// publish
|
||||
sensor_baro_s sensor_baro{};
|
||||
sensor_baro.timestamp_sample = timestamp_sample;
|
||||
sensor_baro.device_id = _interface->get_device_id();
|
||||
sensor_baro.pressure = pressure_pa;
|
||||
sensor_baro.temperature = temperature;
|
||||
sensor_baro.error_count = perf_event_count(_comms_errors);
|
||||
sensor_baro.timestamp = hrt_absolute_time();
|
||||
_sensor_baro_pub.publish(sensor_baro);
|
||||
|
||||
perf_end(_sample_perf);
|
||||
return PX4_OK;
|
||||
|
||||
@@ -43,7 +43,8 @@
|
||||
|
||||
#include <drivers/device/Device.hpp>
|
||||
#include <lib/perf/perf_counter.h>
|
||||
#include <lib/drivers/barometer/PX4Barometer.hpp>
|
||||
#include <uORB/PublicationMulti.hpp>
|
||||
#include <uORB/topics/sensor_baro.h>
|
||||
#include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
|
||||
#include <px4_platform_common/i2c_spi_buses.h>
|
||||
|
||||
@@ -176,7 +177,8 @@ private:
|
||||
int measure();
|
||||
int collect();
|
||||
|
||||
PX4Barometer _px4_barometer;
|
||||
uORB::PublicationMulti<sensor_baro_s> _sensor_baro_pub{ORB_ID(sensor_baro)};
|
||||
|
||||
device::Device *_interface;
|
||||
|
||||
unsigned _measure_interval{0};
|
||||
|
||||
@@ -40,6 +40,5 @@ px4_add_module(
|
||||
lps33hw_spi.cpp
|
||||
lps33hw_main.cpp
|
||||
DEPENDS
|
||||
drivers_barometer
|
||||
px4_work_queue
|
||||
)
|
||||
|
||||
@@ -49,7 +49,6 @@ static void getTwosComplement(T &raw, uint8_t length)
|
||||
|
||||
LPS33HW::LPS33HW(const I2CSPIDriverConfig &config, device::Device *interface) :
|
||||
I2CSPIDriver(config),
|
||||
_px4_barometer(interface->get_device_id()),
|
||||
_interface(interface),
|
||||
_sample_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": read")),
|
||||
_comms_errors(perf_alloc(PC_COUNT, MODULE_NAME": comm errors")),
|
||||
@@ -177,10 +176,17 @@ LPS33HW::RunImpl()
|
||||
int32_t Praw = (int32_t)data[1] | (data[2] << 8) | (data[3] << 16);
|
||||
getTwosComplement(Praw, 24);
|
||||
float pressure_hPa = Praw / 4096.f;
|
||||
float pressure_pa = pressure_hPa * 100.f;
|
||||
|
||||
_px4_barometer.set_error_count(perf_event_count(_comms_errors));
|
||||
_px4_barometer.set_temperature(temp);
|
||||
_px4_barometer.update(timestamp_sample, pressure_hPa); // hPascals -> Millibar
|
||||
// publish
|
||||
sensor_baro_s sensor_baro{};
|
||||
sensor_baro.timestamp_sample = timestamp_sample;
|
||||
sensor_baro.device_id = _interface->get_device_id();
|
||||
sensor_baro.pressure = pressure_pa;
|
||||
sensor_baro.temperature = temp;
|
||||
sensor_baro.error_count = perf_event_count(_comms_errors);
|
||||
sensor_baro.timestamp = hrt_absolute_time();
|
||||
_sensor_baro_pub.publish(sensor_baro);
|
||||
|
||||
perf_end(_sample_perf);
|
||||
ScheduleDelayed(1000000 / SAMPLE_RATE);
|
||||
|
||||
@@ -40,7 +40,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <drivers/device/Device.hpp>
|
||||
#include <lib/drivers/barometer/PX4Barometer.hpp>
|
||||
#include <uORB/PublicationMulti.hpp>
|
||||
#include <uORB/topics/sensor_baro.h>
|
||||
#include <lib/perf/perf_counter.h>
|
||||
#include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
|
||||
#include <px4_platform_common/i2c_spi_buses.h>
|
||||
@@ -82,7 +83,7 @@ private:
|
||||
|
||||
static constexpr uint32_t SAMPLE_RATE{75};
|
||||
|
||||
PX4Barometer _px4_barometer;
|
||||
uORB::PublicationMulti<sensor_baro_s> _sensor_baro_pub{ORB_ID(sensor_baro)};
|
||||
|
||||
device::Device *_interface;
|
||||
|
||||
|
||||
@@ -41,6 +41,5 @@ px4_add_module(
|
||||
MPC2520.cpp
|
||||
MPC2520.hpp
|
||||
DEPENDS
|
||||
drivers_barometer
|
||||
px4_work_queue
|
||||
)
|
||||
|
||||
@@ -44,8 +44,7 @@ static constexpr int32_t combine(uint8_t h, uint8_t m, uint8_t l)
|
||||
|
||||
MPC2520::MPC2520(const I2CSPIDriverConfig &config) :
|
||||
I2C(config),
|
||||
I2CSPIDriver(config),
|
||||
_px4_baro(get_device_id())
|
||||
I2CSPIDriver(config)
|
||||
{
|
||||
//_debug_enabled = true;
|
||||
}
|
||||
@@ -232,7 +231,6 @@ void MPC2520::RunImpl()
|
||||
static constexpr float kT = 7864320; // temperature 8 times oversampling
|
||||
float Traw_sc = static_cast<float>(Traw) / kT;
|
||||
float Tcomp = _prom.c0 * 0.5f + _prom.c1 * Traw_sc;
|
||||
_px4_baro.set_temperature(Tcomp);
|
||||
|
||||
int32_t Praw = (int32_t)(buffer.PSR_B2 << 16) | (int32_t)(buffer.PSR_B1 << 8) | (int32_t)buffer.PSR_B1;
|
||||
Praw = (Praw & 0x800000) ? (0xFF000000 | Praw) : Praw;
|
||||
@@ -244,9 +242,15 @@ void MPC2520::RunImpl()
|
||||
float Pcomp = _prom.c00 + Praw_sc * (_prom.c10 + Praw_sc * (_prom.c20 + Praw_sc * _prom.c30)) + Traw_sc * _prom.c01 +
|
||||
Traw_sc * Praw_sc * (_prom.c11 + Praw_sc * _prom.c21);
|
||||
|
||||
float pressure_mbar = Pcomp / 100.0f; // convert to millibar
|
||||
|
||||
_px4_baro.update(now, pressure_mbar);
|
||||
// publish
|
||||
sensor_baro_s sensor_baro{};
|
||||
sensor_baro.timestamp_sample = now;
|
||||
sensor_baro.device_id = get_device_id();
|
||||
sensor_baro.pressure = Pcomp;
|
||||
sensor_baro.temperature = Tcomp;
|
||||
sensor_baro.error_count = perf_event_count(_bad_transfer_perf) + perf_event_count(_bad_register_perf);
|
||||
sensor_baro.timestamp = hrt_absolute_time();
|
||||
_sensor_baro_pub.publish(sensor_baro);
|
||||
|
||||
success = true;
|
||||
|
||||
|
||||
@@ -37,7 +37,8 @@
|
||||
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <lib/drivers/device/i2c.h>
|
||||
#include <lib/drivers/barometer/PX4Barometer.hpp>
|
||||
#include <uORB/PublicationMulti.hpp>
|
||||
#include <uORB/topics/sensor_baro.h>
|
||||
#include <lib/perf/perf_counter.h>
|
||||
#include <px4_platform_common/i2c_spi_buses.h>
|
||||
|
||||
@@ -76,7 +77,7 @@ private:
|
||||
void RegisterWrite(Register reg, uint8_t value);
|
||||
void RegisterSetAndClearBits(Register reg, uint8_t setbits, uint8_t clearbits);
|
||||
|
||||
PX4Barometer _px4_baro;
|
||||
uORB::PublicationMulti<sensor_baro_s> _sensor_baro_pub{ORB_ID(sensor_baro)};
|
||||
|
||||
perf_counter_t _bad_register_perf{perf_alloc(PC_COUNT, MODULE_NAME": bad register")};
|
||||
perf_counter_t _bad_transfer_perf{perf_alloc(PC_COUNT, MODULE_NAME": bad transfer")};
|
||||
|
||||
@@ -40,6 +40,5 @@ px4_add_module(
|
||||
MPL3115A2.cpp
|
||||
mpl3115a2_main.cpp
|
||||
DEPENDS
|
||||
drivers_barometer
|
||||
px4_work_queue
|
||||
)
|
||||
|
||||
@@ -55,7 +55,6 @@
|
||||
MPL3115A2::MPL3115A2(const I2CSPIDriverConfig &config) :
|
||||
I2C(config),
|
||||
I2CSPIDriver(config),
|
||||
_px4_barometer(get_device_id()),
|
||||
_sample_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": read")),
|
||||
_measure_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": measure")),
|
||||
_comms_errors(perf_alloc(PC_COUNT, MODULE_NAME": com_err"))
|
||||
@@ -260,9 +259,15 @@ int MPL3115A2::collect()
|
||||
float T = (float) reading.temperature.b[1] + ((float)(reading.temperature.b[0]) / 16.0f);
|
||||
float P = (float)(reading.pressure.q >> 8) + ((float)(reading.pressure.b[0]) / 4.0f);
|
||||
|
||||
_px4_barometer.set_error_count(perf_event_count(_comms_errors));
|
||||
_px4_barometer.set_temperature(T);
|
||||
_px4_barometer.update(timestamp_sample, P / 100.0f);
|
||||
// publish
|
||||
sensor_baro_s sensor_baro{};
|
||||
sensor_baro.timestamp_sample = timestamp_sample;
|
||||
sensor_baro.device_id = get_device_id();
|
||||
sensor_baro.pressure = P;
|
||||
sensor_baro.temperature = T;
|
||||
sensor_baro.error_count = perf_event_count(_comms_errors);
|
||||
sensor_baro.timestamp = hrt_absolute_time();
|
||||
_sensor_baro_pub.publish(sensor_baro);
|
||||
|
||||
perf_end(_sample_perf);
|
||||
|
||||
|
||||
@@ -42,7 +42,8 @@
|
||||
#include <drivers/device/i2c.h>
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <lib/perf/perf_counter.h>
|
||||
#include <lib/drivers/barometer/PX4Barometer.hpp>
|
||||
#include <uORB/PublicationMulti.hpp>
|
||||
#include <uORB/topics/sensor_baro.h>
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
#include <px4_platform_common/defines.h>
|
||||
#include <px4_platform_common/log.h>
|
||||
@@ -76,7 +77,7 @@ private:
|
||||
int RegisterRead(uint8_t reg, void *data, unsigned count = 1);
|
||||
int RegisterWrite(uint8_t reg, uint8_t data);
|
||||
|
||||
PX4Barometer _px4_barometer;
|
||||
uORB::PublicationMulti<sensor_baro_s> _sensor_baro_pub{ORB_ID(sensor_baro)};
|
||||
|
||||
bool _collect_phase{false};
|
||||
|
||||
|
||||
@@ -44,6 +44,5 @@ px4_add_module(
|
||||
DEPENDS
|
||||
cdev
|
||||
drivers__device
|
||||
drivers_barometer
|
||||
px4_work_queue
|
||||
)
|
||||
|
||||
@@ -34,7 +34,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <drivers/device/device.h>
|
||||
#include <lib/drivers/barometer/PX4Barometer.hpp>
|
||||
#include <uORB/PublicationMulti.hpp>
|
||||
#include <uORB/topics/sensor_baro.h>
|
||||
#include <lib/perf/perf_counter.h>
|
||||
#include <px4_platform_common/i2c_spi_buses.h>
|
||||
#include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
|
||||
@@ -113,7 +114,7 @@ public:
|
||||
protected:
|
||||
void print_status() override;
|
||||
|
||||
PX4Barometer _px4_barometer;
|
||||
uORB::PublicationMulti<sensor_baro_s> _sensor_baro_pub{ORB_ID(sensor_baro)};
|
||||
|
||||
device::Device *_interface;
|
||||
|
||||
@@ -127,6 +128,11 @@ protected:
|
||||
int64_t _OFF{0};
|
||||
int64_t _SENS{0};
|
||||
|
||||
bool _initialized{false};
|
||||
|
||||
float _last_pressure{NAN};
|
||||
float _last_temperature{NAN};
|
||||
|
||||
perf_counter_t _sample_perf;
|
||||
perf_counter_t _measure_perf;
|
||||
perf_counter_t _comms_errors;
|
||||
|
||||
@@ -43,7 +43,6 @@
|
||||
|
||||
MS5611::MS5611(device::Device *interface, ms5611::prom_u &prom_buf, const I2CSPIDriverConfig &config) :
|
||||
I2CSPIDriver(config),
|
||||
_px4_barometer(interface->get_device_id()),
|
||||
_interface(interface),
|
||||
_prom(prom_buf.s),
|
||||
_sample_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": read")),
|
||||
@@ -108,15 +107,13 @@ MS5611::init()
|
||||
}
|
||||
|
||||
/* state machine will have generated a report, copy it out */
|
||||
const sensor_baro_s &brp = _px4_barometer.get();
|
||||
|
||||
if (_device_type == MS5607_DEVICE) {
|
||||
if (brp.pressure < 520.0f) {
|
||||
if (_last_pressure < 52'000.f) {
|
||||
/* This is likely not this device, abort */
|
||||
ret = -EINVAL;
|
||||
break;
|
||||
|
||||
} else if (brp.pressure > 1500.0f) {
|
||||
} else if (_last_pressure > 150'000.f) {
|
||||
/* This is likely not this device, abort */
|
||||
ret = -EINVAL;
|
||||
break;
|
||||
@@ -129,12 +126,10 @@ MS5611::init()
|
||||
/* fall through */
|
||||
case MS5611_DEVICE:
|
||||
_interface->set_device_type(DRV_BARO_DEVTYPE_MS5611);
|
||||
_px4_barometer.set_device_type(DRV_BARO_DEVTYPE_MS5611);
|
||||
break;
|
||||
|
||||
case MS5607_DEVICE:
|
||||
_interface->set_device_type(DRV_BARO_DEVTYPE_MS5607);
|
||||
_px4_barometer.set_device_type(DRV_BARO_DEVTYPE_MS5607);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -144,6 +139,7 @@ MS5611::init()
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
_initialized = true;
|
||||
start();
|
||||
}
|
||||
|
||||
@@ -235,8 +231,6 @@ MS5611::measure()
|
||||
perf_count(_comms_errors);
|
||||
}
|
||||
|
||||
_px4_barometer.set_error_count(perf_event_count(_comms_errors));
|
||||
|
||||
perf_end(_measure_perf);
|
||||
|
||||
return ret;
|
||||
@@ -321,16 +315,26 @@ MS5611::collect()
|
||||
}
|
||||
}
|
||||
|
||||
float temperature = TEMP / 100.0f;
|
||||
_px4_barometer.set_temperature(temperature);
|
||||
_last_temperature = TEMP / 100.0f;
|
||||
|
||||
} else {
|
||||
/* pressure calculation, result in Pa */
|
||||
int32_t P = (((raw * _SENS) >> 21) - _OFF) >> 15;
|
||||
|
||||
float pressure = P / 100.0f; /* convert to millibar */
|
||||
_last_pressure = P;
|
||||
|
||||
// publish
|
||||
if (_initialized && PX4_ISFINITE(_last_pressure) && PX4_ISFINITE(_last_temperature)) {
|
||||
sensor_baro_s sensor_baro{};
|
||||
sensor_baro.timestamp_sample = timestamp_sample;
|
||||
sensor_baro.device_id = _interface->get_device_id();
|
||||
sensor_baro.pressure = P;
|
||||
sensor_baro.temperature = _last_temperature;
|
||||
sensor_baro.error_count = perf_event_count(_comms_errors);
|
||||
sensor_baro.timestamp = hrt_absolute_time();
|
||||
_sensor_baro_pub.publish(sensor_baro);
|
||||
}
|
||||
|
||||
_px4_barometer.update(timestamp_sample, pressure);
|
||||
}
|
||||
|
||||
/* update the measurement state machine */
|
||||
|
||||
@@ -41,6 +41,5 @@ px4_add_module(
|
||||
MS5837.cpp
|
||||
MS5837.hpp
|
||||
DEPENDS
|
||||
drivers_barometer
|
||||
px4_work_queue
|
||||
)
|
||||
|
||||
@@ -41,7 +41,6 @@
|
||||
MS5837::MS5837(const I2CSPIDriverConfig &config) :
|
||||
I2C(config),
|
||||
I2CSPIDriver(config),
|
||||
_px4_barometer(get_device_id()),
|
||||
_sample_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": read")),
|
||||
_measure_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": measure")),
|
||||
_comms_errors(perf_alloc(PC_COUNT, MODULE_NAME": com_err"))
|
||||
@@ -96,7 +95,7 @@ int MS5837::init()
|
||||
break;
|
||||
}
|
||||
|
||||
_px4_barometer.set_device_type(DRV_BARO_DEVTYPE_MS5837);
|
||||
set_device_type(DRV_BARO_DEVTYPE_MS5837);
|
||||
|
||||
ret = OK;
|
||||
|
||||
@@ -259,8 +258,6 @@ int MS5837::_measure()
|
||||
perf_count(_comms_errors);
|
||||
}
|
||||
|
||||
_px4_barometer.set_error_count(perf_event_count(_comms_errors));
|
||||
|
||||
perf_end(_measure_perf);
|
||||
|
||||
return ret;
|
||||
@@ -331,17 +328,22 @@ int MS5837::_collect()
|
||||
_OFF -= OFF2;
|
||||
_SENS -= SENS2;
|
||||
|
||||
|
||||
float temperature = TEMP / 100.0f;
|
||||
_px4_barometer.set_temperature(temperature);
|
||||
_last_temperature = TEMP / 100.0f;
|
||||
|
||||
} else {
|
||||
/* pressure calculation, result in Pa */
|
||||
int32_t P = (((raw * _SENS) >> 21) - _OFF) >> 13;
|
||||
|
||||
float pressure = P / 10.0f; /* convert to millibar */
|
||||
|
||||
_px4_barometer.update(timestamp_sample, pressure);
|
||||
// publish
|
||||
sensor_baro_s sensor_baro{};
|
||||
sensor_baro.timestamp_sample = timestamp_sample;
|
||||
sensor_baro.device_id = get_device_id();
|
||||
sensor_baro.pressure = P;
|
||||
sensor_baro.temperature = T;
|
||||
sensor_baro.error_count = perf_event_count(_comms_errors);
|
||||
sensor_baro.timestamp = hrt_absolute_time();
|
||||
_sensor_baro_pub.publish(sensor_baro);
|
||||
}
|
||||
|
||||
/* update the measurement state machine */
|
||||
@@ -357,9 +359,6 @@ void MS5837::print_status()
|
||||
I2CSPIDriverBase::print_status();
|
||||
perf_print_counter(_sample_perf);
|
||||
perf_print_counter(_comms_errors);
|
||||
|
||||
printf("pressure: %f\n", (double)_px4_barometer.get().pressure);
|
||||
printf("temperature: %f\n", (double)_px4_barometer.get().temperature);
|
||||
}
|
||||
|
||||
int MS5837::_read_prom()
|
||||
|
||||
@@ -35,7 +35,8 @@
|
||||
|
||||
#include <drivers/device/device.h>
|
||||
#include <drivers/device/i2c.h>
|
||||
#include <lib/drivers/barometer/PX4Barometer.hpp>
|
||||
#include <uORB/PublicationMulti.hpp>
|
||||
#include <uORB/topics/sensor_baro.h>
|
||||
#include <lib/perf/perf_counter.h>
|
||||
#include <px4_platform_common/i2c_spi_buses.h>
|
||||
#include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
|
||||
@@ -79,7 +80,7 @@ public:
|
||||
private:
|
||||
int probe() override;
|
||||
|
||||
PX4Barometer _px4_barometer;
|
||||
uORB::PublicationMulti<sensor_baro_s> _sensor_baro_pub{ORB_ID(sensor_baro)};
|
||||
|
||||
ms5837::prom_u _prom{};
|
||||
|
||||
@@ -90,6 +91,8 @@ private:
|
||||
int64_t _OFF{0};
|
||||
int64_t _SENS{0};
|
||||
|
||||
float _last_temperature{NAN};
|
||||
|
||||
perf_counter_t _sample_perf;
|
||||
perf_counter_t _measure_perf;
|
||||
perf_counter_t _comms_errors;
|
||||
|
||||
@@ -39,6 +39,5 @@ px4_add_module(
|
||||
tcbp001ta_spi.cpp
|
||||
tcbp001ta_main.cpp
|
||||
DEPENDS
|
||||
drivers_barometer
|
||||
px4_work_queue
|
||||
)
|
||||
|
||||
@@ -45,13 +45,11 @@
|
||||
|
||||
TCBP001TA::TCBP001TA(tcbp001ta::ITCBP001TA *interface) :
|
||||
ScheduledWorkItem(MODULE_NAME, px4::device_bus_to_wq(interface->get_device_id())),
|
||||
_px4_baro(interface->get_device_id()),
|
||||
_interface(interface),
|
||||
_sample_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": sample")),
|
||||
_measure_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": measure")),
|
||||
_comms_errors(perf_alloc(PC_COUNT, MODULE_NAME": comms errors"))
|
||||
{
|
||||
_px4_baro.set_device_type(DRV_BARO_DEVTYPE_TCBP001TA);
|
||||
}
|
||||
|
||||
TCBP001TA::~TCBP001TA()
|
||||
@@ -252,12 +250,15 @@ TCBP001TA::collect()
|
||||
Praw_sc * _fcal.c01 +
|
||||
Praw_sc * Praw_sc * (_fcal.c11 + Praw_sc * _fcal.c21);
|
||||
|
||||
_px4_baro.set_error_count(perf_event_count(_comms_errors));
|
||||
_px4_baro.set_temperature(T);
|
||||
|
||||
float pressure = P / 100.0f; // to mbar
|
||||
// PX4_INFO("press %f", double(pressure));
|
||||
_px4_baro.update(timestamp_sample, pressure);
|
||||
// publish
|
||||
sensor_baro_s sensor_baro{};
|
||||
sensor_baro.timestamp_sample = timestamp_sample;
|
||||
sensor_baro.device_id = _interface->get_device_id();
|
||||
sensor_baro.pressure = P;
|
||||
sensor_baro.temperature = T;
|
||||
sensor_baro.error_count = perf_event_count(_comms_errors);
|
||||
sensor_baro.timestamp = hrt_absolute_time();
|
||||
_sensor_baro_pub.publish(sensor_baro);
|
||||
|
||||
perf_end(_sample_perf);
|
||||
|
||||
@@ -270,8 +271,6 @@ TCBP001TA::print_info()
|
||||
perf_print_counter(_sample_perf);
|
||||
perf_print_counter(_measure_perf);
|
||||
perf_print_counter(_comms_errors);
|
||||
|
||||
_px4_baro.print_status();
|
||||
}
|
||||
|
||||
uint32_t
|
||||
|
||||
@@ -38,7 +38,8 @@
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
#include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
|
||||
#include <lib/drivers/barometer/PX4Barometer.hpp>
|
||||
#include <uORB/PublicationMulti.hpp>
|
||||
#include <uORB/topics/sensor_baro.h>
|
||||
#include <lib/perf/perf_counter.h>
|
||||
|
||||
class TCBP001TA : public px4::ScheduledWorkItem
|
||||
@@ -63,7 +64,7 @@ private:
|
||||
int measure(); //start measure
|
||||
int collect(); //get results and publish
|
||||
|
||||
PX4Barometer _px4_baro;
|
||||
uORB::PublicationMulti<sensor_baro_s> _sensor_baro_pub{ORB_ID(sensor_baro)};
|
||||
|
||||
tcbp001ta::ITCBP001TA *_interface;
|
||||
|
||||
|
||||
@@ -93,6 +93,7 @@ tcbp001ta_spi_interface(uint8_t busnum, uint32_t device)
|
||||
TCBP001TA_SPI::TCBP001TA_SPI(uint8_t bus, uint32_t device) :
|
||||
SPI("TCBP001TA_SPI", nullptr, bus, device, SPIDEV_MODE3, 10 * 1000 * 1000)
|
||||
{
|
||||
set_device_type(DRV_BARO_DEVTYPE_TCBP001TA);
|
||||
}
|
||||
|
||||
uint8_t
|
||||
|
||||
@@ -100,7 +100,6 @@ ADIS16448::ADIS16448(const I2CSPIDriverConfig &config) :
|
||||
I2CSPIDriver(config),
|
||||
_drdy_gpio(config.drdy_gpio), // TODO: DRDY disabled
|
||||
_px4_accel(get_device_id(), config.rotation),
|
||||
_px4_baro(get_device_id()),
|
||||
_px4_gyro(get_device_id(), config.rotation),
|
||||
_px4_mag(get_device_id(), config.rotation)
|
||||
{
|
||||
@@ -445,11 +444,18 @@ void ADIS16448::RunImpl()
|
||||
const int16_t mag_z = (buffer.ZMAGN_OUT == INT16_MIN) ? INT16_MAX : -buffer.ZMAGN_OUT;
|
||||
_px4_mag.update(timestamp_sample, mag_x, mag_y, mag_z);
|
||||
|
||||
_px4_baro.set_error_count(error_count);
|
||||
_px4_baro.set_temperature(temperature);
|
||||
|
||||
float pressure_pa = buffer.BARO_OUT * 0.02f; // 20 μbar per LSB
|
||||
_px4_baro.update(timestamp_sample, pressure_pa);
|
||||
|
||||
// publish baro
|
||||
sensor_baro_s sensor_baro{};
|
||||
sensor_baro.timestamp_sample = timestamp_sample;
|
||||
sensor_baro.device_id = get_device_id();
|
||||
sensor_baro.pressure = pressure_pa;
|
||||
sensor_baro.temperature = temperature;
|
||||
sensor_baro.error_count = error_count;
|
||||
sensor_baro.timestamp = hrt_absolute_time();
|
||||
_sensor_baro_pub.publish(sensor_baro);
|
||||
}
|
||||
|
||||
success = true;
|
||||
|
||||
@@ -45,9 +45,10 @@
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <lib/drivers/device/spi.h>
|
||||
#include <lib/drivers/accelerometer/PX4Accelerometer.hpp>
|
||||
#include <lib/drivers/barometer/PX4Barometer.hpp>
|
||||
#include <lib/drivers/gyroscope/PX4Gyroscope.hpp>
|
||||
#include <lib/drivers/magnetometer/PX4Magnetometer.hpp>
|
||||
#include <uORB/PublicationMulti.hpp>
|
||||
#include <uORB/topics/sensor_baro.h>
|
||||
#include <lib/geo/geo.h>
|
||||
#include <lib/perf/perf_counter.h>
|
||||
#include <px4_platform_common/atomic.h>
|
||||
@@ -98,10 +99,11 @@ private:
|
||||
const spi_drdy_gpio_t _drdy_gpio;
|
||||
|
||||
PX4Accelerometer _px4_accel;
|
||||
PX4Barometer _px4_baro;
|
||||
PX4Gyroscope _px4_gyro;
|
||||
PX4Magnetometer _px4_mag;
|
||||
|
||||
uORB::PublicationMulti<sensor_baro_s> _sensor_baro_pub{ORB_ID(sensor_baro)};
|
||||
|
||||
perf_counter_t _reset_perf{perf_alloc(PC_COUNT, MODULE_NAME": reset")};
|
||||
perf_counter_t _bad_register_perf{perf_alloc(PC_COUNT, MODULE_NAME": bad register")};
|
||||
perf_counter_t _bad_transfer_perf{perf_alloc(PC_COUNT, MODULE_NAME": bad transfer")};
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user