35 #include "pprzlink/messages.h"
38 #if PERIODIC_TELEMETRY
42 #ifndef USE_AIRSPEED_MS45XX
44 #define USE_AIRSPEED_MS45XX TRUE
45 PRINT_CONFIG_MSG(
"USE_AIRSPEED_MS45XX set to TRUE since this is set USE_AIRSPEED")
49 #if USE_AIRSPEED_MS45XX
55 #ifndef MS45XX_I2C_DEV
56 #define MS45XX_I2C_DEV i2c2
61 #ifndef MS45XX_I2C_ADDR
62 #define MS45XX_I2C_ADDR 0x50
68 #ifndef MS45XX_PRESSURE_OUTPUT_TYPE_InH2O
69 #define MS45XX_PRESSURE_OUTPUT_TYPE_InH2O 0
76 #ifndef MS45XX_PRESSURE_RANGE
77 #define MS45XX_PRESSURE_RANGE 1
82 #ifndef MS45XX_PRESSURE_TYPE
83 #define MS45XX_PRESSURE_TYPE 0
88 #ifndef USE_AIRSPEED_LOWPASS_FILTER
89 #define USE_AIRSPEED_LOWPASS_FILTER TRUE
96 #ifndef MS45XX_OUTPUT_TYPE
97 #define MS45XX_OUTPUT_TYPE 0
101 #define InH2O_TO_PA 249.08891
104 #define PSI_TO_PA 6894.75729
106 #if MS45XX_PRESSURE_OUTPUT_TYPE_InH2O
107 #define OutputPressureToPa InH2O_TO_PA
109 #define OutputPressureToPa PSI_TO_PA
112 #if MS45XX_OUTPUT_TYPE == 0
123 #ifndef MS45XX_PRESSURE_SCALE
124 #define MS45XX_PRESSURE_SCALE (2 * MS45XX_PRESSURE_RANGE / (0.8 * 16383) * OutputPressureToPa)
126 #ifndef MS45XX_PRESSURE_OFFSET
127 #define MS45XX_PRESSURE_OFFSET (1.25 * MS45XX_PRESSURE_RANGE * OutputPressureToPa)
133 #ifndef MS45XX_PRESSURE_SCALE
134 #define MS45XX_PRESSURE_SCALE (MS45XX_PRESSURE_RANGE/(0.9*16383)*OutputPressureToPa)
136 #ifndef MS45XX_PRESSURE_OFFSET
137 #define MS45XX_PRESSURE_OFFSET (((MS45XX_PRESSURE_RANGE*0.05*16383)/(0.9*16383))*OutputPressureToPa)
150 #ifndef MS45XX_SYNC_SEND
151 #define MS45XX_SYNC_SEND FALSE
159 #ifndef MS45XX_AIRSPEED_SCALE
160 #define MS45XX_AIRSPEED_SCALE 1.6327
166 #ifndef MS45XX_LOWPASS_TAU
167 #define MS45XX_LOWPASS_TAU 0.15
172 #ifdef USE_AIRSPEED_LOWPASS_FILTER
178 pprz_msg_send_AIRSPEED_MS45XX(trans,dev,AC_ID,
197 #ifdef USE_AIRSPEED_LOWPASS_FILTER
199 MS45XX_I2C_PERIODIC_PERIOD, 0);
202 #if PERIODIC_TELEMETRY
215 #define AUTOSET_NB_MAX 20
219 static int autoset_nb = 0;
220 static float autoset_offset = 0.f;
253 autoset_offset = 0.f;
262 temp_raw = temp_raw >> 5;
276 #if USE_AIRSPEED_MS45XX
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
static void init_butterworth_2_low_pass(Butterworth2LowPass *filter, float tau, float sample_time, float value)
Init a second order Butterworth filter.
#define MS45XX_I2C_ADDR
Sensor I2C slave address (existing defaults 0x50, 0x6C and 0x8C)
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
transaction successfully finished by I2C driver
int16_t temperature
Temperature in 0.1 deg Celcius.
Periodic telemetry system header (includes downlink utility and generated code).
Simple first order low pass filter with bilinear transform.
bool pressure_type
Pressure type Differential of Gauge.
void ms45xx_i2c_init(void)
Main include for ABI (AirBorneInterface).
struct AirspeedMs45xx ms45xx
bool autoset_offset
Set offset value from current filtered value.
float pressure
(differential) pressure in Pascal
#define MS45XX_PRESSURE_OFFSET
bool sync_send
Flag to enable sending every new measurement via telemetry for debugging purpose. ...
#define MS45XX_PRESSURE_TYPE
Pressure Type 0 = Differential, 1 = Gauge note there are theoretical more types than 2...
void ms45xx_i2c_event(void)
float airspeed
Airspeed in m/s estimated from (differential) pressure.
transaction set to done by user level
#define MS45XX_AIRSPEED_SCALE
Quadratic scale factor for indicated airspeed.
static Butterworth2LowPass ms45xx_filter
float pressure_scale
Scaling factor from raw measurement to Pascal.
float airspeed_scale
Quadratic scale factor to convert (differential) pressure to airspeed.
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
#define MS45XX_SYNC_SEND
Send a AIRSPEED_MS45XX message with every new measurement.
#define DefaultPeriodic
Set default periodic telemetry.
float pressure_offset
Offset in Pascal.
I2C transaction structure.
enum I2CTransactionStatus status
Transaction status.
static const struct usb_device_descriptor dev
#define MS45XX_OUTPUT_TYPE
MS45xx output Type.
API to get/set the generic vehicle states.
static struct i2c_transaction ms45xx_trans
Airspeed driver for the MS45xx pressure sensor via I2C.
static void stateSetAirspeed_f(float airspeed)
Set airspeed (float).
bool i2c_receive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint16_t len)
Submit a read only transaction.
Common code for AP and FBW telemetry.
#define USE_AIRSPEED_LOWPASS_FILTER
Use low pass filter on pressure values.
#define MS45XX_PRESSURE_RANGE
MS45xx pressure range in PSI or InH2O The sensor is available in many ranges, the datasheet of your p...
Second order low pass filter structure.
#define MS45XX_I2C_DEV
Default I2C device.
void ms45xx_i2c_periodic(void)
#define MS45XX_LOWPASS_TAU
Time constant for second order Butterworth low pass filter Default of 0.15 should give cut-off freq o...
#define MS45XX_PRESSURE_SCALE
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
static void ms45xx_downlink(struct transport_tx *trans, struct link_device *dev)
Architecture independent I2C (Inter-Integrated Circuit Bus) API.