From c75399543fda9196055464f7b594dddfc0daad77 Mon Sep 17 00:00:00 2001 From: Felix Ruess Date: Sat, 11 Oct 2014 23:21:06 +0200 Subject: [PATCH] [modules] make air_data a module --- conf/firmwares/rotorcraft.makefile | 4 +-- .../subsystems/fixedwing/autopilot.makefile | 2 -- conf/modules/air_data.xml | 34 +++++++++++++++++++ sw/airborne/firmwares/fixedwing/main_ap.c | 2 -- sw/airborne/firmwares/rotorcraft/main.c | 2 -- .../air_data}/air_data.c | 24 ++++++++----- .../air_data}/air_data.h | 16 ++++----- 7 files changed, 59 insertions(+), 25 deletions(-) create mode 100644 conf/modules/air_data.xml rename sw/airborne/{subsystems => modules/air_data}/air_data.c (90%) rename sw/airborne/{subsystems => modules/air_data}/air_data.h (88%) diff --git a/conf/firmwares/rotorcraft.makefile b/conf/firmwares/rotorcraft.makefile index 668df46d820..8de4dd47ca2 100644 --- a/conf/firmwares/rotorcraft.makefile +++ b/conf/firmwares/rotorcraft.makefile @@ -73,10 +73,8 @@ $(TARGET).srcs += subsystems/commands.c $(TARGET).srcs += state.c # -# AIR DATA and BARO (if needed) +# BARO_BOARD (if existing/configured) # -$(TARGET).srcs += subsystems/air_data.c - include $(CFG_SHARED)/baro_board.makefile diff --git a/conf/firmwares/subsystems/fixedwing/autopilot.makefile b/conf/firmwares/subsystems/fixedwing/autopilot.makefile index c915ba7d93e..5af5506c4e0 100644 --- a/conf/firmwares/subsystems/fixedwing/autopilot.makefile +++ b/conf/firmwares/subsystems/fixedwing/autopilot.makefile @@ -161,8 +161,6 @@ ap_srcs += state.c ap_srcs += subsystems/settings.c ap_srcs += $(SRC_ARCH)/subsystems/settings_arch.c -# AIR DATA -ap_srcs += subsystems/air_data.c # BARO include $(CFG_SHARED)/baro_board.makefile diff --git a/conf/modules/air_data.xml b/conf/modules/air_data.xml new file mode 100644 index 00000000000..8c447b9ae43 --- /dev/null +++ b/conf/modules/air_data.xml @@ -0,0 +1,34 @@ + + + + + + AirData interface. + Provides an interface for baro absolute and differential pressure as well as airspeed. + Subscribes to BARO_ABS and BARO_DIFF ABI messages and calculates QNH and airspeed from it. + + + + + + + + + + + + + + + + + +
+ +
+ + + + + +
diff --git a/sw/airborne/firmwares/fixedwing/main_ap.c b/sw/airborne/firmwares/fixedwing/main_ap.c index 10f872717bc..8adbcd02ddb 100644 --- a/sw/airborne/firmwares/fixedwing/main_ap.c +++ b/sw/airborne/firmwares/fixedwing/main_ap.c @@ -53,7 +53,6 @@ #if USE_AHRS_ALIGNER #include "subsystems/ahrs/ahrs_aligner.h" #endif -#include "subsystems/air_data.h" #if USE_BARO_BOARD #include "subsystems/sensors/baro.h" PRINT_CONFIG_MSG_VALUE("USE_BARO_BOARD is TRUE, reading onboard baro: ", BARO_BOARD) @@ -205,7 +204,6 @@ void init_ap( void ) { register_periodic_telemetry(DefaultPeriodic, "STATE_FILTER_STATUS", send_filter_status); #endif - air_data_init(); #if USE_BARO_BOARD baro_init(); #endif diff --git a/sw/airborne/firmwares/rotorcraft/main.c b/sw/airborne/firmwares/rotorcraft/main.c index 133b0fe8c41..59d6f37c616 100644 --- a/sw/airborne/firmwares/rotorcraft/main.c +++ b/sw/airborne/firmwares/rotorcraft/main.c @@ -52,7 +52,6 @@ #include "subsystems/imu.h" #include "subsystems/gps.h" -#include "subsystems/air_data.h" #if USE_BARO_BOARD #include "subsystems/sensors/baro.h" @@ -152,7 +151,6 @@ STATIC_INLINE void main_init( void ) { radio_control_init(); - air_data_init(); #if USE_BARO_BOARD baro_init(); #endif diff --git a/sw/airborne/subsystems/air_data.c b/sw/airborne/modules/air_data/air_data.c similarity index 90% rename from sw/airborne/subsystems/air_data.c rename to sw/airborne/modules/air_data/air_data.c index e8c99082cd4..272cf4e4d2e 100644 --- a/sw/airborne/subsystems/air_data.c +++ b/sw/airborne/modules/air_data/air_data.c @@ -1,7 +1,8 @@ /* * Copyright (C) 2013 Gautier Hattenberger + * 2014 Felix Ruess * - * This file is part of paparazzi. + * This file is part of paparazzi * * paparazzi is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -14,13 +15,12 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with paparazzi; see the file COPYING. If not, write to - * the Free Software Foundation, 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * along with paparazzi; see the file COPYING. If not, see + * . */ /** - * @file subsystems/air_data.c + * @file modules/air_data/air_data.c * Air Data interface * - pressures * - airspeed @@ -28,11 +28,12 @@ * - wind */ -#include "subsystems/air_data.h" +#include "modules/air_data/air_data.h" #include "subsystems/abi.h" #include "math/pprz_isa.h" #include "state.h" + /** global AirData state */ struct AirData air_data; @@ -89,13 +90,14 @@ static void pressure_abs_cb(uint8_t __attribute__((unused)) sender_id, const flo // calculate QNH from pressure and absolute alitude if that is available if (air_data.calc_qnh_once && stateIsGlobalCoordinateValid()) { float h = stateGetPositionLla_f()->alt; - air_data.qnh = pprz_isa_ref_pressure_of_height_full(air_data.pressure, h); + air_data.qnh = pprz_isa_ref_pressure_of_height_full(air_data.pressure, h) / 100.f; air_data.calc_qnh_once = FALSE; qnh_set = TRUE; } if (air_data.calc_amsl_baro && qnh_set) { - air_data.amsl_baro = pprz_isa_height_of_pressure_full(air_data.pressure, air_data.qnh); + air_data.amsl_baro = pprz_isa_height_of_pressure_full(air_data.pressure, + air_data.qnh * 100.f); air_data.amsl_baro_valid = TRUE; } @@ -165,3 +167,9 @@ void air_data_periodic(void) air_data.amsl_baro_valid = FALSE; } } + +void air_data_SetQNH(float qnh) +{ + air_data.qnh = qnh; + qnh_set = TRUE; +} diff --git a/sw/airborne/subsystems/air_data.h b/sw/airborne/modules/air_data/air_data.h similarity index 88% rename from sw/airborne/subsystems/air_data.h rename to sw/airborne/modules/air_data/air_data.h index 482c19c3ced..7a06cb9ef9d 100644 --- a/sw/airborne/subsystems/air_data.h +++ b/sw/airborne/modules/air_data/air_data.h @@ -1,7 +1,8 @@ /* * Copyright (C) 2013 Gautier Hattenberger + * 2014 Felix Ruess * - * This file is part of paparazzi. + * This file is part of paparazzi * * paparazzi is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -14,13 +15,12 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with paparazzi; see the file COPYING. If not, write to - * the Free Software Foundation, 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * along with paparazzi; see the file COPYING. If not, see + * . */ /** - * @file subsystems/air_data.h + * @file modules/air_data/air_data.h * Air Data interface * - pressures * - airspeed @@ -44,7 +44,7 @@ struct AirData { float wind_dir; ///< wind direction (rad, 0 north, >0 clockwise) float airspeed_scale; ///< quadratic scale factor to convert differential pressure to airspeed - float qnh; ///< Barometric pressure adjusted to sea level in Pa + float qnh; ///< Barometric pressure adjusted to sea level in hPa float amsl_baro; ///< altitude above sea level in m from pressure and QNH bool_t amsl_baro_valid; ///< TRUE if #amsl_baro is currently valid bool_t calc_airspeed; ///< if TRUE, calculate airspeed from differential pressure @@ -69,6 +69,6 @@ extern void air_data_periodic(void); */ extern float air_data_get_amsl(void); +extern void air_data_SetQNH(float qnh); -#endif /* AIR_DATA_H */ - +#endif