Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
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
25
27#include "mcu_periph/adc.h"
28#include BOARD_CONFIG
29#include "generated/airframe.h"
30#include "state.h"
31#include "modules/core/abi.h"
32#include "mcu_periph/sys_time.h"
33#include "generated/modules.h"
34
35#ifndef USE_AIRSPEED_ADC
36#define USE_AIRSPEED_ADC TRUE
37#endif
39
40#if !defined AIRSPEED_ADC_QUADRATIC_SCALE && !defined AIRSPEED_ADC_SCALE
41#error "You need to define either AIRSPEED_ADC_QUADRATIC_SCALE or AIRSPEED_ADC_SCALE (linear)."
42#endif
43
45
46#ifndef SITL // Use ADC if not in simulation
47
48#ifndef ADC_CHANNEL_AIRSPEED
49#error "ADC_CHANNEL_AIRSPEED needs to be defined to use airspeed_adc module"
50#endif
51
52#ifndef ADC_CHANNEL_AIRSPEED_NB_SAMPLES
53#define ADC_CHANNEL_AIRSPEED_NB_SAMPLES DEFAULT_AV_NB_SAMPLE
54#endif
55
56static struct adc_buf buf_airspeed;
57
58#endif
59
61{
62 airspeed_adc.airspeed = 0.0f;
63 airspeed_adc.offset = AIRSPEED_ADC_BIAS;
64#ifdef AIRSPEED_ADC_QUADRATIC_SCALE
65 airspeed_adc.scale = AIRSPEED_ADC_QUADRATIC_SCALE;
66#else
67 airspeed_adc.scale = AIRSPEED_ADC_SCALE;
68#endif
69
70#ifndef SITL
72#endif
73}
74
76{
77#ifndef SITL
79 float airspeed_unscaled = Max(airspeed_adc.val - airspeed_adc.offset, 0);
80#ifdef AIRSPEED_ADC_QUADRATIC_SCALE
81 airspeed_adc.airspeed = airspeed_adc.scale * sqrtf(airspeed_unscaled);
82#else
83 airspeed_adc.airspeed = airspeed_adc.scale * airspeed_unscaled;
84#endif
85
86#elif !defined USE_NPS
87 extern float sim_air_speed;
88 airspeed_adc.airspeed = sim_air_speed;
89#endif //SITL
90
91#if USE_AIRSPEED_ADC
92 // air_data calibrates it and sets the airspeed
93 AbiSendMsgAIRSPEED_RAW(AIRSPEED_ADC_ID, get_sys_time_usec(), airspeed_adc.airspeed);
94#endif
95}
Main include for ABI (AirBorneInterface).
#define AIRSPEED_ADC_ID
arch independent ADC (Analog to Digital Converter) API
static uint16_t adc_buf_get(struct adc_buf *s)
Get filtered value from buffer.
Definition adc.h:76
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition adc.h:53
struct AirspeedAdc airspeed_adc
static struct adc_buf buf_airspeed
void airspeed_adc_update(void)
#define ADC_CHANNEL_AIRSPEED_NB_SAMPLES
void airspeed_adc_init(void)
#define USE_AIRSPEED_ADC
Read an airspeed or differential pressure sensor via onboard ADC.
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:312
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
API to get/set the generic vehicle states.
Architecture independent timing functions.