calculating targer ms5611 pressure value from average calculated from 4 elements long history

pull/2/head
Mateusz Lubecki 2020-03-06 20:24:20 +01:00
rodzic 11c5e0ddcb
commit 7d11df2dde
5 zmienionych plików z 74 dodań i 43 usunięć

Wyświetl plik

@ -4,7 +4,7 @@
#include "aprs/ax25.h"
#define SW_VER "DE07"
#define SW_DATE "03032020"
#define SW_DATE "06032020"
#define SYSTICK_TICKS_PER_SECONDS 100
#define SYSTICK_TICKS_PERIOD 10

Wyświetl plik

@ -16,12 +16,16 @@
#define WIND_AVERAGE_LEN 18
#define PRESSURE_AVERAGE_LN 4
extern float rte_wx_temperature_dallas, rte_wx_temperature_dallas_valid;
extern float rte_wx_temperature_dalls_slew_rate;
extern float rte_wx_temperature_average_dallas_valid;
extern float rte_wx_temperature_min_dallas_valid, rte_wx_temperature_max_dallas_valid;
extern float rte_wx_temperature_ms, rte_wx_temperature_ms_valid;
extern float rte_wx_pressure, rte_wx_pressure_valid;
extern float rte_wx_pressure_history[PRESSURE_AVERAGE_LN];
extern uint8_t rte_wx_pressure_it;
extern uint16_t rte_wx_windspeed_pulses;
extern uint16_t rte_wx_windspeed[WIND_AVERAGE_LEN];

Wyświetl plik

@ -14,6 +14,8 @@ float rte_wx_temperature_average_dallas_valid = 0.0f;
float rte_wx_temperature_min_dallas_valid = 0.0f, rte_wx_temperature_max_dallas_valid = 0.0f;
float rte_wx_temperature_ms = 0.0f, rte_wx_temperature_ms_valid = 0.0f;
float rte_wx_pressure = 0.0f, rte_wx_pressure_valid = 0.0f;
float rte_wx_pressure_history[PRESSURE_AVERAGE_LN];
uint8_t rte_wx_pressure_it;
uint16_t rte_wx_windspeed_pulses = 0;
uint16_t rte_wx_windspeed[WIND_AVERAGE_LEN];
@ -44,4 +46,10 @@ void rte_wx_init(void) {
rte_wx_windspeed[i] = 0;
rte_wx_winddirection[i] = 0;
}
rte_wx_pressure_it = 0;
for (i = 0; i < 4; i++) {
rte_wx_pressure_history[i] = 0.0f;
}
}

Wyświetl plik

@ -36,7 +36,10 @@ static const float direction_constant = M_PI/180.0f;
void wx_get_all_measurements(void) {
int8_t j = 0;
int32_t i = 0;
int32_t return_value = 0;
float pressure_average_sum = 0.0f;
#ifdef _METEO
// quering MS5611 sensor for temperature
@ -115,7 +118,33 @@ void wx_get_all_measurements(void) {
return_value = ms5611_get_pressure(&rte_wx_pressure, &rte_wx_ms5611_qf);
if (return_value == MS5611_OK) {
rte_wx_pressure_valid = rte_wx_pressure;
// add the current pressure into buffer
rte_wx_pressure_history[rte_wx_pressure_it++] = rte_wx_pressure;
// reseting the average length iterator
j = 0;
// check if and end of the buffer was reached
if (rte_wx_pressure_it >= PRESSURE_AVERAGE_LN) {
rte_wx_pressure_it = 0;
}
// calculating the average of pressure measuremenets
for (i = 0; i < PRESSURE_AVERAGE_LN; i++) {
// skip empty slots in the history to provide proper value even for first wx packet
if (rte_wx_pressure_history[i] < 10.0f) {
continue;
}
// add to the average
pressure_average_sum += rte_wx_pressure_history[i];
// increase the average lenght iterator
j++;
}
rte_wx_pressure_valid = pressure_average_sum / (float)j;
}
// if humidity sensor is idle trigger the communiction & measuremenets

Wyświetl plik

@ -23,7 +23,14 @@
#define PM TX20.PrevMeasCounter
#define OE TX20.OddEven
#define MAX_SLEW_RATE 9
#define HALF_MAX_SLEW_RATE 4.5f
Anemometer TX20; // Deklaracja zmiennej strukturalnej typu Anemometer
float tx20_previous_windspeed;
uint16_t tx20_previous_direction;
float tx20_current_windspeed;
uint16_t tx20_current_direction;
@ -66,11 +73,6 @@ void tx20_init(void) {
//// inicjalizacja p<>l struktury //
////////////////////////////////////////
BQ = 0, QL = 0, FC = 0, DCD = 0, RD = 0, MC = 1, OE = 0, PM = 1;
// for (i = 1; i <= TX20_BUFF_LN - 1; i++) {
// VNAME.HistoryAVG[i].WindSpeed = -1;
// VNAME.HistoryAVG[i].WindDirX = -1;
// VNAME.HistoryAVG[i].WindDirY = -1;
// }
AFIO->EXTICR[(TX/4)] |= PORTNUM << (TX % 4) * 4;
EXTI->RTSR |= 1 << TX;
EXTI->IMR |= 1 << TX;
@ -122,45 +124,31 @@ void tx20_batch(void) {
}
float tx20_data_average(void) {
int i;
short x = 0,xx = 0,y = 0,yy = 0, out = 0;
x = (short)(100.0f * cosf((float)TX20.Data.WindDirX * PI/180.0f));
y = (short)(100.0f * sinf((float)TX20.Data.WindDirX * PI/180.0f));
// if (
// PM != MC &&
// abs((int32_t)(TX20.HistoryAVG[PM].WindSpeed - TX20.Data.WindSpeed)) > 9
//
// ) {
// rte_wx_tx20_excessive_slew_rate = 1;
// return 0;
// }
// copy values from previous function call
tx20_previous_direction = tx20_current_direction;
tx20_previous_windspeed = tx20_current_windspeed;
tx20_current_windspeed = VNAME.Data.WindSpeed;
// fetch current measuremeents
tx20_current_direction = TX20.Data.WindDirX;
tx20_current_windspeed = TX20.Data.WindSpeed;
// calculate the difference between current and previous
int abs_windspeed_diff = ((int32_t)tx20_current_windspeed - (int32_t)tx20_previous_windspeed);
//int abs_direction_diff = ((int16_t)tx20_current_direction - (int16_t)tx20_previous_direction);
// check if current measurement is too big in comparison with the previous one
if (abs_windspeed_diff > MAX_SLEW_RATE) {
tx20_current_windspeed = tx20_previous_windspeed + (float)HALF_MAX_SLEW_RATE;
}
// check if current measuremenet is too small in comparision with the previous one
else if (abs_windspeed_diff < -MAX_SLEW_RATE) {
tx20_current_windspeed = tx20_previous_windspeed - (float)HALF_MAX_SLEW_RATE;
}
else {
;
}
// TX20.HistoryAVG[MC].WindSpeed = VNAME.Data.WindSpeed;
// TX20.HistoryAVG[MC].WindDirX = x;
// TX20.HistoryAVG[MC].WindDirY = y;
// TX20.HistoryAVG[0].WindDirX = 0;
// TX20.HistoryAVG[0].WindDirY = 0;
// TX20.HistoryAVG[0].WindSpeed = 0;
// x = 0, y = 0;
// for (i = 1; (i <= TX20_BUFF_LN - 1 && TX20.HistoryAVG[i].WindSpeed != -1); i++) {
// TX20.HistoryAVG[0].WindSpeed += TX20.HistoryAVG[i].WindSpeed;
// x += TX20.HistoryAVG[i].WindDirX;
// y += TX20.HistoryAVG[i].WindDirY;
// }
// TX20.HistoryAVG[0].WindSpeed /= (i - 1);
// xx = x / (i - 1);
// yy = y / (i - 1);
// out = (short)(atan2f(yy , xx) * 180.0f/PI);
// if (out < 0)
// out += 360;
// TX20.HistoryAVG[0].WindDirX = out;
// PM = MC;
// if ((MC++) == TX20_BUFF_LN)
// MC = 1;
return 0;
}
@ -192,7 +180,9 @@ void tx20_data_parse(void) {
TX20.Data.Checksum = temp;
if (TX20.Data.Checksum == TX20.Data.CalcChecksum)
tx20_data_average();
else;
else {
;
}
wx_last_good_wind_time = master_time;
}