Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
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
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
97  uint32_t now_ts = get_sys_time_usec();
99  AbiSendMsgTEMPERATURE(BARO_BOARD_SENDER_ID, temp_deg);
101 #if USE_BARO_MEDIAN_FILTER
102  press_pascal = update_median_filter_i(&baro_median, press_pascal);
103 #endif
104  float pressure = (float)press_pascal;
105  AbiSendMsgBARO_ABS(BARO_BOARD_SENDER_ID, now_ts, pressure);
106  }
107  navdata.baro_available = false;
108  }
109 }
navdata.h
BARO_BOARD_SENDER_ID
#define BARO_BOARD_SENDER_ID
default onboard baro
Definition: abi_sender_ids.h:33
navdata_t::measure
struct navdata_measure_t measure
Main navdata packet receieved from navboard.
Definition: navdata.h:125
ardrone_baro_event
void ardrone_baro_event(void)
Definition: baro_board.c:92
abi.h
navdata_measure_t::pressure
int32_t pressure
Definition: navdata.h:75
bmp180_calib_t::b1
int16_t b1
Definition: navdata.h:94
baro_board.h
bmp180_calib_t::ac3
int16_t ac3
Definition: navdata.h:90
bmp180_calib_t::ac6
uint16_t ac6
Definition: navdata.h:93
uint32_t
unsigned long uint32_t
Definition: types.h:18
baro_init
void baro_init(void)
Definition: baro_board.c:76
baro_periodic
void baro_periodic(void)
Definition: baro_board.c:90
get_sys_time_usec
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:68
bmp180_calib_t::b2
int16_t b2
Definition: navdata.h:95
bmp180_calib_t::md
int16_t md
Definition: navdata.h:98
BMP180_OSS
#define BMP180_OSS
Use an extra median filter to filter baro data.
Definition: baro_board.c:42
bmp180_calib_t::mc
int16_t mc
Definition: navdata.h:97
navdata_measure_t::temperature_pressure
uint16_t temperature_pressure
Definition: navdata.h:76
bmp180_calib_t::b5
int32_t b5
Definition: navdata.h:101
update_median_filter_i
static int32_t update_median_filter_i(struct MedianFilterInt *filter, int32_t new_data)
Definition: median_filter.h:68
median_filter.h
bmp180_calib_t::ac4
uint16_t ac4
Definition: navdata.h:91
navdata_t::baro_calibrated
bool baro_calibrated
Whenever the baro is calibrated.
Definition: navdata.h:128
baro_apply_calibration
static int32_t baro_apply_calibration(int32_t raw)
Apply temperature and sensor calibration to get pressure in Pa.
Definition: baro_board.c:58
baro.h
navdata
struct navdata_t navdata
Definition: navdata.c:59
MEDIAN_DEFAULT_SIZE
#define MEDIAN_DEFAULT_SIZE
Definition: median_filter.h:28
baro_apply_calibration_temp
static int32_t baro_apply_calibration_temp(int32_t tmp_raw)
Apply temperature calibration.
Definition: baro_board.c:84
int32_t
signed long int32_t
Definition: types.h:19
MedianFilterInt
Definition: median_filter.h:33
bmp180_calib_t::ac5
uint16_t ac5
Definition: navdata.h:92
bmp180_calib_t::ac1
int16_t ac1
Definition: navdata.h:88
bmp180_calib_t::ac2
int16_t ac2
Definition: navdata.h:89
navdata_t::baro_available
bool baro_available
Whenever the baro is available.
Definition: navdata.h:129
init_median_filter_i
static void init_median_filter_i(struct MedianFilterInt *filter, uint8_t size)
Definition: median_filter.h:39
navdata_t::bmp180_calib
struct bmp180_calib_t bmp180_calib
BMP180 calibration receieved from navboard.
Definition: navdata.h:126
p
static float p[2][2]
Definition: ins_alt_float.c:268