Reduced the size of averaging buffer and introduced a raw (unfiltered) value. Averaged value is same as before, but one byte saved per class instance. Unfiltered value is used for writing into telemetry log.

This commit is contained in:
Damjan Adamic
2014-06-30 21:12:01 +02:00
parent d38c02f847
commit 3f39352d95
3 changed files with 29 additions and 8 deletions
+5 -1
View File
@@ -200,13 +200,17 @@ void writeLogs()
#if defined(FRSKY)
#if defined(CPUARM)
f_printf(&g_oLogFile, "%d,%d,", frskyData.swr.value, frskyData.rssi[0].value);
f_printf(&g_oLogFile, "%d,%d,", frskyData.swr.raw, frskyData.rssi[0].raw);
#else
f_printf(&g_oLogFile, "%d,%d,%d,", frskyStreaming, frskyData.rssi[0].value, frskyData.rssi[1].value);
#endif
for (uint8_t i=0; i<MAX_FRSKY_A_CHANNELS; i++) {
#if defined(CPUARM)
int16_t converted_value = applyChannelRatio(i, frskyData.analog[i].raw);
#else
int16_t converted_value = applyChannelRatio(i, frskyData.analog[i].value);
#endif
f_printf(&g_oLogFile, "%d.%02d,", converted_value/100, converted_value%100);
}
#endif
+20 -4
View File
@@ -84,16 +84,18 @@ void FrskyValueWithMin::set(uint8_t value)
this->value = value;
}
else {
unsigned int sum = 0;
//calculate the average from values[], raw, value
unsigned int sum = values[0];
for (int i=0; i<TELEMETRY_AVERAGE_COUNT-1; i++) {
uint8_t tmp = values[i+1];
values[i] = tmp;
sum += tmp;
}
values[TELEMETRY_AVERAGE_COUNT-1] = value;
sum += value;
this->value = sum/TELEMETRY_AVERAGE_COUNT;
values[TELEMETRY_AVERAGE_COUNT-1] = raw;
sum += raw + value;
this->value = sum/(TELEMETRY_AVERAGE_COUNT+2);
}
raw = value;
#else
if (this->value == 0) {
this->value = value;
@@ -573,6 +575,20 @@ void telemetryReset()
frskyData.hub.current = 55;
frskyData.hub.maxCurrent = 65;
// //test of averaging
// FrskyValueWithMin testVal;
// testVal.value = 0;
// testVal.set(10);
// TRACE("testVal after first set: %d", (int)testVal.value);
// for(int n=2; n<10; ++n) {
// testVal.set(n*10);
// TRACE("in %d, testVal: %d", n*10, (int)testVal.value);
// }
// for(int n=2; n<10; ++n) {
// testVal.set(100);
// TRACE("in %d, testVal: %d", 100, (int)testVal.value);
// }
#endif
}
+4 -3
View File
@@ -70,12 +70,13 @@ extern uint8_t telemetryState;
#endif
#if defined(CPUARM)
#define TELEMETRY_AVERAGE_COUNT 4
#define TELEMETRY_AVERAGE_COUNT 2 //we actually average two more readings!
class FrskyValueWithMin {
public:
uint8_t value;
uint8_t min;
uint8_t value; //fitered value (average of last TELEMETRY_AVERAGE_COUNT+2 values)
uint8_t min;
uint8_t values[TELEMETRY_AVERAGE_COUNT];
uint8_t raw; //raw value (unfiltered)
void set(uint8_t value);
};
#else