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
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 "pprzlink/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 {
58  sonar_adc.meas = 0;
60 
61 #ifndef SITL
63 #endif
64 }
65 
68 void sonar_adc_read(void)
69 {
70 #ifndef SITL
73 #else // SITL
75  Bound(sonar_adc.distance, 0.1f, 7.0f);
76 #endif // SITL
77 
78  // Send ABI message
79  AbiSendMsgAGL(AGL_SONAR_ADC_ID, sonar_adc.distance);
80 
81 #ifdef SENSOR_SYNC_SEND_SONAR
82  // Send Telemetry report
83  DOWNLINK_SEND_SONAR(DefaultChannel, DefaultDevice, &sonar_adc.meas, &sonar_adc.distance);
84 #endif
85 }
86 
uint8_t av_nb_sample
Definition: adc.h:57
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
#define AGL_SONAR_ADC_ID
float distance
Distance measured in meters.
Definition: sonar_adc.h:35
Main include for ABI (AirBorneInterface).
uint16_t meas
Raw ADC value.
Definition: sonar_adc.h:33
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
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
Definition: state.h:713
void sonar_adc_read(void)
Read ADC value to update sonar measurement.
Definition: sonar_adc.c:68
arch independent ADC (Analog to Digital Converter) API
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition: adc.h:53
void sonar_adc_init(void)
Definition: sonar_adc.c:56
struct SonarAdc sonar_adc
Definition: sonar_adc.c:50
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.
float z
in meters
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
uint16_t offset
Sonar offset in ADC units.
Definition: sonar_adc.h:34