Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
baro_board.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 TU Delft Quatrotor Team 1
3  *
4  * This file is part of Paparazzi.
5  *
6  * Paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * Paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
30 #include "subsystems/abi.h"
31 #include "baro_board.h"
32 #include "navdata.h"
33 
36 #if USE_BARO_MEDIAN_FILTER
37 #include "filters/median_filter.h"
38 struct MedianFilterInt baro_median;
39 #endif
40 
41 
42 #define BMP180_OSS 0 // Parrot ARDrone uses no oversampling
43 
44 void baro_init(void)
45 {
46 #if USE_BARO_MEDIAN_FILTER
47  init_median_filter(&baro_median);
48 #endif
49 }
50 
51 void baro_periodic(void) {}
52 
59 {
60  int32_t b6 = ((int32_t)navdata.bmp180_calib.b5) - 4000L;
61  int32_t x1 = (((int32_t)navdata.bmp180_calib.b2) * (b6 * b6 >> 12)) >> 11;
62  int32_t x2 = ((int32_t)navdata.bmp180_calib.ac2) * b6 >> 11;
63  int32_t x3 = x1 + x2;
64  int32_t b3 = (((((int32_t)navdata.bmp180_calib.ac1) * 4 + x3) << BMP180_OSS) + 2) / 4;
65  x1 = ((int32_t)navdata.bmp180_calib.ac3) * b6 >> 13;
66  x2 = (((int32_t)navdata.bmp180_calib.b1) * (b6 * b6 >> 12)) >> 16;
67  x3 = ((x1 + x2) + 2) >> 2;
68  uint32_t b4 = (((int32_t)navdata.bmp180_calib.ac4) * (uint32_t)(x3 + 32768L)) >> 15;
69  uint32_t b7 = (raw - b3) * (50000L >> BMP180_OSS);
70  int32_t p = b7 < 0x80000000L ? (b7 * 2) / b4 : (b7 / b4) * 2;
71  x1 = (p >> 8) * (p >> 8);
72  x1 = (x1 * 3038UL) >> 16;
73  x2 = (-7357L * p) >> 16;
74  int32_t press = p + ((x1 + x2 + 3791L) >> 4);
75  // Zero at sealevel
76  return press;
77 }
78 
85 {
86  int32_t x1 = ((tmp_raw - ((int32_t)navdata.bmp180_calib.ac6)) * ((int32_t)navdata.bmp180_calib.ac5)) >> 15;
87  int32_t x2 = (((int32_t)navdata.bmp180_calib.mc) << 11) / (x1 + ((int32_t)navdata.bmp180_calib.md));
88  navdata.bmp180_calib.b5 = x1 + x2;
89  return (navdata.bmp180_calib.b5 + 8) >> 4;
90 }
91 
93 {
94  if (navdata.baro_available) {
96  // first read temperature because pressure calibration depends on temperature
98  AbiSendMsgTEMPERATURE(BARO_BOARD_SENDER_ID, temp_deg);
100 #if USE_BARO_MEDIAN_FILTER
101  press_pascal = update_median_filter(&baro_median, press_pascal);
102 #endif
103  float pressure = (float)press_pascal;
104  AbiSendMsgBARO_ABS(BARO_BOARD_SENDER_ID, pressure);
105  }
107  }
108 }
Common barometric sensor implementation.
static int32_t baro_apply_calibration(int32_t raw)
Apply temperature and sensor calibration to get pressure in Pa.
Definition: baro_board.c:58
Main include for ABI (AirBorneInterface).
void baro_init(void)
Definition: baro_board.c:68
#define FALSE
Definition: std.h:5
void baro_periodic(void)
Definition: baro_board.c:77
#define BMP180_OSS
Use an extra median filter to filter baro data.
Definition: baro_board.c:42
Paparazzi AR Drone 2 Baro Sensor implementation:.
int32_t update_median_filter(struct MedianFilterInt *filter, int32_t new_data)
Definition: median_filter.h:51
unsigned long uint32_t
Definition: types.h:18
#define BARO_BOARD_SENDER_ID
default onboard baro
signed long int32_t
Definition: types.h:19
void ardrone_baro_event(void)
Definition: baro_board.c:92
static int32_t baro_apply_calibration_temp(int32_t tmp_raw)
Apply temperature calibration.
Definition: baro_board.c:84
static float p[2][2]
void init_median_filter(struct MedianFilterInt *filter)
Definition: median_filter.h:41