Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
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 "modules/core/abi.h"
#include <pthread.h>
#include <unistd.h>
#include "modules/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   50
 SONAR_BEBOP_PEAK_THRESHOLD minimum samples from broadcast stop. More...
 
#define SONAR_BEBOP_MIN_PEAK_VAL   512
 SONAR_BEBOP_MIN_PEAK_VAL minimum adc value of reflected peak that will be cosidered. More...
 
#define SONAR_BEBOP_MAX_TRANS_TIME   370
 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)
 
void sonar_bebop_event (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
 
static pthread_mutex_t sonar_mutex = PTHREAD_MUTEX_INITIALIZER
 
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

◆ SONAR_BEBOP_ADC_BUFFER_SIZE

#define SONAR_BEBOP_ADC_BUFFER_SIZE   8192

SONAR_BEBOP_ADC_BUFFER_SIZE ADC buffer size.

Definition at line 59 of file sonar_bebop.c.

◆ SONAR_BEBOP_ADC_MAX_VALUE

#define SONAR_BEBOP_ADC_MAX_VALUE   4095

SONAR_BEBOP_ADC_MAX_VALUE maximum ADC output (12 bit ADC)

Definition at line 56 of file sonar_bebop.c.

◆ SONAR_BEBOP_INX_DIFF_TO_DIST

#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 53 of file sonar_bebop.c.

◆ SONAR_BEBOP_MAX_TRANS_TIME

#define SONAR_BEBOP_MAX_TRANS_TIME   370

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

Definition at line 95 of file sonar_bebop.c.

◆ SONAR_BEBOP_MIN_PEAK_VAL

#define SONAR_BEBOP_MIN_PEAK_VAL   512

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

Definition at line 91 of file sonar_bebop.c.

◆ SONAR_BEBOP_PEAK_THRESHOLD

#define SONAR_BEBOP_PEAK_THRESHOLD   50

SONAR_BEBOP_PEAK_THRESHOLD minimum samples from broadcast stop.

Definition at line 86 of file sonar_bebop.c.

◆ SONAR_BEBOP_TRANSITION_COUNT

#define SONAR_BEBOP_TRANSITION_COUNT   7

SONAR_BEBOP_TRANSITION_COUNT number of samples before switching mode.

Definition at line 79 of file sonar_bebop.c.

◆ SONAR_BEBOP_TRANSITION_HIGH_TO_LOW

#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 69 of file sonar_bebop.c.

◆ SONAR_BEBOP_TRANSITION_LOW_TO_HIGH

#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 74 of file sonar_bebop.c.

Function Documentation

◆ sonar_bebop_event()

void sonar_bebop_event ( void  )

◆ sonar_bebop_init()

◆ sonar_bebop_read()

Variable Documentation

◆ adc_buffer

Definition at line 175 of file sonar_bebop.c.

Referenced by sonar_bebop_read().

◆ mode

◆ pulse_transition_counter

uint8_t pulse_transition_counter
static

Definition at line 82 of file sonar_bebop.c.

Referenced by sonar_bebop_init(), and sonar_bebop_read().

◆ sonar_bebop

struct SonarBebop sonar_bebop

Definition at line 101 of file sonar_bebop.c.

Referenced by sonar_bebop_event(), sonar_bebop_init(), and sonar_bebop_read().

◆ sonar_bebop_spi_d

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 101 of file sonar_bebop.c.

Referenced by sonar_bebop_init(), and sonar_bebop_read().

◆ sonar_bebop_spi_t

struct spi_transaction sonar_bebop_spi_t
static

Definition at line 101 of file sonar_bebop.c.

Referenced by sonar_bebop_init(), and sonar_bebop_read().

◆ sonar_bebop_spike_timer

uint32_t sonar_bebop_spike_timer

Definition at line 48 of file sonar_bebop.c.

Referenced by sonar_bebop_init().

◆ sonar_filt

struct MedianFilterFloat sonar_filt

Definition at line 1 of file sonar_bebop.c.

Referenced by sonar_bebop_init(), sonar_bebop_read(), sonar_pwm_init(), and sonar_pwm_read().

◆ sonar_mutex

pthread_mutex_t sonar_mutex = PTHREAD_MUTEX_INITIALIZER
static

Definition at line 111 of file sonar_bebop.c.

Referenced by sonar_bebop_event(), sonar_bebop_init(), and sonar_bebop_read().