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 #include "subsystems/chibios-libopencm3/chibios_sdlog.h"
178 bool_t log_ptu_started;
191 #include "messages.h"
195 #define MS_DATA_SIZE 4
197 static inline void meteo_stick_send_data(
void)
199 float ptu_data[MS_DATA_SIZE];
215 #ifdef MS_PRESSURE_SLAVE_IDX
229 #ifdef MS_DIFF_PRESSURE_SLAVE_IDX
243 #ifdef MS_TEMPERATURE_SLAVE_IDX
281 log_ptu_started =
FALSE;
290 #ifdef MS_PRESSURE_SLAVE_IDX
293 #ifdef MS_DIFF_PRESSURE_SLAVE_IDX
296 #ifdef MS_TEMPERATURE_SLAVE_IDX
300 #ifdef MS_HUMIDITY_PWM_INPUT
324 if (pprzLogFile != -1) {
325 if (!log_ptu_started) {
332 sdLogWriteLog(pprzLogFile,
"# Sensor: %d, time: %d, num_temp: %d, num_coeff: %d\n", i,
341 sdLogWriteLog(pprzLogFile,
"# Coeffs:");
345 sdLogWriteLog(pprzLogFile,
"\n");
348 sdLogWriteLog(pprzLogFile,
"#\n");
349 sdLogWriteLog(pprzLogFile,
350 "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");
351 log_ptu_started =
TRUE;
354 sdLogWriteLog(pprzLogFile,
355 "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");
356 log_ptu_started =
TRUE;
359 sdLogWriteLog(pprzLogFile,
"%d %d %d %d %.2f %.2f %.2f %.2f %d %d %d %d %d %d %d %d %d\n",
373 meteo_stick_send_data();
387 #ifdef MS_PRESSURE_SLAVE_IDX
390 #ifdef MS_DIFF_PRESSURE_SLAVE_IDX
393 #ifdef MS_TEMPERATURE_SLAVE_IDX
397 #ifdef MS_PRESSURE_SLAVE_IDX
408 #ifdef MS_DIFF_PRESSURE_SLAVE_IDX
421 #if USE_MS_DIFF_PRESSURE
431 #ifdef MS_TEMPERATURE_SLAVE_IDX
435 #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)
bool_t reset_dp_offset
reset differential pressure offset
void eeprom25AA256_init(struct Eeprom25AA256 *eeprom, struct spi_periph *spi_p, uint8_t slave_idx)
Init function.
struct spi_transaction spi_trans
spi transaction
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
float temps[MTOSTK_MAX_TEMP_ARRAY_SIZE]
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)
float coeffs[MTOSTK_MAX_TEMP_ARRAY_SIZE][MTOSTK_MAX_POLY_ARRAY_SIZE]
#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 in mm
enum Ads1220VRef vref
voltage ref
uint32_t tow
GPS time of week in ms.
volatile bool_t data_available
data ready flag
Device independent GPS code (interface)
bool_t pga_bypass
bypass PGA (PGA enabled = 0)
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
#define DefaultChannel
SITL.
bool_t data_available
data read flag
enum Ads1220SampleRate rate
data output rate
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)
volatile uint8_t rx_buf[E25_IN_BUFFER_LEN]
receive buffer
Sensors_params params[MTOSTK_NUM_SENSORS]
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.
struct Eeprom25AA256 eeprom
eeprom with calibration data
#define MS_PRESSURE_SCALE
uint16_t gspeed
norm of 2d ground speed in cm/s
Calibration_params calib
calibration
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
enum SPITransactionStatus status
#define MS_PRESSURE_OFFSET
Default scale and offset Only used if calibration from EEPROM is not used/available.