Dejitter:
Filter:
adclib/Classes (extension) | Utilities

Dejitter
ExtensionExtension

remove jitter from unstable control sources

Description

Dejitter is useful for calming controls with some jitter, e.g. a joystick that toggles between two adjacent values. It will reduce control traffic, because its function will only be run when the incoming value changes are outside the current jitter range. More precisely, jitter range is a moving window of [hi, lo] within which changes are handled as follows: when the incoming value is within the current range window nothing happens; when the incoming value goes above hi, value and hi are set to incoming, func runs, and lo is pulled up to (hi - width), i.e. the range window is dragged up. The same happens conversely when value goes below lo. This way, values leading in one direction drag the range window along with full sensitivity; after a change of direction, the window has to be traversed before changes are passed on and dragging sets in again. Therefore, one should keep the width just above the average jitter to avoid "dead" zones on every direction change.

Class Methods

.new

create a new Dejitter

Arguments:

width

the width within which to filter jitter

func

the func to run when filtered value has changed

value

an initial value

Instance Methods

.value

the current value

.func

the func to run when filtered value has changed

.width

the width of the moving range window

.set

the method to set a new (jittery) value

.lo

.hi

the current lo and hi values of the moving range window