Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
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 #include "subsystems/abi.h"
32 
33 #ifndef USE_AIRSPEED_ADC
34 #define USE_AIRSPEED_ADC TRUE
35 #endif
36 PRINT_CONFIG_VAR(USE_AIRSPEED_ADC)
37 
38 #if !defined AIRSPEED_ADC_QUADRATIC_SCALE && !defined AIRSPEED_ADC_SCALE
39 #error "You need to define either AIRSPEED_ADC_QUADRATIC_SCALE or AIRSPEED_ADC_SCALE (linear)."
40 #endif
41 
43 
44 #ifndef SITL // Use ADC if not in simulation
45 
46 #ifndef ADC_CHANNEL_AIRSPEED
47 #error "ADC_CHANNEL_AIRSPEED needs to be defined to use airspeed_adc module"
48 #endif
49 
50 #ifndef ADC_CHANNEL_AIRSPEED_NB_SAMPLES
51 #define ADC_CHANNEL_AIRSPEED_NB_SAMPLES DEFAULT_AV_NB_SAMPLE
52 #endif
53 
54 static struct adc_buf buf_airspeed;
55 
56 #endif
57 
59 {
60  airspeed_adc.airspeed = 0.0f;
61  airspeed_adc.offset = AIRSPEED_ADC_BIAS;
62 #ifdef AIRSPEED_ADC_QUADRATIC_SCALE
63  airspeed_adc.scale = AIRSPEED_ADC_QUADRATIC_SCALE;
64 #else
65  airspeed_adc.scale = AIRSPEED_ADC_SCALE;
66 #endif
67 
68 #ifndef SITL
70 #endif
71 }
72 
74 {
75 #ifndef SITL
77  float airspeed_unscaled = Max(airspeed_adc.val - airspeed_adc.offset, 0);
78 #ifdef AIRSPEED_ADC_QUADRATIC_SCALE
79  airspeed_adc.airspeed = airspeed_adc.scale * sqrtf(airspeed_unscaled);
80 #else
81  airspeed_adc.airspeed = airspeed_adc.scale * airspeed_unscaled;
82 #endif
83 
84 #elif !defined USE_NPS
85  extern float sim_air_speed;
87 #endif //SITL
88 
89  AbiSendMsgAIRSPEED(AIRSPEED_ADC_ID, airspeed_adc.airspeed);
90 
91 #if USE_AIRSPEED_ADC
93 #endif
94 }
stateSetAirspeed_f
static void stateSetAirspeed_f(float airspeed)
Set airspeed (float).
Definition: state.h:1309
abi.h
adc_buf_channel
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:289
airspeed_adc_update
void airspeed_adc_update(void)
Definition: airspeed_adc.c:73
adc.h
arch independent ADC (Analog to Digital Converter) API
adc_buf::sum
uint32_t sum
Definition: adc.h:54
AIRSPEED_ADC_ID
#define AIRSPEED_ADC_ID
Definition: abi_sender_ids.h:103
airspeed_adc.h
sim_air_speed
float sim_air_speed
Definition: sim_ir.c:14
AirspeedAdc::val
uint16_t val
Definition: airspeed_adc.h:32
airspeed_adc
struct AirspeedAdc airspeed_adc
Definition: airspeed_adc.c:42
ADC_CHANNEL_AIRSPEED_NB_SAMPLES
#define ADC_CHANNEL_AIRSPEED_NB_SAMPLES
Definition: airspeed_adc.c:51
airspeed_adc_init
void airspeed_adc_init(void)
Definition: airspeed_adc.c:58
adc_buf::av_nb_sample
uint8_t av_nb_sample
Definition: adc.h:57
AirspeedAdc::airspeed
float airspeed
Definition: airspeed_adc.h:35
buf_airspeed
static struct adc_buf buf_airspeed
Definition: airspeed_adc.c:54
AirspeedAdc::offset
uint16_t offset
Definition: airspeed_adc.h:33
AirspeedAdc::scale
float scale
used as quadratic scale if AIRSPEED_ADC_QUADRATIC_SCALE, otherwise linear
Definition: airspeed_adc.h:34
AirspeedAdc
Definition: airspeed_adc.h:31
Max
#define Max(x, y)
Definition: main_fbw.c:53
state.h
USE_AIRSPEED_ADC
#define USE_AIRSPEED_ADC
Definition: airspeed_adc.c:34
adc_buf
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition: adc.h:53