diff --git a/conf/airframes/tudelft/rot_wing_v3b.xml b/conf/airframes/tudelft/rot_wing_v3b.xml index 4ce71b4180..084f3f0d36 100644 --- a/conf/airframes/tudelft/rot_wing_v3b.xml +++ b/conf/airframes/tudelft/rot_wing_v3b.xml @@ -74,11 +74,13 @@ + - + + diff --git a/conf/airframes/tudelft/rot_wing_v3d.xml b/conf/airframes/tudelft/rot_wing_v3d.xml index 62b836a45c..19c85c4553 100644 --- a/conf/airframes/tudelft/rot_wing_v3d.xml +++ b/conf/airframes/tudelft/rot_wing_v3d.xml @@ -74,10 +74,12 @@ + + diff --git a/conf/modules/airspeed_uavcan.xml b/conf/modules/airspeed_uavcan.xml index 616977af08..9cfacc14a6 100644 --- a/conf/modules/airspeed_uavcan.xml +++ b/conf/modules/airspeed_uavcan.xml @@ -9,7 +9,17 @@ + + + + + + + + + + uavcan airspeed diff --git a/conf/telemetry/highspeed_rotorcraft.xml b/conf/telemetry/highspeed_rotorcraft.xml index 218e3e3497..2fa8cf28d8 100644 --- a/conf/telemetry/highspeed_rotorcraft.xml +++ b/conf/telemetry/highspeed_rotorcraft.xml @@ -24,7 +24,7 @@ - + diff --git a/sw/airborne/modules/sensors/airspeed_ms45xx_i2c.c b/sw/airborne/modules/sensors/airspeed_ms45xx_i2c.c index 52b430f750..6d199b814f 100644 --- a/sw/airborne/modules/sensors/airspeed_ms45xx_i2c.c +++ b/sw/airborne/modules/sensors/airspeed_ms45xx_i2c.c @@ -39,6 +39,11 @@ #include "modules/datalink/telemetry.h" #endif +/* Enable ABI sending */ +#ifndef AIRSPEED_MS45XX_SEND_ABI +#define AIRSPEED_MS45XX_SEND_ABI true +#endif + /** Default I2C device */ #ifndef MS45XX_I2C_DEV @@ -286,10 +291,16 @@ void ms45xx_i2c_event(void) ms45xx.temperature = ((uint32_t)temp_raw * 2000) / 2047 - 500; // Send (differential) pressure via ABI + + #if AIRSPEED_MS45XX_SEND_ABI AbiSendMsgBARO_DIFF(MS45XX_SENDER_ID, ms45xx.pressure); + // Send temperature as float in deg Celcius via ABI float temp = ms45xx.temperature / 10.0f; + AbiSendMsgTEMPERATURE(MS45XX_SENDER_ID, temp); + #endif + // Compute airspeed float sign = 1.0f; if (ms45xx.pressure < 0.0f) { diff --git a/sw/airborne/modules/sensors/airspeed_uavcan.c b/sw/airborne/modules/sensors/airspeed_uavcan.c index eb1512e2af..b093c9b5ae 100644 --- a/sw/airborne/modules/sensors/airspeed_uavcan.c +++ b/sw/airborne/modules/sensors/airspeed_uavcan.c @@ -32,6 +32,11 @@ #define AIRSPEED_UAVCAN_SEND_ABI true #endif +/* Default pressure scaling */ +#ifndef AIRSPEED_UAVCAN_DIFF_P_SCALE +#define AIRSPEED_UAVCAN_DIFF_P_SCALE 1.0f +#endif + /* Airspeed lowpass filter*/ #ifdef USE_AIRSPEED_UAVCAN_LOWPASS_FILTER #include "filters/low_pass_filter.h" @@ -52,14 +57,8 @@ static Butterworth2LowPass airspeed_filter; #define UAVCAN_EQUIPMENT_AIR_DATA_RAWAIRDATA_SIGNATURE (0xC77DF38BA122F5DAULL) #define UAVCAN_EQUIPMENT_AIR_DATA_RAWAIRDATA_MAX_SIZE ((397 + 7)/8) -/* Local structure */ -struct airspeed_uavcan_t { - float diff_p; ///< Differential pressure - float temperature; ///< Temperature in Celsius -}; - /* Local variables */ -static struct airspeed_uavcan_t airspeed_uavcan = {0}; +struct airspeed_uavcan_t airspeed_uavcan = {0}; static uavcan_event airspeed_uavcan_ev; #if PERIODIC_TELEMETRY @@ -103,6 +102,11 @@ static void airspeed_uavcan_cb(struct uavcan_iface_t *iface __attribute__((unuse //float pitot_temp = canardConvertFloat16ToNativeFloat(tmp_float); if(!isnan(diff_p)) { + // Remove the offset and apply a scaling factor + diff_p -= airspeed_uavcan.diff_p_offset; + diff_p *= airspeed_uavcan.diff_p_scale; + + // Filtering #ifdef USE_AIRSPEED_UAVCAN_LOWPASS_FILTER float diff_p_filt = update_butterworth_2_low_pass(&airspeed_filter, diff_p); airspeed_uavcan.diff_p = diff_p_filt; @@ -110,6 +114,7 @@ static void airspeed_uavcan_cb(struct uavcan_iface_t *iface __attribute__((unuse airspeed_uavcan.diff_p = diff_p; #endif + // Send the ABI message #if AIRSPEED_UAVCAN_SEND_ABI AbiSendMsgBARO_DIFF(UAVCAN_SENDER_ID, airspeed_uavcan.diff_p); #endif @@ -125,6 +130,9 @@ static void airspeed_uavcan_cb(struct uavcan_iface_t *iface __attribute__((unuse void airspeed_uavcan_init(void) { + // Set the default values + airspeed_uavcan.diff_p_scale = AIRSPEED_UAVCAN_DIFF_P_SCALE; + // Setup the low pass filter #ifdef USE_AIRSPEED_UAVCAN_LOWPASS_FILTER init_butterworth_2_low_pass(&airspeed_filter, AIRSPEED_UAVCAN_LOWPASS_TAU, AIRSPEED_UAVCAN_LOWPASS_PERIOD, 0); @@ -137,3 +145,9 @@ void airspeed_uavcan_init(void) register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_AIRSPEED_RAW, airspeed_uavcan_downlink); #endif } + +void airspeed_uavcan_autoset_offset(bool set) { + if(set) { + airspeed_uavcan.diff_p_offset = airspeed_uavcan.diff_p; + } +} \ No newline at end of file diff --git a/sw/airborne/modules/sensors/airspeed_uavcan.h b/sw/airborne/modules/sensors/airspeed_uavcan.h index e45454ad36..8b93356cf2 100644 --- a/sw/airborne/modules/sensors/airspeed_uavcan.h +++ b/sw/airborne/modules/sensors/airspeed_uavcan.h @@ -26,7 +26,20 @@ #ifndef AIRSPEED_UAVCAN_H #define AIRSPEED_UAVCAN_H +#include "std.h" + +/* Airspeed UAVCAN structure */ +struct airspeed_uavcan_t { + float diff_p; ///< Differential pressure + float temperature; ///< Temperature in Celsius + + float diff_p_offset; ///< Differential pressure offset + float diff_p_scale; ///< Differential pressure scale +}; +extern struct airspeed_uavcan_t airspeed_uavcan; + /* External functions */ extern void airspeed_uavcan_init(void); +extern void airspeed_uavcan_autoset_offset(bool set); #endif /* AIRSPEED_UAVCAN_H */ \ No newline at end of file