27 #include "generated/airframe.h"
32 #ifndef MS_PRESSURE_OFFSET
33 #define MS_PRESSURE_OFFSET 0.0f
35 #ifndef MS_PRESSURE_SCALE
36 #define MS_PRESSURE_SCALE 1.0f
38 #ifndef MS_TEMPERATURE_OFFSET
39 #define MS_TEMPERATURE_OFFSET 0.0f
41 #ifndef MS_TEMPERATURE_SCALE
42 #define MS_TEMPERATURE_SCALE 1.0f
44 #ifndef MS_HUMIDTY_OFFSET
45 #define MS_HUMIDTY_OFFSET 0.0f
47 #ifndef MS_HUMIDTY_SCALE
48 #define MS_HUMIDTY_SCALE 1.0f
50 #ifndef MS_DIFF_PRESSURE_OFFSET
51 #define MS_DIFF_PRESSURE_OFFSET 0.0f
53 #ifndef MS_DIFF_PRESSURE_SCALE
54 #define MS_DIFF_PRESSURE_SCALE 1.0f
58 #ifdef MS_PRESSURE_SLAVE_IDX
59 #ifndef USE_MS_PRESSURE
60 #define USE_MS_PRESSURE TRUE
65 #ifdef MS_DIFF_PRESSURE_SLAVE_IDX
66 #ifndef USE_MS_DIFF_PRESSURE
67 #define USE_MS_DIFF_PRESSURE TRUE
72 #ifdef MS_TEMPERATURE_SLAVE_IDX
73 #ifndef USE_MS_TEMPERATURE
74 #define USE_MS_TEMPERATURE TRUE
80 #ifndef MS_EEPROM_SLAVE_IDX
91 static const float maxAdc = 8388608.0f;
95 const float uncal_abs = ((raw /
maxAdc) + 0.095f) / 0.0009f;
106 const float coeff_A = 3.9083e-3f;
107 const float coeff_B = -5.775e-7f;
108 const float R0 = 1000.0f;
110 const float pga_factor = 1.0f;
111 const float Rref = 6.8e3f;
112 const float Rt = (raw * Rref) / (gain_factor * pga_factor *
maxAdc);
113 const float uncal_temp = ((-R0 * coeff_A) + (sqrtf(powf((R0 * coeff_A), 2.0f) +
114 (4.0f * R0 * coeff_B * (Rt - R0))))) / (2.0f * R0 * coeff_B);
126 #define MS_PITOT_COUNTER 20
128 #define MS_PITOT_FILTER 0.6
134 const float uncal_diff = ((raw_diff /
maxAdc) * 5000.f / gain_factor);
145 return sqrtf((2.0f *
get_diff(raw)) / 1.293f);
150 const float icu_freq = 42e6f;
151 const float Ra = 390e3f;
152 const float Rb = 680e3f;
153 const float S1 = 0.3e-12f;
154 const float calib_raw_period = 17800.f;
155 const float calib_humidity = 45.f;
156 const float k = 2.f * logf(2.f) * (Ra + Rb + Rb);
157 const float uncal_hum = calib_humidity + ((raw - calib_raw_period) / (k * icu_freq * S1));
177 bool log_ptu_started;
190 #include "pprzlink/messages.h"
194 #define MS_DATA_SIZE 4
196 static inline void meteo_stick_send_data(
void)
198 float ptu_data[MS_DATA_SIZE];
214 #ifdef MS_PRESSURE_SLAVE_IDX
228 #ifdef MS_DIFF_PRESSURE_SLAVE_IDX
242 #ifdef MS_TEMPERATURE_SLAVE_IDX
280 log_ptu_started =
false;
289 #ifdef MS_PRESSURE_SLAVE_IDX
292 #ifdef MS_DIFF_PRESSURE_SLAVE_IDX
295 #ifdef MS_TEMPERATURE_SLAVE_IDX
299 #ifdef MS_HUMIDITY_PWM_INPUT
324 if (!log_ptu_started) {
331 sdLogWriteLog(
pprzLogFile,
"# Sensor: %d, time: %d, num_temp: %d, num_coeff: %d\n", i,
338 for (j = 0; j <
meteo_stick.calib.params[i].num_temp; j++) {
341 for (k = 0; k <
meteo_stick.calib.params[i].num_coeff; k++) {
349 "P(adc) T(adc) H(ticks) P_diff(adc) P(hPa) T(C) H(\%) CAS(m/s) FIX TOW(ms) WEEK Lat(1e7rad) Lon(1e7rad) HMSL(mm) GS(cm/s) course(1e7rad) VZ(cm/s)\n");
350 log_ptu_started =
true;
354 "P(adc) T(adc) H(ticks) P_diff(adc) P(hPa) T(C) H(\%) CAS(m/s) FIX TOW(ms) WEEK Lat(1e7rad) Lon(1e7rad) HMSL(mm) GS(cm/s) course(1e7rad) VZ(cm/s)\n");
355 log_ptu_started =
true;
358 sdLogWriteLog(
pprzLogFile,
"%d %d %d %d %.2f %.2f %.2f %.2f %d %d %d %d %d %d %d %d %d\n",
372 meteo_stick_send_data();
386 #ifdef MS_PRESSURE_SLAVE_IDX
389 #ifdef MS_DIFF_PRESSURE_SLAVE_IDX
392 #ifdef MS_TEMPERATURE_SLAVE_IDX
396 #ifdef MS_PRESSURE_SLAVE_IDX
407 #ifdef MS_DIFF_PRESSURE_SLAVE_IDX
420 #if USE_MS_DIFF_PRESSURE
430 #ifdef MS_TEMPERATURE_SLAVE_IDX
434 #if USE_MS_TEMPERATURE
void meteo_stick_event(void)
Event function.
struct MeteoStick meteo_stick
General structure.
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
enum Ads1220ConvMode conv
conversion mode
static const float maxAdc
Prescaling of data according to datasheets.
static float get_humidity(uint32_t raw)
void eeprom25AA256_init(struct Eeprom25AA256 *eeprom, struct spi_periph *spi_p, uint8_t slave_idx)
Init function.
void eeprom25AA256_read(struct Eeprom25AA256 *eeprom, uint16_t addr, uint16_t length)
Read function.
void ads1220_event(struct Ads1220 *ads)
enum Ads1220Imux i2mux
IDAC routing 2.
static float get_pitot(uint32_t raw)
float current_temperature
calibrated temperature
volatile bool data_available
data ready flag
enum Ads1220Mux mux
input multiplexer
#define MS_HUMIDTY_OFFSET
struct Ads1220 pressure
absolute pressure
struct Ads1220 temperature
temperature
Main include for ABI (AirBorneInterface).
bool mtostk_populate_cal_from_buffer(Calibration_params *cp, uint8_t *_eeprom_buffer)
Initializes a Calibration_params structure from memory buffer.
static float pitot_offset
static float get_temp(uint32_t raw)
void eeprom25AA256_event(struct Eeprom25AA256 *eeprom)
Event function.
#define METEO_STICK_SENDER_ID
uint32_t humidity_period
humidity (in ticks)
#define MS_TEMPERATURE_OFFSET
struct Ads1220Config config
configuration
struct Ads1220 diff_pressure
differential pressure
float mtostk_get_calibrated_value(Calibration_params *cp, Mtostk_sensors type, float uncal, float temp)
get calibrated value for a sensor according to current temperature
static float get_pressure(uint32_t raw)
void meteo_stick_periodic(void)
Periodic function.
Driver for the ADS1220 24-bits ADC from TI SPI communication.
enum Ads1220Gain gain
gain
int32_t hmsl
height above mean sea level (MSL) in mm
bool pga_bypass
bypass PGA (PGA enabled = 0)
enum Ads1220VRef vref
voltage ref
uint32_t tow
GPS time of week in ms.
Device independent GPS code (interface)
float current_humidity
calibrated humidity
void meteo_stick_init(void)
Init function.
#define MS_TEMPERATURE_SCALE
#define MS_DIFF_PRESSURE_OFFSET
int32_t lon
in degrees*1e7
float current_airspeed
calibrated airspeed
float current_pressure
calibrated pressure
#define MS_DIFF_PRESSURE_SCALE
enum Ads1220SampleRate rate
data output rate
bool reset_dp_offset
reset differential pressure offset
static void ads1220_periodic(struct Ads1220 *ads)
convenience function: read or start configuration if not already initialized
int32_t course
GPS course over ground in rad*1e7, [0, 2*Pi]*1e7 (CW/north)
static const float Ads1220GainTable[]
uint32_t data
raw ADC value
enum Ads1220Idac idac
IDAC config.
void ads1220_init(struct Ads1220 *ads, struct spi_periph *spi_p, uint8_t slave_idx)
Common code for AP and FBW telemetry.
#define MS_PRESSURE_SCALE
uint16_t gspeed
norm of 2d ground speed in cm/s
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
enum Ads1220Imux i1mux
IDAC routing 1.
Data acquisition module for ENAC PTU board.
int32_t lat
in degrees*1e7
static float get_diff(uint32_t raw)
struct NedCoor_i ned_vel
speed NED in cm/s
struct GpsState gps
global GPS state
#define MS_PRESSURE_OFFSET
Default scale and offset Only used if calibration from EEPROM is not used/available.