Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
airspeed_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 
27 #include "mcu_periph/adc.h"
28 #include BOARD_CONFIG
29 #include "generated/airframe.h"
30 #include "state.h"
31 
32 #ifndef USE_AIRSPEED_ADC
33 #define USE_AIRSPEED_ADC TRUE
34 #endif
35 PRINT_CONFIG_VAR(USE_AIRSPEED_ADC)
36 
37 #if !defined AIRSPEED_ADC_QUADRATIC_SCALE && !defined AIRSPEED_ADC_SCALE
38 #error "You need to define either AIRSPEED_ADC_QUADRATIC_SCALE or AIRSPEED_ADC_SCALE (linear)."
39 #endif
40 
42 
43 #ifndef SITL // Use ADC if not in simulation
44 
45 #ifndef ADC_CHANNEL_AIRSPEED
46 #error "ADC_CHANNEL_AIRSPEED needs to be defined to use airspeed_adc module"
47 #endif
48 
49 #ifndef ADC_CHANNEL_AIRSPEED_NB_SAMPLES
50 #define ADC_CHANNEL_AIRSPEED_NB_SAMPLES DEFAULT_AV_NB_SAMPLE
51 #endif
52 
53 static struct adc_buf buf_airspeed;
54 
55 #endif
56 
58 {
59  airspeed_adc.airspeed = 0.0f;
60  airspeed_adc.offset = AIRSPEED_ADC_BIAS;
61 #ifdef AIRSPEED_ADC_QUADRATIC_SCALE
62  airspeed_adc.scale = AIRSPEED_ADC_QUADRATIC_SCALE;
63 #else
64  airspeed_adc.scale = AIRSPEED_ADC_SCALE;
65 #endif
66 
67 #ifndef SITL
69 #endif
70 }
71 
73 {
74 #ifndef SITL
76  float airspeed_unscaled = Max(airspeed_adc.val - airspeed_adc.offset, 0);
77 #ifdef AIRSPEED_ADC_QUADRATIC_SCALE
78  airspeed_adc.airspeed = airspeed_adc.scale * sqrtf(airspeed_unscaled);
79 #else
80  airspeed_adc.airspeed = airspeed_adc.scale * airspeed_unscaled;
81 #endif
82 
83 #elif !defined USE_NPS
84  extern float sim_air_speed;
86 #endif //SITL
87 
88 #if USE_AIRSPEED_ADC
90 #endif
91 }
uint8_t av_nb_sample
Definition: adc.h:57
Read an airspeed or differential pressure sensor via onboard ADC.
void airspeed_adc_update(void)
Definition: airspeed_adc.c:72
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:265
uint32_t sum
Definition: adc.h:54
arch independent ADC (Analog to Digital Converter) API
void airspeed_adc_init(void)
Definition: airspeed_adc.c:57
uint16_t val
Definition: airspeed_adc.h:32
#define ADC_CHANNEL_AIRSPEED_NB_SAMPLES
Definition: airspeed_adc.c:50
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition: adc.h:53
float sim_air_speed
Definition: sim_ir.c:14
static struct adc_buf buf_airspeed
Definition: airspeed_adc.c:53
struct AirspeedAdc airspeed_adc
Definition: airspeed_adc.c:41
#define Max(x, y)
Definition: main_fbw.c:53
float airspeed
Definition: airspeed_adc.h:35
float scale
used as quadratic scale if AIRSPEED_ADC_QUADRATIC_SCALE, otherwise linear
Definition: airspeed_adc.h:34
uint16_t offset
Definition: airspeed_adc.h:33
API to get/set the generic vehicle states.
static void stateSetAirspeed_f(float airspeed)
Set airspeed (float).
Definition: state.h:1291
#define USE_AIRSPEED_ADC
Definition: airspeed_adc.c:33