Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures 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 #if USE_BARO_MEDIAN_FILTER
46  init_median_filter(&baro_median);
47 #endif
48 }
49 
50 void baro_periodic(void) {}
51 
53 {
54  int32_t b6 = ((int32_t)baro_calibration.b5) - 4000L;
55  int32_t x1 = (((int32_t)baro_calibration.b2) * (b6 * b6 >> 12)) >> 11;
56  int32_t x2 = ((int32_t)baro_calibration.ac2) * b6 >> 11;
57  int32_t x3 = x1 + x2;
58  int32_t b3 = (((((int32_t)baro_calibration.ac1) * 4 + x3) << BMP180_OSS) + 2)/4;
59  x1 = ((int32_t)baro_calibration.ac3) * b6 >> 13;
60  x2 = (((int32_t)baro_calibration.b1) * (b6 * b6 >> 12)) >> 16;
61  x3 = ((x1 + x2) + 2) >> 2;
62  uint32_t b4 = (((int32_t)baro_calibration.ac4) * (uint32_t) (x3 + 32768L)) >> 15;
63  uint32_t b7 = (raw - b3) * (50000L >> BMP180_OSS);
64  int32_t p = b7 < 0x80000000L ? (b7 * 2) / b4 : (b7 / b4) * 2;
65  x1 = (p >> 8) * (p >> 8);
66  x1 = (x1 * 3038UL) >> 16;
67  x2 = (-7357L * p) >> 16;
68  int32_t press = p + ((x1 + x2 + 3791L) >> 4);
69  // Zero at sealevel
70  return press;
71 }
72 
74 {
75  int32_t x1 = ((tmp_raw - ((int32_t)baro_calibration.ac6)) * ((int32_t)baro_calibration.ac5)) >> 15;
76  int32_t x2 = (((int32_t)baro_calibration.mc) << 11) / (x1 + ((int32_t)baro_calibration.md));
77  baro_calibration.b5 = x1 + x2;
78  return (baro_calibration.b5 + 8) >> 4;
79 }
80 
82 {
84  if (baro_calibrated) {
85  // first read temperature because pressure calibration depends on temperature
86  // TODO send Temperature message
89 #if USE_BARO_MEDIAN_FILTER
90  press_raw = update_median_filter(&baro_median, press_raw);
91 #endif
92  float pressure = (float)press_raw;
93  AbiSendMsgBARO_ABS(BARO_BOARD_SENDER_ID, &pressure);
94  }
96  }
97 }
Common barometric sensor implementation.
static int32_t baro_apply_calibration(int32_t raw)
Definition: baro_board.c:52
Main include for ABI (AirBorneInterface).
void baro_init(void)
Definition: baro_board.c:68
#define FALSE
Definition: imu_chimu.h:141
void baro_periodic(void)
Definition: baro_board.c:76
#define BMP180_OSS
Use an extra median filter to filter baro data.
Definition: baro_board.c:42
uint16_t temperature_pressure
Definition: navdata.h:70
Paparazzi AR Drone 2 Baro Sensor implementation:.
int32_t pressure
Definition: navdata.h:69
int32_t update_median_filter(struct MedianFilterInt *filter, int32_t new_data)
Definition: median_filter.h:50
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:81
static int32_t baro_apply_calibration_temp(int32_t tmp_raw)
Definition: baro_board.c:73
static float p[2][2]
void init_median_filter(struct MedianFilterInt *filter)
Definition: median_filter.h:41