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
sonar_adc.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 Gautier Hattenberger, 2013 Tobias M√ľnch
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 "generated/airframe.h"
25 #include "mcu_periph/adc.h"
26 #include "subsystems/abi.h"
27 #ifdef SITL
28 #include "state.h"
29 #endif
30 
31 #include "mcu_periph/uart.h"
32 #include "messages.h"
34 
39 #ifndef SONAR_OFFSET
40 #define SONAR_OFFSET 0
41 #endif
42 
46 #ifndef SONAR_SCALE
47 #define SONAR_SCALE 0.0166
48 #endif
49 
51 
52 #ifndef SITL
53 static struct adc_buf sonar_adc_buf;
54 #endif
55 
56 void sonar_adc_init(void) {
57  sonar_adc.meas = 0;
59 
60 #ifndef SITL
62 #endif
63 }
64 
67 void sonar_adc_read(void) {
68 #ifndef SITL
71 #else // SITL
73  Bound(sonar_adc.distance, 0.1f, 7.0f);
74 #endif // SITL
75 
76  // Send ABI message
77  AbiSendMsgAGL(AGL_SONAR_ADC_ID, &sonar_adc.distance);
78 
79 #ifdef SENSOR_SYNC_SEND_SONAR
80  // Send Telemetry report
81  DOWNLINK_SEND_SONAR(DefaultChannel, DefaultDevice, &sonar_adc.meas, &sonar_adc.distance);
82 #endif
83 }
84 
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
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
float distance
Distance measured in meters.
Definition: sonar_adc.h:35
#define AGL_SONAR_ADC_ID
Main include for ABI (AirBorneInterface).
float z
in meters
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
Definition: state.h:672
uint8_t av_nb_sample
Definition: adc.h:57
void sonar_adc_read(void)
Read ADC value to update sonar measurement.
Definition: sonar_adc.c:67
arch independent ADC (Analog to Digital Converter) API
uint32_t sum
Definition: adc.h:54
uint16_t offset
Sonar offset in ADC units.
Definition: sonar_adc.h:34
void sonar_adc_init(void)
Definition: sonar_adc.c:56
struct SonarAdc sonar_adc
Definition: sonar_adc.c:50
uint16_t meas
Raw ADC value.
Definition: sonar_adc.h:33
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition: adc.h:53
static struct adc_buf sonar_adc_buf
Definition: sonar_adc.c:53
#define SONAR_SCALE
Sonar scale.
Definition: sonar_adc.c:47
API to get/set the generic vehicle states.
simple driver to deal with one sonar sensor on ADC
#define DEFAULT_AV_NB_SAMPLE
Definition: adc.h:41
#define SONAR_OFFSET
Sonar offset.
Definition: sonar_adc.c:40