-
Notifications
You must be signed in to change notification settings - Fork 31
FR: better event detection via dual moving average cross-over #7
Copy link
Copy link
Open
Description
-
currently "tare" happens once, on setup:
https://github.com/IvDm/Z-probe-on-smd-resistors-2512/blob/master/strain_gage_switch_ATtiny85.ino -
this does not reflect environment changes during long operation:
- parameters temperature drift,
- parameters mechanical creep,
etc.
- a better way is to use dual moving average cross-over approach,
and eliminate dependency on environment changes i.e.:
// detect touch events
void process_trigger() {
const int32_t fast = moving_fast.average();
const int32_t slow = moving_slow.average();
const int32_t delta = fast - slow;
if (delta > 0) { // react only on proper direction
if (has_trigger) {
if (delta < DELTA_PASSIVE) { // detect turn off
has_trigger = false; // remember state
moving_slow.setup(trigger_slow); // recover to event start
process_output (LOW); // issue turn off
time_passive = millis(); // report event finish
}
} else {
if (delta > DELTA_ACTIVE) { // detect turn on
has_trigger = true; // remember state
trigger_slow = slow; // remember till event finish
process_output (HIGH); // issue turn on
time_active = millis(); // report event start
}
}
}
}- here is full sketch for arduino/nano:
https://gist.github.com/Andrei-Pozolotin/e7bf413e2438863a04c2497258662bec
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels