32 #include "pprzlink/messages.h"
35 #if PERIODIC_TELEMETRY
39 #ifndef USE_AIRSPEED_SDP3X
41 #define USE_AIRSPEED_SDP3X TRUE
42 PRINT_CONFIG_MSG(
"USE_AIRSPEED_SDP3X set to TRUE since this is set USE_AIRSPEED")
48 #ifndef USE_AIRSPEED_LOWPASS_FILTER
49 #define USE_AIRSPEED_LOWPASS_FILTER TRUE
54 #define SDP3X_SCALE_TEMPERATURE 200.0f
55 #define SDP3X_RESET_ADDR 0x00
56 #define SDP3X_RESET_CMD 0x06
58 #define SDP3X_CONT_MEAS_AVG_MODE 0x3615
59 #define SDP3X_CONT_NONE_MODE 0x361E
61 #define SDP3X_SCALE_PRESSURE_SDP31 60
62 #define SDP3X_SCALE_PRESSURE_SDP32 240
63 #define SDP3X_SCALE_PRESSURE_SDP33 20
67 #ifndef SDP3X_I2C_ADDR
68 #define SDP3X_I2C_ADDR 0x42
74 #define SDP3X_MODE SDP3X_CONT_MEAS_AVG_MODE
79 #ifndef SDP3X_PRESSURE_SCALE
80 #define SDP3X_PRESSURE_SCALE SDP3X_SCALE_PRESSURE_SDP31
85 #ifndef SDP3X_PRESSURE_OFFSET
86 #define SDP3X_PRESSURE_OFFSET 0.f
95 #ifndef SDP3X_SYNC_SEND
96 #define SDP3X_SYNC_SEND FALSE
104 #ifndef SDP3X_AIRSPEED_SCALE
105 #define SDP3X_AIRSPEED_SCALE 1.6327
111 #ifndef SDP3X_LOWPASS_TAU
112 #define SDP3X_LOWPASS_TAU 0.15
118 #ifdef USE_AIRSPEED_LOWPASS_FILTER
127 for (
unsigned i = 0; i < size; i++) {
128 crc_value ^= (data[i]);
130 for (
int bit = 8; bit > 0; --bit) {
131 if (crc_value & 0x80) {
132 crc_value = (crc_value << 1) ^ 0x31;
135 crc_value = (crc_value << 1);
141 return (crc_value == checksum);
147 pprz_msg_send_AIRSPEED_MS45XX(trans,dev,AC_ID,
167 #ifdef USE_AIRSPEED_LOWPASS_FILTER
169 SDP3X_PERIODIC_PERIOD, 0);
172 #if PERIODIC_TELEMETRY
196 #define AUTOSET_NB_MAX 20
204 static int autoset_nb = 0;
205 static float autoset_offset = 0.f;
207 for (
uint8_t i = 0; i < 6; i++) {
222 #ifdef USE_AIRSPEED_LOWPASS_FILTER
234 autoset_offset = 0.f;
250 #if USE_AIRSPEED_SDP3X
#define SDP3X_LOWPASS_TAU
Time constant for second order Butterworth low pass filter Default of 0.15 should give cut-off freq o...
#define SDP3X_PRESSURE_SCALE
Default scale for SDP31.
static float update_butterworth_2_low_pass(Butterworth2LowPass *filter, float value)
Update second order Butterworth low pass filter state with a new value.
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
bool initialized
init flag
static void init_butterworth_2_low_pass(Butterworth2LowPass *filter, float tau, float sample_time, float value)
Init a second order Butterworth filter.
#define SDP3X_AIRSPEED_SCALE
Quadratic scale factor for indicated airspeed.
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
static Butterworth2LowPass sdp3x_filter
transaction successfully finished by I2C driver
Periodic telemetry system header (includes downlink utility and generated code).
bool sync_send
Flag to enable sending every new measurement via telemetry for debugging purpose. ...
Simple first order low pass filter with bilinear transform.
Main include for ABI (AirBorneInterface).
Airspeed driver for the SDP3X pressure sensor via I2C.
float temperature
Temperature in deg Celcius.
float airspeed
Airspeed in m/s estimated from (differential) pressure.
static void sdp3x_downlink(struct transport_tx *trans, struct link_device *dev)
transaction set to done by user level
float pressure_offset
Offset in Pascal.
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
float pressure
(differential) pressure in Pascal
#define DefaultPeriodic
Set default periodic telemetry.
struct AirspeedSdp3x sdp3x
#define SDP3X_MODE
Default operation mode.
void sdp3x_periodic(void)
I2C transaction structure.
#define SDP3X_SYNC_SEND
Send a AIRSPEED_MS45XX message with every new measurement.
enum I2CTransactionStatus status
Transaction status.
#define SDP3X_PRESSURE_OFFSET
bool i2c_transmit(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len)
Submit a write only transaction.
static const struct usb_device_descriptor dev
static bool sdp3x_crc(const uint8_t data[], unsigned size, uint8_t checksum)
float airspeed_scale
Quadratic scale factor to convert (differential) pressure to airspeed.
bool i2c_receive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint16_t len)
Submit a read only transaction.
#define AIRSPEED_SDP3X_ID
Common code for AP and FBW telemetry.
static struct i2c_transaction sdp3x_trans
float pressure_scale
Scaling factor from raw measurement to Pascal.
#define SDP3X_SCALE_TEMPERATURE
Commands and scales.
Second order low pass filter structure.
#define SDP3X_I2C_ADDR
Sensor I2C slave address (existing defaults 0x42, 0x44 and 0x46)
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
bool autoset_offset
Set offset value from current filtered value.
Architecture independent I2C (Inter-Integrated Circuit Bus) API.