36 #include "generated/airframe.h"
54 #define SONAR_BEBOP_INX_DIFF_TO_DIST 340./(2.*160000.)
57 #define SONAR_BEBOP_ADC_MAX_VALUE 4095
60 #define SONAR_BEBOP_ADC_BUFFER_SIZE 8192
69 #define SONAR_BEBOP_TRANSITION_HIGH_TO_LOW 0.8
72 #define SONAR_BEBOP_TRANSITION_LOW_TO_HIGH 1.2
75 #define SONAR_BEBOP_TRANSITION_COUNT 7
80 #define SONAR_BEBOP_PEAK_THRESHOLD 250
86 static uint8_t sonar_bebop_spi_d[2][16] = {{ 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
87 { 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00 }};
94 static pthread_t sonar_bebop_thread;
156 if (start_send != 0 && stop_send != 0 && first_peak == 0 && adc_val < lowest_value) {
157 lowest_value = adc_val;
158 }
else if (start_send != 0 && stop_send != 0 && adc_val > lowest_value + 100 && adc_val > peak_value) {
160 peak_value = adc_val;
165 uint16_t diff = stop_send - start_send;
170 peak_distance = first_peak - (stop_send - diff / 2);
196 if (peak_distance > 0) {
199 #ifdef SENSOR_SYNC_SEND_SONAR
void adc_enable(struct adc_t *adc, uint8_t value)
Start or stop the ADC readings.
void * sonar_bebop_read(void *data)
sonar_bebop_read Read ADC value to update sonar measurement
int adc_read(struct adc_t *adc, uint16_t *buf, uint16_t size)
Read the ADC buffer from the driver.
uint16_t output_length
number of data words to write
static struct spi_transaction sonar_bebop_spi_t
#define SONAR_BEBOP_ADC_BUFFER_SIZE
SONAR_BEBOP_ADC_BUFFER_SIZE ADC buffer size.
#define SONAR_BEBOP_PEAK_THRESHOLD
SONAR_BEBOP_PEAK_THRESHOLD minimum samples from broadcast stop.
Main include for ABI (AirBorneInterface).
Parrot Bebop Sonar driver.
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 w...
SPI transaction structure.
#define SONAR_BEBOP_INX_DIFF_TO_DIST
SONAR_BEBOP_INX_DIFF_TO_DIST conversion from index difference to distance based on time of flight ADC...
bool spi_submit(struct spi_periph *p, struct spi_transaction *t)
Submit SPI transaction.
#define SONAR_BEBOP_TRANSITION_HIGH_TO_LOW
SONAR_BEBOP_TRANSITION_HIGH_TO_LOW below this altitude we should use mode 0.
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
volatile uint8_t * output_buf
pointer to transmit buffer for DMA
enum SPISlaveSelect select
slave selection behavior
arch independent ADC (Analog to Digital Converter) API
Architecture independent SPI (Serial Peripheral Interface) API.
float distance
Distance measured in meters.
struct MedianFilterFloat sonar_filt
static uint8_t pulse_transition_counter
#define SONAR_BEBOP_TRANSITION_LOW_TO_HIGH
SONAR_BEBOP_TRANSITION_LOW_TO_HIGH above this altitude we should use mode 1.
#define SONAR_BEBOP_TRANSITION_COUNT
SONAR_BEBOP_TRANSITION_COUNT number of samples before switching mode.
uint16_t input_length
number of data words to read
#define SONAR_BEBOP_ADC_MAX_VALUE
SONAR_BEBOP_ADC_MAX_VALUE maximum ADC output (12 bit ADC)
API to get/set the generic vehicle states.
static uint8_t mode
mode holds the current sonar mode mode = 0 used at high altitude, uses 16 wave patterns mode = 1 used...
void sonar_bebop_init(void)
slave is selected before transaction and unselected after
Common code for AP and FBW telemetry.
enum SPIDataSizeSelect dss
data transfer word size
volatile uint8_t * input_buf
pointer to receive buffer for DMA
uint16_t offset
Sonar offset in ADC units.
uint16_t meas
Raw ADC value.
struct SonarBebop sonar_bebop
uint16_t adc_buffer[SONAR_BEBOP_ADC_BUFFER_SIZE]
enum SPITransactionStatus status