introduce (crude) false-reading detection
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
#include <avr/io.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <util/delay.h>
|
||||
#include <stdio.h>
|
||||
#include <avr/interrupt.h>
|
||||
@@ -25,7 +27,10 @@ void kraftsensor_init(){
|
||||
}
|
||||
|
||||
void do_kraftsensor(){
|
||||
static int32_t last_read;
|
||||
static int32_t old_value;
|
||||
uint16_t m_data[4];
|
||||
int32_t kraftsensor_read;
|
||||
|
||||
/* read 2 16bit values and merge to 32bit signed integer */
|
||||
readReg(1,0,2);
|
||||
@@ -38,8 +43,26 @@ void do_kraftsensor(){
|
||||
int32_t tmp = (uint32_t)m_data[1]<<16;
|
||||
tmp |= m_data[0];
|
||||
|
||||
//kraftsensor_value = tmp;
|
||||
/* conversion magic to milliNewton */
|
||||
kraftsensor_value = ((tmp + 539363)*9.81)/177.380;
|
||||
kraftsensor_read = ((tmp + 197700 /*539363*/)*9.81)/177.380;
|
||||
|
||||
if(abs(kraftsensor_read - old_value) > 10000){
|
||||
if(abs(last_read - kraftsensor_read) > 10000){
|
||||
kraftsensor_value = old_value;
|
||||
printf("delta: %d\tvalue:%ld\n", kraftsensor_read - old_value, kraftsensor_read);
|
||||
printf("spike\n");
|
||||
}
|
||||
else{
|
||||
kraftsensor_value = kraftsensor_read;
|
||||
printf("jump\n");
|
||||
}
|
||||
}
|
||||
else{
|
||||
kraftsensor_value = kraftsensor_read;
|
||||
}
|
||||
last_read = kraftsensor_read;
|
||||
old_value = kraftsensor_value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user