From fda4ce96b170b3f58d986a53f4c2f71a237a51f4 Mon Sep 17 00:00:00 2001 From: Christophe De Wagter Date: Mon, 25 Sep 2023 11:30:27 +0200 Subject: [PATCH] [ms45xx] Harmonize airspeed, send pressure to air_data and downlink via telemetry (#3098) * [fix] Airspeed data different from airspeed state * Update conf/modules/airspeed_ms45xx_i2c.xml * [ms45xx] do not set state_speed but send to , downlink now via telemetry.xml (no more sync send) --- conf/airframes/ENAC/cyfoam.xml | 3 +- .../ENAC/fixed-wing/zagi_mekf_wind.xml | 1 - .../OPENUAS/openuas_df_mini_spirit.xml | 2 +- conf/airframes/OPENUAS/openuas_eflite_t28.xml | 2 +- .../OPENUAS/openuas_multiplex_minimag.xml | 2 +- .../OPENUAS/openuas_multiplex_twinstar_nd.xml | 2 +- conf/airframes/OPENUAS/openuas_own_flexo.xml | 2 +- .../airframes/OPENUAS/openuas_own_sumo_ii.xml | 2 +- .../OPENUAS/openuas_parrot_disco.xml | 2 +- conf/airframes/tudelft/cyfoam.xml | 3 +- .../tudelft/disco_rotorcraft_indi.xml | 2 -- conf/modules/air_data.xml | 2 +- conf/modules/airspeed_ms45xx_i2c.xml | 10 +++--- sw/airborne/boards/disco.h | 1 - .../modules/sensors/airspeed_ms45xx_i2c.c | 31 +++---------------- .../modules/sensors/airspeed_ms45xx_i2c.h | 2 -- 16 files changed, 18 insertions(+), 51 deletions(-) diff --git a/conf/airframes/ENAC/cyfoam.xml b/conf/airframes/ENAC/cyfoam.xml index 3bb1e2bca8..c2d19942dc 100644 --- a/conf/airframes/ENAC/cyfoam.xml +++ b/conf/airframes/ENAC/cyfoam.xml @@ -130,8 +130,7 @@ - - + diff --git a/conf/airframes/ENAC/fixed-wing/zagi_mekf_wind.xml b/conf/airframes/ENAC/fixed-wing/zagi_mekf_wind.xml index f88fc8002a..c78d28501c 100644 --- a/conf/airframes/ENAC/fixed-wing/zagi_mekf_wind.xml +++ b/conf/airframes/ENAC/fixed-wing/zagi_mekf_wind.xml @@ -83,7 +83,6 @@ - diff --git a/conf/airframes/OPENUAS/openuas_df_mini_spirit.xml b/conf/airframes/OPENUAS/openuas_df_mini_spirit.xml index 508cd0dad7..e86b22d0d9 100644 --- a/conf/airframes/OPENUAS/openuas_df_mini_spirit.xml +++ b/conf/airframes/OPENUAS/openuas_df_mini_spirit.xml @@ -185,7 +185,7 @@ (differential) pressure sensor module publishing the BARO_DIFF ABI message. Make sure to disable other modules which otherwise directly set the airspeed in the state interface. E.g. when using the airspeed_ms45xx.xml module, - define USE_AIRSPEED or USE_AIRSPEED_MS45XX to FALSE only when Airdata is set to TRUE + define USE_AIRSPEED to FALSE only when Airdata is set to TRUE Sometimes one just wants to measure, and not yet use the airspeed in a final navigational solution then also set it to FALSE --> diff --git a/conf/airframes/OPENUAS/openuas_eflite_t28.xml b/conf/airframes/OPENUAS/openuas_eflite_t28.xml index c53cec60bb..48682bb1c4 100644 --- a/conf/airframes/OPENUAS/openuas_eflite_t28.xml +++ b/conf/airframes/OPENUAS/openuas_eflite_t28.xml @@ -243,7 +243,7 @@ NOTES: (differential) pressure sensor module publishing the BARO_DIFF ABI message. Make sure to disable other modules which otherwise directly set the airspeed in the state interface. E.g. when using the airspeed_ms45xx.xml module, - define USE_AIRSPEED or USE_AIRSPEED_MS45XX to FALSE only when Airdata is set to TRUE + define USE_AIRSPEED to FALSE only when Airdata is set to TRUE Sometimes one just wants to measure, and not yet use the airspeed in a final navigational solution then also set it to FALSE --> diff --git a/conf/airframes/OPENUAS/openuas_multiplex_minimag.xml b/conf/airframes/OPENUAS/openuas_multiplex_minimag.xml index e402e8e525..3267774486 100644 --- a/conf/airframes/OPENUAS/openuas_multiplex_minimag.xml +++ b/conf/airframes/OPENUAS/openuas_multiplex_minimag.xml @@ -257,7 +257,7 @@ NOTES: (differential) pressure sensor module publishing the BARO_DIFF ABI message. Make sure to disable other modules which otherwise directly set the airspeed in the state interface. E.g. when using the airspeed_ms45xx.xml module, - define USE_AIRSPEED or USE_AIRSPEED_MS45XX to FALSE only when Airdata is set to TRUE + define USE_AIRSPEED to FALSE only when Airdata is set to TRUE Sometimes one just wants to measure, and not yet use the airspeed in a final navigational solution then also set it to FALSE --> diff --git a/conf/airframes/OPENUAS/openuas_multiplex_twinstar_nd.xml b/conf/airframes/OPENUAS/openuas_multiplex_twinstar_nd.xml index cf4b28eddb..6bd6c028d2 100644 --- a/conf/airframes/OPENUAS/openuas_multiplex_twinstar_nd.xml +++ b/conf/airframes/OPENUAS/openuas_multiplex_twinstar_nd.xml @@ -187,7 +187,7 @@ NOTES: (differential) pressure sensor module publishing the BARO_DIFF ABI message. Make sure to disable other modules which otherwise directly set the airspeed in the state interface. E.g. when using the airspeed_ms45xx.xml module, - define USE_AIRSPEED or USE_AIRSPEED_MS45XX to FALSE only when Airdata is set to TRUE + define USE_AIRSPEED to FALSE only when Airdata is set to TRUE Sometimes one just wants to measure, and not yet use the airspeed in a final navigational solution then also set it to FALSE --> diff --git a/conf/airframes/OPENUAS/openuas_own_flexo.xml b/conf/airframes/OPENUAS/openuas_own_flexo.xml index 7c703abe19..2ad141766d 100644 --- a/conf/airframes/OPENUAS/openuas_own_flexo.xml +++ b/conf/airframes/OPENUAS/openuas_own_flexo.xml @@ -220,7 +220,7 @@ NOTES: (differential) pressure sensor module publishing the BARO_DIFF ABI message. Make sure to disable other modules which otherwise directly set the airspeed in the state interface. E.g. when using the airspeed_ms45xx.xml module, - define USE_AIRSPEED or USE_AIRSPEED_MS45XX to FALSE only when Airdata is set to TRUE + define USE_AIRSPEED to FALSE only when Airdata is set to TRUE Sometimes one just wants to measure, and not yet use the airspeed in a final navigational solution then also set it to FALSE --> diff --git a/conf/airframes/OPENUAS/openuas_own_sumo_ii.xml b/conf/airframes/OPENUAS/openuas_own_sumo_ii.xml index e45428562e..a7bea79715 100644 --- a/conf/airframes/OPENUAS/openuas_own_sumo_ii.xml +++ b/conf/airframes/OPENUAS/openuas_own_sumo_ii.xml @@ -222,7 +222,7 @@ NOTES: (differential) pressure sensor module publishing the BARO_DIFF ABI message. Make sure to disable other modules which otherwise directly set the airspeed in the state interface. E.g. when using the airspeed_ms45xx.xml module, - define USE_AIRSPEED or USE_AIRSPEED_MS45XX to FALSE only when Airdata is set to TRUE + define USE_AIRSPEED to FALSE only when Airdata is set to TRUE Sometimes one just wants to measure, and not yet use the airspeed in a final navigational solution then also set it to FALSE --> diff --git a/conf/airframes/OPENUAS/openuas_parrot_disco.xml b/conf/airframes/OPENUAS/openuas_parrot_disco.xml index dda9a4bf41..35e9f797d8 100644 --- a/conf/airframes/OPENUAS/openuas_parrot_disco.xml +++ b/conf/airframes/OPENUAS/openuas_parrot_disco.xml @@ -255,7 +255,7 @@ (differential) pressure sensor module publishing the BARO_DIFF ABI message. Make sure to disable other modules which otherwise directly set the airspeed in the state interface. E.g. when using the airspeed_ms45xx.xml module, - define USE_AIRSPEED or USE_AIRSPEED_MS45XX to FALSE only when Airdata is set to TRUE + define USE_AIRSPEED to FALSE only when Airdata is set to TRUE Sometimes one just wants to measure, and not yet use the airspeed in a final navigational solution then also set it to FALSE --> diff --git a/conf/airframes/tudelft/cyfoam.xml b/conf/airframes/tudelft/cyfoam.xml index dd70fdc532..91b61451e5 100644 --- a/conf/airframes/tudelft/cyfoam.xml +++ b/conf/airframes/tudelft/cyfoam.xml @@ -233,8 +233,7 @@ - - + diff --git a/conf/airframes/tudelft/disco_rotorcraft_indi.xml b/conf/airframes/tudelft/disco_rotorcraft_indi.xml index c6b1c14359..8580151d8e 100644 --- a/conf/airframes/tudelft/disco_rotorcraft_indi.xml +++ b/conf/airframes/tudelft/disco_rotorcraft_indi.xml @@ -18,8 +18,6 @@ - - diff --git a/conf/modules/air_data.xml b/conf/modules/air_data.xml index 529f34a6a3..4d97b7c36d 100644 --- a/conf/modules/air_data.xml +++ b/conf/modules/air_data.xml @@ -8,7 +8,7 @@ Subscribes to BARO_ABS, BARO_DIFF and TEMPERATURE ABI messages and calculates QNH and true airspeed from it. Also enables you to fly on "flight levels" using AMSL (AltitudeAboveSeaLevel) calculated from current pressure and QNH. - When using this module to provide airspeed you need a differential pressure sensor module publishing the BARO_DIFF ABI message. Make sure to disable other modules which otherwise directly set the airspeed in the state interface. E.g. when using the airspeed_ms45xx.xml module, define USE_AIRSPEED_MS45XX to FALSE. + When using this module to provide airspeed you need a differential pressure sensor module publishing the BARO_DIFF ABI message. Make sure to disable other modules which otherwise directly set the airspeed in the state interface. diff --git a/conf/modules/airspeed_ms45xx_i2c.xml b/conf/modules/airspeed_ms45xx_i2c.xml index 09b8923414..fe0dca0b84 100644 --- a/conf/modules/airspeed_ms45xx_i2c.xml +++ b/conf/modules/airspeed_ms45xx_i2c.xml @@ -6,29 +6,27 @@ MS45XX differential or gauge type of pressure sensor for e.g measuring airspeed. This sensor module is using the MS45xxDO digital pressure sensor with readings via I2C. Needs to be a versions with 14bit pressure and 11bit temperature data output. + + If the airspeed reading is badly calibrated, use the MS45XX_PRESSURE_SCALE to compensate. + Use the MS45XX_AIRSPEED_SCALE only to change air density. - - - - - + - diff --git a/sw/airborne/boards/disco.h b/sw/airborne/boards/disco.h index 0058967c77..edefcbcb73 100644 --- a/sw/airborne/boards/disco.h +++ b/sw/airborne/boards/disco.h @@ -97,7 +97,6 @@ extern struct video_config_t front_camera; #define MS45XX_PRESSURE_TYPE 1 #define MS45XX_OUTPUT_TYPE 1 #define MS45XX_PRESSURE_OUTPUT_TYPE_InH2O 1 -#define MS45XX_AIRSPEED_SCALE 1.6327 #ifndef USE_AIRSPEED_LOWPASS_FILTER #define USE_AIRSPEED_LOWPASS_FILTER 1 #endif diff --git a/sw/airborne/modules/sensors/airspeed_ms45xx_i2c.c b/sw/airborne/modules/sensors/airspeed_ms45xx_i2c.c index 00e1c7abfe..566bc974be 100644 --- a/sw/airborne/modules/sensors/airspeed_ms45xx_i2c.c +++ b/sw/airborne/modules/sensors/airspeed_ms45xx_i2c.c @@ -39,17 +39,6 @@ #include "modules/datalink/telemetry.h" #endif -#ifndef USE_AIRSPEED_MS45XX -#if USE_AIRSPEED -#define USE_AIRSPEED_MS45XX TRUE -PRINT_CONFIG_MSG("USE_AIRSPEED_MS45XX set to TRUE since this is set USE_AIRSPEED") -#endif -#endif - -#if USE_AIRSPEED_MS45XX -#include "state.h" -#endif - /** Default I2C device */ #ifndef MS45XX_I2C_DEV @@ -144,19 +133,15 @@ PRINT_CONFIG_VAR(MS45XX_PRESSURE_RANGE) PRINT_CONFIG_VAR(MS45XX_PRESSURE_SCALE) PRINT_CONFIG_VAR(MS45XX_PRESSURE_OFFSET) -/** Send a AIRSPEED_MS45XX message with every new measurement. - * Mainly for debugging, use with caution, sends message at ~100Hz. - */ -#ifndef MS45XX_SYNC_SEND -#define MS45XX_SYNC_SEND FALSE -#endif /** Quadratic scale factor for indicated airspeed. * airspeed = sqrt(2*p_diff/density) * With p_diff in Pa and standard air density of 1.225 kg/m^3, * default airspeed scale is 2/1.225 */ -#ifndef MS45XX_AIRSPEED_SCALE +#ifdef MS45XX_AIRSPEED_SCALE +#PRINT_CONFIG("MS45XX changed air density. PS: Use MS45XX_PRESSURE_SCALE to calibrate the MS45XX.") +#else #define MS45XX_AIRSPEED_SCALE 1.6327 #endif @@ -195,8 +180,6 @@ void ms45xx_i2c_init(void) ms45xx.pressure_type = MS45XX_PRESSURE_TYPE; ms45xx.pressure_scale = MS45XX_PRESSURE_SCALE; ms45xx.pressure_offset = MS45XX_PRESSURE_OFFSET; - ms45xx.airspeed_scale = MS45XX_AIRSPEED_SCALE; - ms45xx.sync_send = MS45XX_SYNC_SEND; ms45xx_trans.status = I2CTransDone; // setup low pass filter with time constant and 100Hz sampling freq @@ -286,14 +269,8 @@ void ms45xx_i2c_event(void) float temp = ms45xx.temperature / 10.0f; AbiSendMsgTEMPERATURE(MS45XX_SENDER_ID, temp); // Compute airspeed - ms45xx.airspeed = sqrtf(Max(ms45xx.pressure * ms45xx.airspeed_scale, 0)); + ms45xx.airspeed = sqrtf(Max(ms45xx.pressure, 0)) * MS45XX_AIRSPEED_SCALE; -#if USE_AIRSPEED_MS45XX - stateSetAirspeed_f(ms45xx.airspeed); -#endif - if (ms45xx.sync_send) { - ms45xx_downlink(&(DefaultChannel).trans_tx, &(DefaultDevice).device); - } } // Set to done diff --git a/sw/airborne/modules/sensors/airspeed_ms45xx_i2c.h b/sw/airborne/modules/sensors/airspeed_ms45xx_i2c.h index 847a79e71d..98b2e75bfb 100644 --- a/sw/airborne/modules/sensors/airspeed_ms45xx_i2c.h +++ b/sw/airborne/modules/sensors/airspeed_ms45xx_i2c.h @@ -34,11 +34,9 @@ struct AirspeedMs45xx { uint16_t raw_p; ///< Raw pressure float airspeed; ///< Airspeed in m/s estimated from (differential) pressure. bool pressure_type; ///< Pressure type Differential of Gauge - float airspeed_scale; ///< Quadratic scale factor to convert (differential) pressure to airspeed float pressure_scale; ///< Scaling factor from raw measurement to Pascal float pressure_offset; ///< Offset in Pascal bool autoset_offset; ///< Set offset value from current filtered value - bool sync_send; ///< Flag to enable sending every new measurement via telemetry for debugging purpose }; extern struct AirspeedMs45xx ms45xx;