Paparazzi UAS  v5.15_devel-230-gc96ce27
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 "subsystems/abi.h"
34 #include "state.h"
35 
36 // Messages
37 #include "mcu_periph/uart.h"
38 #include "pprzlink/messages.h"
40 
42 #ifndef AOA_OFFSET
43 #define AOA_OFFSET M_PI
44 #endif
45 #ifndef AOA_FILTER
47 #define AOA_FILTER 0.5
48 #endif
49 #ifndef AOA_SENS
51 #define AOA_SENS ((2.0*M_PI)/1024)
52 #endif
53 
54 
55 // Downlink
56 
57 #ifndef ADC_CHANNEL_AOA
58 #error "ADC_CHANNEL_AOA needs to be defined to use AOA_adc module"
59 #endif
60 
61 #ifndef ADC_CHANNEL_AOA_NB_SAMPLES
62 #define ADC_CHANNEL_AOA_NB_SAMPLES DEFAULT_AV_NB_SAMPLE
63 #endif
64 
66 
67 void aoa_adc_init(void)
68 {
72  aoa_adc.angle = 0.0;
74 }
75 
76 void aoa_adc_update(void)
77 {
78  static float prev_aoa = 0.0;
79 
81 
82  // PT1 filter and convert to rad
83  aoa_adc.angle = aoa_adc.filter * prev_aoa +
85  prev_aoa = aoa_adc.angle;
86 
87 #ifdef USE_AOA
88  uint8_t flag = 1;
89  float foo = 0.f;
90  AbiSendMsgINCIDENCE(AOA_ADC_ID, flag, aoa_adc.angle, foo);
92 #endif
93 
94  RunOnceEvery(30, DOWNLINK_SEND_AOA(DefaultChannel, DefaultDevice, &aoa_adc.raw, &aoa_adc.angle));
95 }
96 
uint8_t av_nb_sample
Definition: adc.h:57
void aoa_adc_update(void)
Definition: aoa_adc.c:76
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
Main include for ABI (AirBorneInterface).
void adc_buf_channel(uint8_t adc_channel, struct adc_buf *s, uint8_t av_nb_sample)
Link between ChibiOS ADC drivers and Paparazzi adc_buffers.
Definition: adc_arch.c:281
uint32_t sum
Definition: adc.h:54
uint32_t raw
raw ADC value
Definition: aoa_adc.h:41
#define AOA_ADC_ID
static void stateSetAngleOfAttack_f(float aoa)
Set angle of attack in radians (float).
Definition: state.h:1318
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:43
uint16_t foo
Definition: main_demo5.c:59
#define AOA_SENS
Default sensitivity (2*pi on a 10 bit ADC)
Definition: aoa_adc.c:51
struct Aoa_Adc aoa_adc
Definition: aoa_adc.c:65
unsigned char uint8_t
Definition: types.h:14
API to get/set the generic vehicle states.
void aoa_adc_init(void)
Definition: aoa_adc.c:67
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:47
#define ADC_CHANNEL_AOA_NB_SAMPLES
Definition: aoa_adc.c:62
float angle
Angle of attack in radians.
Definition: aoa_adc.h:42