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
aoa_adc.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  */
22 
32 #include "generated/airframe.h"
33 #include "state.h"
34 
35 // Messages
36 #include "mcu_periph/uart.h"
37 #include "messages.h"
39 
41 #ifndef AOA_OFFSET
42 #define AOA_OFFSET M_PI
43 #endif
44 #ifndef AOA_FILTER
46 #define AOA_FILTER 0.5
47 #endif
48 #ifndef AOA_SENS
50 #define AOA_SENS ((2.0*M_PI)/1024)
51 #endif
52 
53 
54 // Downlink
55 
56 #ifndef ADC_CHANNEL_AOA
57 #error "ADC_CHANNEL_AOA needs to be defined to use AOA_adc module"
58 #endif
59 
60 #ifndef ADC_CHANNEL_AOA_NB_SAMPLES
61 #define ADC_CHANNEL_AOA_NB_SAMPLES DEFAULT_AV_NB_SAMPLE
62 #endif
63 
65 
66 void aoa_adc_init(void)
67 {
71  aoa_adc.angle = 0.0;
73 }
74 
75 void aoa_adc_update(void)
76 {
77  static float prev_aoa = 0.0;
78 
80 
81  // PT1 filter and convert to rad
82  aoa_adc.angle = aoa_adc.filter * prev_aoa +
84  prev_aoa = aoa_adc.angle;
85 
86 #ifdef USE_AOA
88 #endif
89 
90  RunOnceEvery(30, DOWNLINK_SEND_AOA(DefaultChannel, DefaultDevice, &aoa_adc.raw, &aoa_adc.angle));
91 }
92 
uint8_t av_nb_sample
Definition: adc.h:57
void aoa_adc_update(void)
Definition: aoa_adc.c:75
float filter
Filtering value [0-1] 0: no filtering 1: output is a constant value.
Definition: aoa_adc.h:50
Angle of Attack sensor via ADC.
Definition: aoa_adc.h:39
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
uint32_t sum
Definition: adc.h:54
uint32_t raw
raw ADC value
Definition: aoa_adc.h:41
static void stateSetAngleOfAttack_f(float aoa)
Set angle of attack in radians (float).
Definition: state.h:1263
float sens
sensitiviy, i.e. scale to conver raw to angle
Definition: aoa_adc.h:44
#define AOA_OFFSET
Default offset value (assuming 0 AOA is in the middle of the range)
Definition: aoa_adc.c:42
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 AOA_SENS
Default sensitivity (2*pi on a 10 bit ADC)
Definition: aoa_adc.c:50
struct Aoa_Adc aoa_adc
Definition: aoa_adc.c:64
API to get/set the generic vehicle states.
void aoa_adc_init(void)
Definition: aoa_adc.c:66
struct adc_buf buf
Definition: aoa_adc.h:40
float offset
Angle of attack offset in radians.
Definition: aoa_adc.h:43
#define AOA_FILTER
Default filter value.
Definition: aoa_adc.c:46
#define ADC_CHANNEL_AOA_NB_SAMPLES
Definition: aoa_adc.c:61
float angle
Angle of attack in radians.
Definition: aoa_adc.h:42