Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures 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 
40 // Default offset value (assuming 0 AOA is in the middle of the range)
41 #ifndef AOA_OFFSET
42 #define AOA_OFFSET M_PI
43 #endif
44 // Default filter value
45 #ifndef AOA_FILTER
46 #define AOA_FILTER 0.5
47 #endif
48 // Default sensitivity (2*pi on a 10 bit ADC)
49 #ifndef AOA_SENS
50 #define AOA_SENS ((2.0*M_PI)/1024)
51 #endif
52 
55 
56 // Internal values
57 float AOA, AOA_old;
58 
59 // Downlink
60 #ifndef DOWNLINK_DEVICE
61 #define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
62 #endif
63 
64 #ifndef SITL // Use ADC if not in simulation
65 
66 #include "mcu_periph/adc.h"
67 
68 #ifndef ADC_CHANNEL_AOA
69 #error "ADC_CHANNEL_AOA needs to be defined to use AOA_adc module"
70 #endif
71 
72 #ifndef ADC_CHANNEL_AOA_NB_SAMPLES
73 #define ADC_CHANNEL_AOA_NB_SAMPLES DEFAULT_AV_NB_SAMPLE
74 #endif
75 
77 #endif
78 
79 
80 void AOA_adc_init( void ) {
83  AOA_old = 0.0;
84  AOA = 0.0;
85 #ifndef SITL
87 #endif
88 }
89 
90 void AOA_adc_update( void ) {
91 #ifndef SITL
93 
94  // PT1 filter and convert to rad
96  AOA_old = AOA;
97 #endif
98  RunOnceEvery(30, DOWNLINK_SEND_AOA_adc(DefaultChannel, DefaultDevice, &adc_AOA_val, &AOA));
99 
100 #ifdef USE_AOA
102 #endif
103 }
104 
unsigned short uint16_t
Definition: types.h:16
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
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
static void stateSetAngleOfAttack_f(float *aoa)
Set angle of attack (float).
Definition: state.h:1160
uint8_t av_nb_sample
Definition: adc.h:64
struct adc_buf buf_AOA
Definition: AOA_adc.c:76
arch independent ADC (Analog to Digital Converter) API
uint32_t sum
Definition: adc.h:61
float AOA_filter
Filtering value [0-1[ 0: no filtering 1: output is a constant value.
Definition: AOA_adc.c:54
uint16_t adc_AOA_val
Raw ADC value.
Definition: AOA_adc.c:53
float AOA
Definition: AOA_adc.c:57
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition: adc.h:60
#define AOA_OFFSET
Definition: AOA_adc.c:42
void AOA_adc_init(void)
Definition: AOA_adc.c:80
#define ADC_CHANNEL_AOA_NB_SAMPLES
Definition: AOA_adc.c:73
float AOA_offset
Angle of Attack offset.
Definition: AOA_adc.c:54
API to get/set the generic vehicle states.
#define AOA_SENS
Definition: AOA_adc.c:50
float AOA_old
Definition: AOA_adc.c:57
void AOA_adc_update(void)
Definition: AOA_adc.c:90
#define AOA_FILTER
Definition: AOA_adc.c:46