Skip to content

Commit

Permalink
[modules] make air_data a module
Browse files Browse the repository at this point in the history
  • Loading branch information
flixr committed Oct 11, 2014
1 parent d585cd4 commit c753995
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 25 deletions.
4 changes: 1 addition & 3 deletions conf/firmwares/rotorcraft.makefile
Expand Up @@ -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


Expand Down
2 changes: 0 additions & 2 deletions conf/firmwares/subsystems/fixedwing/autopilot.makefile
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions conf/modules/air_data.xml
@@ -0,0 +1,34 @@
<!DOCTYPE module SYSTEM "module.dtd">

<module name="air_data">
<doc>
<description>
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.
</description>
<define name="AIR_DATA_BARO_ABS_ID" value="ABI_SENDER_ID" description="ABI sender id for absolute baro measurement (default: ABI_BROADCAST)"/>
<define name="AIR_DATA_BARO_DIFF_ID" value="ABI_SENDER_ID" description="ABI sender id for differential baro measurement (default: ABI_BROADCAST)"/>
<define name="AIR_DATA_AIRSPEED_SCALE" value="1.6327" description="quadratic scale factor to convert differential pressure to airspeed"/>
<define name="AIR_DATA_CALC_AIRSPEED" value="FALSE|TRUE" description="Calculate Airspeed from differential pressure (default: TRUE)"/>
<define name="AIR_DATA_AMSL_BARO" value="FALSE|TRUE" description="Calculate AMS from baro and QNH (default: FALSE)"/>
</doc>
<settings>
<dl_settings>
<dl_settings name="air_data">
<dl_setting min="800" max="1200" step="1" module="air_data/air_data" var="air_data.qnh" shortname="QNH" handler="SetQNH"/>
<dl_setting min="0" max="1" step="1" var="air_data.calc_qnh_once" module="air_data/air_data" shortname="calc_qnh"/>
<dl_setting min="0" max="1" step="1" var="air_data.calc_airspeed" module="air_data/air_data" shortname="calc_airspeed"/>
<dl_setting min="0" max="1" step="1" var="air_data.calc_amsl_baro" module="air_data/air_data" shortname="calc_amsl"/>
</dl_settings>
</dl_settings>
</settings>
<header>
<file name="air_data.h"/>
</header>
<init fun="air_data_init()"/>
<periodic fun="air_data_periodic()" freq="10"/>
<makefile>
<file name="air_data.c"/>
</makefile>
</module>
2 changes: 0 additions & 2 deletions sw/airborne/firmwares/fixedwing/main_ap.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions sw/airborne/firmwares/rotorcraft/main.c
Expand Up @@ -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"
Expand Down Expand Up @@ -152,7 +151,6 @@ STATIC_INLINE void main_init( void ) {

radio_control_init();

air_data_init();
#if USE_BARO_BOARD
baro_init();
#endif
Expand Down
@@ -1,7 +1,8 @@
/*
* Copyright (C) 2013 Gautier Hattenberger
* 2014 Felix Ruess <felix.ruess@gmail.com>
*
* 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
Expand All @@ -14,25 +15,25 @@
* 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
* <http://www.gnu.org/licenses/>.
*/

/**
* @file subsystems/air_data.c
* @file modules/air_data/air_data.c
* Air Data interface
* - pressures
* - airspeed
* - angle of attack and sideslip
* - 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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
@@ -1,7 +1,8 @@
/*
* Copyright (C) 2013 Gautier Hattenberger
* 2014 Felix Ruess <felix.ruess@gmail.com>
*
* 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
Expand All @@ -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
* <http://www.gnu.org/licenses/>.
*/

/**
* @file subsystems/air_data.h
* @file modules/air_data/air_data.h
* Air Data interface
* - pressures
* - airspeed
Expand All @@ -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
Expand All @@ -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

0 comments on commit c753995

Please sign in to comment.