Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: better event detection via dual moving average cross-over #7

Open
Andrei-Pozolotin opened this issue Jul 18, 2020 · 0 comments
Open

Comments

@Andrei-Pozolotin
Copy link

  1. currently "tare" happens once, on setup:
    https://github.com/IvDm/Z-probe-on-smd-resistors-2512/blob/master/strain_gage_switch_ATtiny85.ino

  2. this does not reflect environment changes during long operation:

  • parameters temperature drift,
  • parameters mechanical creep,
    etc.
  1. 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
            }
        }
    }
}
  1. here is full sketch for arduino/nano:
    https://gist.github.com/Andrei-Pozolotin/e7bf413e2438863a04c2497258662bec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant