Close

Crawling average.

A project log for Christine's Blooming Rose

3D printed, heat formed, servo actuated blooming, Dotstar module lit, rose.

Daren SchwenkeDaren Schwenke 03/13/2019 at 04:050 Comments

We are using the capsense library here to trigger the movement based on touch.

This is a remarkably simple solution, uses only N+1 digital pins, and N resistors to drive it.  So for my two channels of capsense, I need 2 resistors and 3 pins.   Sweet.

However, the values you get from it can vary by two orders of magnitude, just depending on where you end up placing the rose, grounding of the power source, humidity, people in the room, the phase of the moon... etc.

So.. I attempted to implement some sort of auto-calibration of the capsense thresholds based upon a running average.  

The idea is that an actual touch will cause a rapid spike in the value as compared to the previous values, no matter what those previous values happen to be.  

This should work..  

It sorta does now.. but.. the current running average code either compensates so rapidly so as to eliminate the touch signal sometimes, or still triggers based on the random fluctuations.  

The happy medium seems hard to find, but I am using the simplest form of running average.  This ends up weighting the last measurement much more heavily than the previous ones which I believe is the source of my problems.

I could use an array instead to store the actual previous measurements and average that way, but it costs memory.  I do have memory to throw at the problem though, so worst case I can do that.  I think I'll just do that.

Working on it.

<EDIT>

It is better, but not enough to justify consuming 4x as much memory.  It still triggers sometimes on it's own. 

What's happening is this.

Before the first touch, the value hovers around 15, with threshold set to 45.

On touch it goes up to about 200, and on release settles down to about 60.

On the next touch it goes back up to about 180, and barely triggers.

On next settle it can go down to either 15 or 45...

Sometimes then it goes back up to 60 without a touch, and if the previous level was 60, it will trigger on it's own.

Setting a static threshold of 75 or so would solve it, for where it is now.  Or... perhaps an exponential or logarithmic threshold curve might help...  I'll try those next I think.

</EDIT>

Discussions