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) 2010 The Paparazzi Team
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 
29 
30 #include "generated/airframe.h"
31 #include "subsystems/abi.h"
32 #include "led.h"
33 
34 
36 #ifndef BOOZ_ANALOG_BARO_THRESHOLD
37 #define BOOZ_ANALOG_BARO_THRESHOLD 850
38 #endif
39 
59 #ifndef BOOZ_BARO_SENS
60 #define BOOZ_BARO_SENS 0.759837
61 #endif
62 
64 
65 void baro_init( void ) {
66 
68 
70  baro_board.absolute = 0;
71  baro_board.offset = 1023;
74 #ifdef BARO_LED
75  LED_OFF(BARO_LED);
76 #endif
77 }
78 
79 void baro_periodic(void) {
80 
84  RunOnceEvery(10, { baro_board_calibrate();});
85  }
86  else {
87  float pressure = 101325.0 - BOOZ_BARO_SENS*(BOOZ_ANALOG_BARO_THRESHOLD - baro_board.absolute);
88  AbiSendMsgBARO_ABS(BARO_BOARD_SENDER_ID, &pressure);
89  }
90 }
91 
92 /* decrement offset until adc reading is over a threshold */
95  if (baro_board.value_filtered == 0 && baro_board.offset > 15)
96  baro_board.offset -= 15;
97  else
100 #ifdef BARO_LED
101  LED_TOGGLE(BARO_LED);
102 #endif
103  }
104  else {
106 #ifdef BARO_LED
107  LED_ON(BARO_LED);
108 #endif
109  }
110 }
111 
struct BaroBoard baro_board
Definition: baro_board.c:63
Common barometric sensor implementation.
void adc_buf_channel(uint8_t adc_channel, struct adc_buf *s, uint8_t av_nb_sample)
Registers a buffer to be used to store the specified converted channel Usage:
Definition: adc_arch.c:59
void baro_board_calibrate(void)
Definition: baro_board.c:93
Main include for ABI (AirBorneInterface).
#define LED_ON(i)
Definition: led_hw.h:28
void baro_init(void)
Definition: baro_board.c:68
uint8_t av_nb_sample
Definition: adc.h:57
uint16_t offset
Definition: baro_board.h:45
int32_t absolute
Definition: baro_board.h:44
uint32_t sum
Definition: adc.h:54
void baro_periodic(void)
Definition: baro_board.c:76
uint16_t value_filtered
Definition: baro_board.h:46
#define BOOZ_ANALOG_BARO_THRESHOLD
threshold >0 && <1023
Definition: baro_board.c:37
#define BOOZ_BARO_SENS
scale factor to convert raw ADC measurement to pressure in Pascal.
Definition: baro_board.c:60
#define BARO_BOARD_SENDER_ID
default onboard baro
#define LED_TOGGLE(i)
Definition: led_hw.h:30
#define ADC_CHANNEL_BARO
Definition: booz_1.0.h:111
static void DACSet(uint16_t x)
Definition: dac_arch.h:36
struct adc_buf buf
Definition: baro_board.h:47
#define LED_OFF(i)
Definition: led_hw.h:29
arch independent LED (Light Emitting Diodes) API
#define DEFAULT_AV_NB_SAMPLE
Definition: adc.h:41
enum BaroBoardStatus status
Definition: baro_board.h:43