Paparazzi UAS  v5.15_devel-81-gd13dafb
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
sonar_bebop.c File Reference

Parrot Bebop Sonar driver. More...

#include "sonar_bebop.h"
#include "generated/airframe.h"
#include "mcu_periph/adc.h"
#include "mcu_periph/spi.h"
#include "mcu_periph/sys_time.h"
#include "subsystems/abi.h"
#include <pthread.h>
#include <unistd.h>
#include "subsystems/datalink/downlink.h"
#include "filters/median_filter.h"
+ Include dependency graph for sonar_bebop.c:

Go to the source code of this file.

Macros

#define SONAR_BEBOP_INX_DIFF_TO_DIST   340./(2.*160000.)
 SONAR_BEBOP_INX_DIFF_TO_DIST conversion from index difference to distance based on time of flight ADC speed = 160kHz speed of sound = 340m/s. More...
 
#define SONAR_BEBOP_ADC_MAX_VALUE   4095
 SONAR_BEBOP_ADC_MAX_VALUE maximum ADC output (12 bit ADC) More...
 
#define SONAR_BEBOP_ADC_BUFFER_SIZE   8192
 SONAR_BEBOP_ADC_BUFFER_SIZE ADC buffer size. More...
 
#define SONAR_BEBOP_TRANSITION_HIGH_TO_LOW   0.8
 SONAR_BEBOP_TRANSITION_HIGH_TO_LOW below this altitude we should use mode 0. More...
 
#define SONAR_BEBOP_TRANSITION_LOW_TO_HIGH   1.2
 SONAR_BEBOP_TRANSITION_LOW_TO_HIGH above this altitude we should use mode 1. More...
 
#define SONAR_BEBOP_TRANSITION_COUNT   7
 SONAR_BEBOP_TRANSITION_COUNT number of samples before switching mode. More...
 
#define SONAR_BEBOP_PEAK_THRESHOLD   100
 SONAR_BEBOP_PEAK_THRESHOLD minimum samples from broadcast stop. More...
 
#define SONAR_BEBOP_MIN_PEAK_VAL   1024
 SONAR_BEBOP_MIN_PEAK_VAL minimum adc value of reflected peak that will be cosidered. More...
 
#define SONAR_BEBOP_MAX_TRANS_TIME   270
 SONAR_BEBOP_MAX_TRANS_TIME maximum time for a reflection to travel and return in the adc measurement window. More...
 

Functions

void * sonar_bebop_read (void *data)
 sonar_bebop_read Read ADC value to update sonar measurement More...
 
void sonar_bebop_init (void)
 

Variables

struct MedianFilterFloat sonar_filt
 
uint32_t sonar_bebop_spike_timer
 
static uint8_t mode
 mode holds the current sonar mode mode = 0 used at high altitude, uses 16 wave patterns mode = 1 used at low altitude, uses 4 wave patterns More...
 
static uint8_t pulse_transition_counter
 
static uint8_t sonar_bebop_spi_d [2][16]
 sonar_bebop_spi_d the waveforms emitted by the sonar waveform 0 is long pulse used at high altitude waveform 1 is shorter pulse used at low altitude More...
 
struct SonarBebop sonar_bebop
 
static struct spi_transaction sonar_bebop_spi_t
 
uint16_t adc_buffer [SONAR_BEBOP_ADC_BUFFER_SIZE]
 

Detailed Description

Parrot Bebop Sonar driver.

This file contains the ADC driver for the sonar on the Parrot Bebop and Bebop 2 quadrotors. The sonar is both transmitter and receiver. An SPI interface is used to communicate with the 12 bit ADC which operates at 160kHz. The required waveform of the sonar is sent during the SPI transaction, with the returned data the recorded signal from the sonar. Two waveforms have been implemented dependent on the operating altitude of the Bebop.

Definition in file sonar_bebop.c.

Macro Definition Documentation

#define SONAR_BEBOP_ADC_BUFFER_SIZE   8192

SONAR_BEBOP_ADC_BUFFER_SIZE ADC buffer size.

Definition at line 63 of file sonar_bebop.c.

Referenced by sonar_bebop_read().

#define SONAR_BEBOP_ADC_MAX_VALUE   4095

SONAR_BEBOP_ADC_MAX_VALUE maximum ADC output (12 bit ADC)

Definition at line 60 of file sonar_bebop.c.

Referenced by sonar_bebop_read().

#define SONAR_BEBOP_INX_DIFF_TO_DIST   340./(2.*160000.)

SONAR_BEBOP_INX_DIFF_TO_DIST conversion from index difference to distance based on time of flight ADC speed = 160kHz speed of sound = 340m/s.

Definition at line 57 of file sonar_bebop.c.

Referenced by sonar_bebop_read().

#define SONAR_BEBOP_MAX_TRANS_TIME   270

SONAR_BEBOP_MAX_TRANS_TIME maximum time for a reflection to travel and return in the adc measurement window.

Definition at line 89 of file sonar_bebop.c.

Referenced by sonar_bebop_read().

#define SONAR_BEBOP_MIN_PEAK_VAL   1024

SONAR_BEBOP_MIN_PEAK_VAL minimum adc value of reflected peak that will be cosidered.

Definition at line 86 of file sonar_bebop.c.

Referenced by sonar_bebop_read().

#define SONAR_BEBOP_PEAK_THRESHOLD   100

SONAR_BEBOP_PEAK_THRESHOLD minimum samples from broadcast stop.

Definition at line 83 of file sonar_bebop.c.

Referenced by sonar_bebop_read().

#define SONAR_BEBOP_TRANSITION_COUNT   7

SONAR_BEBOP_TRANSITION_COUNT number of samples before switching mode.

Definition at line 78 of file sonar_bebop.c.

Referenced by sonar_bebop_read().

#define SONAR_BEBOP_TRANSITION_HIGH_TO_LOW   0.8

SONAR_BEBOP_TRANSITION_HIGH_TO_LOW below this altitude we should use mode 0.

Definition at line 72 of file sonar_bebop.c.

Referenced by sonar_bebop_read().

#define SONAR_BEBOP_TRANSITION_LOW_TO_HIGH   1.2

SONAR_BEBOP_TRANSITION_LOW_TO_HIGH above this altitude we should use mode 1.

Definition at line 75 of file sonar_bebop.c.

Referenced by sonar_bebop_read().

Function Documentation

Variable Documentation

Definition at line 136 of file sonar_bebop.c.

Referenced by sonar_bebop_read().

uint8_t mode
static

mode holds the current sonar mode mode = 0 used at high altitude, uses 16 wave patterns mode = 1 used at low altitude, uses 4 wave patterns

Definition at line 69 of file sonar_bebop.c.

Referenced by atmega_i2c_cam_ctrl_send(), dc_info(), lis3mdl_init(), mavlink_common_message_handler(), nav_throttle_curve_set(), parse_rc_3ch_datalink(), parseFormationSlot(), periodic_telemetry_err_report(), rotorcraft_cam_set_mode(), sdio_connect(), sonar_bebop_init(), sonar_bebop_read(), throttle_curve_run(), and uart_periph_set_mode().

uint8_t pulse_transition_counter
static

Definition at line 80 of file sonar_bebop.c.

Referenced by sonar_bebop_init(), and sonar_bebop_read().

struct SonarBebop sonar_bebop

Definition at line 97 of file sonar_bebop.c.

Referenced by sonar_bebop_init(), and sonar_bebop_read().

uint8_t sonar_bebop_spi_d[2][16]
static
Initial value:
= {{ 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00 }}

sonar_bebop_spi_d the waveforms emitted by the sonar waveform 0 is long pulse used at high altitude waveform 1 is shorter pulse used at low altitude

Definition at line 95 of file sonar_bebop.c.

Referenced by sonar_bebop_init(), and sonar_bebop_read().

struct spi_transaction sonar_bebop_spi_t
static

Definition at line 99 of file sonar_bebop.c.

Referenced by sonar_bebop_init(), and sonar_bebop_read().

uint32_t sonar_bebop_spike_timer

Definition at line 48 of file sonar_bebop.c.

Referenced by sonar_bebop_init().

struct MedianFilterFloat sonar_filt

Definition at line 47 of file sonar_bebop.c.

Referenced by sonar_bebop_init(), and sonar_bebop_read().