mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-23 03:33:34 +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:
@@ -65,7 +65,6 @@ px4_add_module(
|
||||
conversion
|
||||
geo
|
||||
drivers_accelerometer
|
||||
drivers_barometer
|
||||
drivers_gyroscope
|
||||
drivers_magnetometer
|
||||
)
|
||||
|
||||
@@ -39,7 +39,6 @@ px4_add_module(
|
||||
SensorBaroSim.cpp
|
||||
SensorBaroSim.hpp
|
||||
DEPENDS
|
||||
drivers_barometer
|
||||
geo
|
||||
px4_work_queue
|
||||
)
|
||||
|
||||
@@ -161,8 +161,15 @@ void SensorBaroSim::Run()
|
||||
// calculate temperature in Celsius
|
||||
float temperature = temperature_local - 273.0f + _sim_baro_off_t.get();
|
||||
|
||||
_px4_baro.set_temperature(temperature);
|
||||
_px4_baro.update(gpos.timestamp, pressure);
|
||||
// publish
|
||||
sensor_baro_s sensor_baro{};
|
||||
sensor_baro.timestamp_sample = gpos.timestamp;
|
||||
sensor_baro.device_id = 6620172; // 6620172: DRV_BARO_DEVTYPE_BAROSIM, BUS: 1, ADDR: 4, TYPE: SIMULATION
|
||||
sensor_baro.pressure = pressure;
|
||||
sensor_baro.temperature = temperature;
|
||||
sensor_baro.timestamp = hrt_absolute_time();
|
||||
_sensor_baro_pub.publish(sensor_baro);
|
||||
|
||||
|
||||
_last_update_time = gpos.timestamp;
|
||||
}
|
||||
|
||||
@@ -33,16 +33,17 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <lib/drivers/barometer/PX4Barometer.hpp>
|
||||
#include <lib/perf/perf_counter.h>
|
||||
#include <px4_platform_common/defines.h>
|
||||
#include <px4_platform_common/module.h>
|
||||
#include <px4_platform_common/module_params.h>
|
||||
#include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/PublicationMulti.hpp>
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/SubscriptionInterval.hpp>
|
||||
#include <uORB/topics/parameter_update.h>
|
||||
#include <uORB/topics/sensor_baro.h>
|
||||
#include <uORB/topics/vehicle_global_position.h>
|
||||
|
||||
using namespace time_literals;
|
||||
@@ -80,12 +81,12 @@ private:
|
||||
|
||||
hrt_abstime _last_update_time{0};
|
||||
|
||||
PX4Barometer _px4_baro{6620172}; // 6620172: DRV_BARO_DEVTYPE_BAROSIM, BUS: 1, ADDR: 4, TYPE: SIMULATION
|
||||
uORB::PublicationMulti<sensor_baro_s> _sensor_baro_pub{ORB_ID(sensor_baro)};
|
||||
|
||||
perf_counter_t _loop_perf{perf_alloc(PC_ELAPSED, MODULE_NAME": cycle")};
|
||||
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamFloat<px4::params::SIM_BARO_OFF_P>) _sim_baro_off_p,
|
||||
(ParamFloat<px4::params::SIM_BARO_OFF_P>) _sim_baro_off_t
|
||||
(ParamFloat<px4::params::SIM_BARO_OFF_T>) _sim_baro_off_t
|
||||
)
|
||||
};
|
||||
|
||||
@@ -42,5 +42,6 @@ PARAM_DEFINE_FLOAT(SIM_BARO_OFF_P, 0.0f);
|
||||
* simulated barometer temperature offset
|
||||
*
|
||||
* @group Simulator
|
||||
* @unit celcius
|
||||
*/
|
||||
PARAM_DEFINE_FLOAT(SIM_BARO_OFF_T, 0.0f);
|
||||
|
||||
@@ -44,7 +44,6 @@
|
||||
|
||||
#include <drivers/drv_hrt.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 <lib/geo/geo.h>
|
||||
@@ -64,6 +63,7 @@
|
||||
#include <uORB/topics/manual_control_setpoint.h>
|
||||
#include <uORB/topics/optical_flow.h>
|
||||
#include <uORB/topics/parameter_update.h>
|
||||
#include <uORB/topics/sensor_baro.h>
|
||||
#include <uORB/topics/sensor_gps.h>
|
||||
#include <uORB/topics/vehicle_angular_velocity.h>
|
||||
#include <uORB/topics/vehicle_attitude.h>
|
||||
@@ -179,8 +179,7 @@ private:
|
||||
PX4Magnetometer _px4_mag_0{197388, ROTATION_NONE}; // 197388: DRV_MAG_DEVTYPE_MAGSIM, BUS: 1, ADDR: 1, TYPE: SIMULATION
|
||||
PX4Magnetometer _px4_mag_1{197644, ROTATION_NONE}; // 197644: DRV_MAG_DEVTYPE_MAGSIM, BUS: 2, ADDR: 1, TYPE: SIMULATION
|
||||
|
||||
PX4Barometer _px4_baro_0{6620172}; // 6620172: DRV_BARO_DEVTYPE_BAROSIM, BUS: 1, ADDR: 4, TYPE: SIMULATION
|
||||
PX4Barometer _px4_baro_1{6620428}; // 6620428: DRV_BARO_DEVTYPE_BAROSIM, BUS: 2, ADDR: 4, TYPE: SIMULATION
|
||||
uORB::PublicationMulti<sensor_baro_s> _sensor_baro_pubs[2] {{ORB_ID(sensor_baro)}, {ORB_ID(sensor_baro)}};
|
||||
|
||||
float _sensors_temperature{0};
|
||||
|
||||
@@ -291,6 +290,9 @@ private:
|
||||
float _last_magz{0.0f};
|
||||
bool _use_dynamic_mixing{false};
|
||||
|
||||
float _last_baro_pressure{0.0f};
|
||||
float _last_baro_temperature{0.0f};
|
||||
|
||||
#if defined(ENABLE_LOCKSTEP_SCHEDULER)
|
||||
px4::atomic<bool> _has_initialized {false};
|
||||
#endif
|
||||
|
||||
@@ -326,18 +326,27 @@ void Simulator::update_sensors(const hrt_abstime &time, const mavlink_hil_sensor
|
||||
|
||||
// baro
|
||||
if ((sensors.fields_updated & SensorSource::BARO) == SensorSource::BARO && !_baro_blocked) {
|
||||
if (_baro_stuck) {
|
||||
_px4_baro_0.update(time, _px4_baro_0.get().pressure);
|
||||
_px4_baro_0.set_temperature(_px4_baro_0.get().temperature);
|
||||
_px4_baro_1.update(time, _px4_baro_1.get().pressure);
|
||||
_px4_baro_1.set_temperature(_px4_baro_1.get().temperature);
|
||||
|
||||
} else {
|
||||
_px4_baro_0.update(time, sensors.abs_pressure);
|
||||
_px4_baro_0.set_temperature(sensors.temperature);
|
||||
_px4_baro_1.update(time, sensors.abs_pressure);
|
||||
_px4_baro_1.set_temperature(sensors.temperature);
|
||||
if (!_baro_stuck) {
|
||||
_last_baro_pressure = sensors.abs_pressure;
|
||||
_last_baro_temperature = sensors.temperature;
|
||||
}
|
||||
|
||||
// publish
|
||||
sensor_baro_s sensor_baro{};
|
||||
sensor_baro.timestamp_sample = time;
|
||||
sensor_baro.pressure = _last_baro_pressure;
|
||||
sensor_baro.temperature = _last_baro_temperature;
|
||||
|
||||
// publish 1st baro
|
||||
sensor_baro.device_id = 6620172; // 6620172: DRV_BARO_DEVTYPE_BAROSIM, BUS: 1, ADDR: 4, TYPE: SIMULATION
|
||||
sensor_baro.timestamp = hrt_absolute_time();
|
||||
_sensor_baro_pubs[0].publish(sensor_baro);
|
||||
|
||||
// publish 2nd baro
|
||||
sensor_baro.device_id = 6620428; // 6620428: DRV_BARO_DEVTYPE_BAROSIM, BUS: 2, ADDR: 4, TYPE: SIMULATION
|
||||
sensor_baro.timestamp = hrt_absolute_time();
|
||||
_sensor_baro_pubs[1].publish(sensor_baro);
|
||||
}
|
||||
|
||||
// differential pressure
|
||||
|
||||
Reference in New Issue
Block a user