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) 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 {
67 
69 
71  baro_board.absolute = 0;
72  baro_board.offset = 1023;
75 #ifdef BARO_LED
76  LED_OFF(BARO_LED);
77 #endif
78 }
79 
80 void baro_periodic(void)
81 {
82 
86  RunOnceEvery(10, { baro_board_calibrate();});
87  } else {
88  float pressure = 101325.0 - BOOZ_BARO_SENS * (BOOZ_ANALOG_BARO_THRESHOLD - baro_board.absolute);
89  AbiSendMsgBARO_ABS(BARO_BOARD_SENDER_ID, pressure);
90  }
91 }
92 
93 /* decrement offset until adc reading is over a threshold */
95 {
97  if (baro_board.value_filtered == 0 && baro_board.offset > 15) {
98  baro_board.offset -= 15;
99  } else {
100  baro_board.offset--;
101  }
103 #ifdef BARO_LED
104  LED_TOGGLE(BARO_LED);
105 #endif
106  } else {
108 #ifdef BARO_LED
109  LED_ON(BARO_LED);
110 #endif
111  }
112 }
113 
uint8_t av_nb_sample
Definition: adc.h:57
struct BaroBoard baro_board
Definition: baro_board.c:63
Common barometric sensor implementation.
struct adc_buf buf
Definition: baro_board.h:47
void baro_board_calibrate(void)
Definition: baro_board.c:94
Main include for ABI (AirBorneInterface).
uint32_t sum
Definition: adc.h:54
void baro_init(void)
Definition: baro_board.c:68
uint16_t value_filtered
Definition: baro_board.h:46
void baro_periodic(void)
Definition: baro_board.c:77
uint16_t offset
Definition: baro_board.h:45
#define LED_TOGGLE(i)
Definition: led_hw.h:44
int32_t absolute
Definition: baro_board.h:44
#define BOOZ_ANALOG_BARO_THRESHOLD
threshold >0 && <1023
Definition: baro_board.c:37
enum BaroBoardStatus status
Definition: baro_board.h:43
#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
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:91
#define ADC_CHANNEL_BARO
Definition: booz_1.0.h:111
#define LED_ON(i)
Definition: led_hw.h:42
static void DACSet(uint16_t x)
Definition: dac_arch.h:36
arch independent LED (Light Emitting Diodes) API
#define DEFAULT_AV_NB_SAMPLE
Definition: adc.h:41
#define LED_OFF(i)
Definition: led_hw.h:43