Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures 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  */
22 
24 #include "mcu_periph/adc.h"
25 #include BOARD_CONFIG
26 #include "generated/airframe.h"
27 #include "state.h"
28 
30 
31 #ifndef SITL // Use ADC if not in simulation
32 
33 #ifndef ADC_CHANNEL_AIRSPEED
34 #error "ADC_CHANNEL_AIRSPEED needs to be defined to use airspeed_adc module"
35 #endif
36 
37 #ifndef ADC_CHANNEL_AIRSPEED_NB_SAMPLES
38 #define ADC_CHANNEL_AIRSPEED_NB_SAMPLES DEFAULT_AV_NB_SAMPLE
39 #endif
40 
42 
43 #endif
44 
45 void airspeed_adc_init( void ) {
46 #ifndef SITL
48 #endif
49 }
50 
51 void airspeed_adc_update( void ) {
52 #ifndef SITL
54 #ifdef AIRSPEED_QUADRATIC_SCALE
55  float airspeed = (adc_airspeed_val - AIRSPEED_BIAS);
56  if (airspeed <= 0.0f)
57  airspeed = 0.0f;
58  airspeed = sqrtf(airspeed) * AIRSPEED_QUADRATIC_SCALE;
59 #else
60  float airspeed = AIRSPEED_SCALE * (adc_airspeed_val - AIRSPEED_BIAS);
61 #endif
62  stateSetAirspeed_f(&airspeed);
63 #elif !defined USE_NPS
64  extern float sim_air_speed;
65  stateSetAirspeed_f(&sim_air_speed);
66  adc_airspeed_val = 0;
67 #endif //SITL
68 }
unsigned short uint16_t
Definition: types.h:16
void airspeed_adc_update(void)
Definition: airspeed_adc.c:51
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
uint8_t av_nb_sample
Definition: adc.h:57
arch independent ADC (Analog to Digital Converter) API
void airspeed_adc_init(void)
Definition: airspeed_adc.c:45
uint32_t sum
Definition: adc.h:54
#define ADC_CHANNEL_AIRSPEED_NB_SAMPLES
Definition: airspeed_adc.c:38
float sim_air_speed
Definition: sim_ir.c:14
struct adc_buf buf_airspeed
Definition: airspeed_adc.c:41
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition: adc.h:53
static void stateSetAirspeed_f(float *airspeed)
Set airspeed (float).
Definition: state.h:1152
API to get/set the generic vehicle states.
uint16_t adc_airspeed_val
Definition: airspeed_adc.c:29