27#include "generated/airframe.h"
30#if defined(SITL) || (defined(SONAR_ADC_COMPENSATE_ROTATION) && (SONAR_ADC_COMPENSATE_ROTATION == 1))
35#include "pprzlink/messages.h"
38#if defined(SENSOR_SYNC_SEND_SONAR) && (!defined(SONAR_ADC_SYNC_SEND))
39#define SONAR_ADC_SYNC_SEND 1
42#ifdef SONAR_ADC_SYNC_SEND
48#error sonar_adc module error: please add and configure SONAR_ADC_PORT, the port your sensor is connected to e.g. ADC_3 and save in your airframe file.
52#include "mcu_periph/adc.h"
57#ifndef SONAR_ADC_MIN_RANGE
58#define SONAR_ADC_MIN_RANGE 0.24f
62#ifndef SONAR_ADC_MAX_RANGE
63#define SONAR_ADC_MAX_RANGE 4.0f
67#ifndef SONAR_ADC_RAW_OFFSET
68#define SONAR_ADC_RAW_OFFSET 0
73#ifndef SONAR_ADC_OFFSET
74#define SONAR_ADC_OFFSET 0.0f
78#ifndef SONAR_ADC_USE_FILTER
79#define SONAR_ADC_USE_FILTER 1
83#ifndef USE_SONAR_ADC_AGL
84#define USE_SONAR_ADC_AGL 0
87#ifdef SONAR_ADC_USE_FILTER
89#ifndef SONAR_ADC_LOWPASS_TAU
90#define SONAR_ADC_LOWPASS_TAU 0.16
96#ifndef SONAR_ADC_COMPENSATE_ROTATION
97#define SONAR_ADC_COMPENSATE_ROTATION 0
103#ifndef SONAR_ADC_SCALE
104#define SONAR_ADC_SCALE 0.001855f
129#ifdef SONAR_ADC_USE_FILTER
133#if PERIODIC_TELEMETRY
156#ifdef SONAR_ADC_USE_FILTER
166#if SONAR_ADC_COMPENSATE_ROTATION
169 float gain =
cosf(phi) *
cosf(theta);
198#if SONAR_ADC_SYNC_SEND
209#if SONAR_ADC_SYNC_SEND
Main include for ABI (AirBorneInterface).
#define DEFAULT_AV_NB_SAMPLE
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
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.
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Common code for AP and FBW telemetry.
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
Simple first order low pass filter with bilinear transform.
static void init_butterworth_2_low_pass(Butterworth2LowPass *filter, float tau, float sample_time, float value)
Init a second order Butterworth filter.
static float update_butterworth_2_low_pass(Butterworth2LowPass *filter, float value)
Update second order Butterworth low pass filter state with a new value.
Second order low pass filter structure.
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
static struct adc_buf sonar_adc_buf
#define SONAR_ADC_SCALE
Scale Sensor sensitivity in m/adc (float)
static Butterworth2LowPass sonar_filt
#define SONAR_ADC_RAW_OFFSET
Sonar offset in ADC units.
void sonar_adc_init(void)
void sonar_adc_report(void)
Debug report Option to send debug informative values over telemetry.
#define SONAR_ADC_OFFSET
Rangefinder distance offset value for what should be considered zero distance, e.g.
struct SonarADC sonar_adc
static void sonar_adc_send_sonar(struct transport_tx *trans, struct link_device *dev)
Sending Send measured value and status information so it can be read back in e.g.
#define SONAR_ADC_LOWPASS_TAU
#define SONAR_ADC_MIN_RANGE
The minimum chosen distance for the device to be give readings.
void sonar_adc_periodic(void)
Reading Read ADC value to update sonar measurement.
#define USE_SONAR_ADC_AGL
Option to send AGL data over ABI.
#define SONAR_ADC_MAX_RANGE
The maximum chosen distance for the device to be give readings.
Driver for an sonar rangfinder sensor when used via an ADC channel.
float scale
Scaling factor to convert raw value to a distance in SI unit (meters)
uint16_t raw
raw measuread non scaled range value from sensor
float distance
Distance measured in meters.
bool update_agl
Do or don't update AGL ABI message.
API to get/set the generic vehicle states.
static const struct usb_device_descriptor dev
int16_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint16_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.