Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
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 "modules/core/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 
50 struct SonarAdc sonar_adc;
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  uint32_t now_ts = get_sys_time_usec();
80  AbiSendMsgAGL(AGL_SONAR_ADC_ID, now_ts, sonar_adc.distance);
81 
82 #ifdef SENSOR_SYNC_SEND_SONAR
83  // Send Telemetry report
84  DOWNLINK_SEND_SONAR(DefaultChannel, DefaultDevice, &sonar_adc.meas, &sonar_adc.distance);
85 #endif
86 }
87 
Main include for ABI (AirBorneInterface).
#define AGL_SONAR_ADC_ID
arch independent ADC (Analog to Digital Converter) API
uint32_t sum
Definition: adc.h:54
#define DEFAULT_AV_NB_SAMPLE
Definition: adc.h:41
uint8_t av_nb_sample
Definition: adc.h:57
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition: adc.h:53
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.
Definition: sys_time_arch.c:71
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
Definition: state.h:719
float z
in meters
static struct adc_buf sonar_adc_buf
Definition: sonar_adc.c:53
void sonar_adc_init(void)
Definition: sonar_adc.c:56
struct SonarAdc sonar_adc
Definition: sonar_adc.c:50
#define SONAR_SCALE
Sonar scale.
Definition: sonar_adc.c:47
void sonar_adc_read(void)
Read ADC value to update sonar measurement.
Definition: sonar_adc.c:68
#define SONAR_OFFSET
Sonar offset.
Definition: sonar_adc.c:40
simple driver to deal with one sonar sensor on ADC
uint16_t offset
Sonar offset in ADC units.
Definition: sonar_adc.h:34
uint16_t meas
Raw ADC value.
Definition: sonar_adc.h:33
float distance
Distance measured in meters.
Definition: sonar_adc.h:35
API to get/set the generic vehicle states.
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78