28#include "generated/airframe.h"
29#include "pprzlink/messages.h"
35#ifndef MS_PRESSURE_OFFSET
36#define MS_PRESSURE_OFFSET 0.0f
38#ifndef MS_PRESSURE_SCALE
39#define MS_PRESSURE_SCALE 1.0f
41#ifndef MS_TEMPERATURE_OFFSET
42#define MS_TEMPERATURE_OFFSET 0.0f
44#ifndef MS_TEMPERATURE_SCALE
45#define MS_TEMPERATURE_SCALE 1.0f
47#ifndef MS_HUMIDTY_OFFSET
48#define MS_HUMIDTY_OFFSET 0.0f
50#ifndef MS_HUMIDTY_SCALE
51#define MS_HUMIDTY_SCALE 1.0f
53#ifndef MS_DIFF_PRESSURE_OFFSET
54#define MS_DIFF_PRESSURE_OFFSET 0.0f
56#ifndef MS_DIFF_PRESSURE_SCALE
57#define MS_DIFF_PRESSURE_SCALE 1.0f
61#ifdef MS_PRESSURE_SLAVE_IDX
62#ifndef USE_MS_PRESSURE
63#define USE_MS_PRESSURE TRUE
68#ifdef MS_DIFF_PRESSURE_SLAVE_IDX
69#ifndef USE_MS_DIFF_PRESSURE
70#define USE_MS_DIFF_PRESSURE TRUE
75#ifdef MS_TEMPERATURE_SLAVE_IDX
76#ifndef USE_MS_TEMPERATURE
77#define USE_MS_TEMPERATURE TRUE
83#ifndef MS_EEPROM_SLAVE_IDX
94static const float maxAdc = 8388608.0f;
98 const float uncal_abs = ((raw /
maxAdc) + 0.095f) / 0.0009f;
109 const float coeff_A = 3.9083e-3f;
110 const float coeff_B = -5.775e-7f;
111 const float R0 = 1000.0f;
113 const float pga_factor = 1.0f;
114 const float Rref = 6.8e3f;
115 const float Rt = (raw * Rref) / (gain_factor * pga_factor *
maxAdc);
116 const float uncal_temp = ((-R0 * coeff_A) + (sqrtf(powf((R0 * coeff_A), 2.0f) +
117 (4.0f * R0 * coeff_B * (Rt - R0))))) / (2.0f * R0 * coeff_B);
129#define MS_PITOT_COUNTER 20
131#define MS_PITOT_FILTER 0.6
137 const float uncal_diff = ((raw_diff /
maxAdc) * 5000.f / gain_factor);
148 return sqrtf((2.0f *
get_diff(raw)) / 1.293f);
153 const float icu_freq = 42e6f;
154 const float Ra = 390e3f;
155 const float Rb = 680e3f;
156 const float S1 = 0.3e-12f;
157 const float calib_raw_period = 17800.f;
158 const float calib_humidity = 45.f;
159 const float k = 2.f * logf(2.f) * (Ra + Rb + Rb);
160 const float uncal_hum = calib_humidity + ((raw - calib_raw_period) / (k * icu_freq *
S1));
173 pprz_msg_send_METEO_STICK(trans, device, AC_ID,
189#define SEND_MS_SYNC FALSE
204static bool log_ptu_started;
206static inline void meteo_stick_log_data_ascii(
void)
209 if (!log_ptu_started) {
223 for (j = 0; j <
meteo_stick.calib.params[i].num_temp; j++) {
226 for (k = 0; k <
meteo_stick.calib.params[i].num_coeff; k++) {
234 "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");
235 log_ptu_started =
true;
239 "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");
240 log_ptu_started =
true;
249 gps.lla_pos.lat,
gps.lla_pos.lon,
gps.hmsl,
261#ifndef LOG_MS_FLIGHTRECORDER
262#define LOG_MS_FLIGHTRECORDER FALSE
267#define MS_LOG_FILE flightrecorder_sdlog
270#if LOG_MS_FLIGHTRECORDER
275static inline void meteo_stick_log_data_fr(
void)
303#ifdef MS_PRESSURE_SLAVE_IDX
317#ifdef MS_DIFF_PRESSURE_SLAVE_IDX
321 meteo_stick.diff_pressure.config.pga_bypass =
true;
331#ifdef MS_TEMPERATURE_SLAVE_IDX
369 log_ptu_started =
false;
371#if LOG_MS_FLIGHTRECORDER
381#ifdef MS_PRESSURE_SLAVE_IDX
384#ifdef MS_DIFF_PRESSURE_SLAVE_IDX
387#ifdef MS_TEMPERATURE_SLAVE_IDX
391#ifdef MS_HUMIDITY_PWM_INPUT
415 meteo_stick_log_data_ascii();
417#if LOG_MS_FLIGHTRECORDER
418 meteo_stick_log_data_fr();
437#ifdef MS_PRESSURE_SLAVE_IDX
440#ifdef MS_DIFF_PRESSURE_SLAVE_IDX
443#ifdef MS_TEMPERATURE_SLAVE_IDX
447#ifdef MS_PRESSURE_SLAVE_IDX
459#ifdef MS_DIFF_PRESSURE_SLAVE_IDX
472#if USE_MS_DIFF_PRESSURE
482#ifdef MS_TEMPERATURE_SLAVE_IDX
486#if USE_MS_TEMPERATURE
Main include for ABI (AirBorneInterface).
#define TEMPERATURE_TYPE_AIR
Types of the TEMPERATURE_RAW message, what the temperature measures.
#define METEO_STICK_SENDER_ID
void ads1220_event(struct Ads1220 *ads)
void ads1220_init(struct Ads1220 *ads, struct spi_periph *spi_p, uint8_t slave_idx)
Driver for the ADS1220 24-bits ADC from TI SPI communication.
@ ADS1220_CONTINIOUS_CONVERSION
@ ADS1220_VREF_EXTERNAL_REF
static void ads1220_periodic(struct Ads1220 *ads)
convenience function: read or start configuration if not already initialized
static const float Ads1220GainTable[]
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Common code for AP and FBW telemetry.
void eeprom25AA256_event(struct Eeprom25AA256 *eeprom)
Event function.
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.
struct GpsState gps
global GPS state
Device independent GPS code (interface).
static struct LlaCoor_i * stateGetPositionLla_i(void)
Get position in LLA coordinates (int).
static struct UtmCoor_f * stateGetPositionUtm_f(void)
Get position in UTM coordinates (float).
static FILE * pprzLogFile
#define MS_HUMIDTY_OFFSET
#define MS_PRESSURE_OFFSET
Default scale and offset Only used if calibration from EEPROM is not used/available.
void meteo_stick_init(void)
Init function.
#define MS_TEMPERATURE_SCALE
struct MeteoStick meteo_stick
General structure.
static float pitot_offset
static float get_temp(uint32_t raw)
void meteo_stick_periodic(void)
Periodic function.
#define MS_DIFF_PRESSURE_OFFSET
static float get_humidity(uint32_t raw)
static float get_diff(uint32_t raw)
#define MS_DIFF_PRESSURE_SCALE
#define MS_TEMPERATURE_OFFSET
static float get_pitot(uint32_t raw)
static const float maxAdc
Prescaling of data according to datasheets.
static float get_pressure(uint32_t raw)
void meteo_stick_report(void)
void meteo_stick_event(void)
Event function.
static void meteo_stick_send_data(struct transport_tx *trans, struct link_device *device)
Funnction to send over different transport and device.
#define MS_PRESSURE_SCALE
Data acquisition module for ENAC PTU board.
bool mtostk_populate_cal_from_buffer(Calibration_params *cp, uint8_t *_eeprom_buffer)
Initializes a Calibration_params structure from memory buffer.
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
uint8_t zone
UTM zone number.
position in UTM coordinates Units: meters
struct pprzlog_transport pprzlog_tp
PPRZLOG transport structure.
Initialize pprzlog transport.
SdioError sdLogWriteLog(const FileDes fd, const char *fmt,...)
Architecture independent timing functions.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
short int16_t
Typedef defining 16 bit short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.