tune threshold and add weight interpretation

This commit is contained in:
King Kévin 2015-01-28 19:36:00 +01:00
parent 336d4e5bda
commit 81888eb26b
1 changed files with 21 additions and 15 deletions

View File

@ -29,15 +29,11 @@
#include "main.h" // main definitions
/* contants */
// max measurement jitter for high and low value
#define JITTER_HIGH 8
#define JITTER_LOW 3
// max measurement jitter for high and low value 8/3
#define JITTER_HIGH 11
#define JITTER_LOW 5
// how many value have to be stable before showing output
#define MEASUREMENT_STABLE 3
// weight coefficient (timer 1 ticks/kg)
// proportionally decreasing for high, increasing for low
#define COEF_HIGH 41.78
#define COEF_LOW 39.87
/* variables */
volatile uint8_t state_portD; // the state of port D
@ -204,21 +200,31 @@ int main(void)
zero_high = measurement_high;
zero_low = measurement_low;
#ifdef DEBUG
printf("zero values high/low: %u/%u\n", zero_high, zero_low);
printf("zero values high low: %u %u\n", zero_high, zero_low);
#endif
} else { // prinf measurement weight
double weight_high = (int16_t)(zero_high-measurement_high)/COEF_HIGH;
double weight_low = (int16_t)(measurement_low-zero_low)/COEF_LOW;
double weight = (weight_high+weight_low)/2;
printf("%d kg\n", zero_high-measurement_high);
printf("%.2f kg\n", weight);
count_high = count_low = 0;
} else { // print measurement weight
#ifdef DEBUG
printf("%u %u 0\n", zero_high, zero_low);
printf("%u %u t1\n", measurement_high, measurement_low);
#endif
// the low measurement are linear and more stable
// normally it should not have a origin, but the linear estimation shows one and it works better
const double orig_low = -1.92285;
const double coef_low = 0.0258119;
double weight_low = (int16_t)(measurement_low-zero_low)*coef_low+orig_low;
if (weight_low<orig_low*-1.5 && weight_low>orig_low*1.5) {
weight_low = 0;
}
printf("%.2f kg\n", weight_low);
}
count_high = count_low = 0;
}
/* display if scale switches off */
if (scale_old!=scale_on && !scale_on) {
#ifdef DEBUG
printf(PSTR("scale stop\n"));
printf(PSTR("scale stop\n")); // actually measurement is finished and the on switch is released
#endif
scale_old = scale_on; // save new state
}