Utils
Esta página aún no está traducida. Se muestra la versión en inglés.
#EasyStack Utilities
The dev.easyfamily.EasyStack.util package holds small helper classes for filtering sensor signals, detecting changes, measuring loop time, interpolating tables and common math.
Most of these classes keep state between calls. Create one instance per signal, create it before the OpMode loop, and call it once per loop cycle.
| Class | Group | What it does |
|---|---|---|
Debouncer | Signals | Accepts a change in a boolean signal only after it stays stable for a set time. |
EdgeDetector | Signals | Reports rising edges, falling edges and changes of a boolean signal. |
LowPassFilter | Filters | Smooths a value with an exponential filter defined by a time constant in seconds. |
MedianFilter | Filters | Returns the median of the last N samples, which removes single-sample spikes. |
MovingAverageFilter | Filters | Returns the average of the last N samples. |
SimpleKalmanFilter | Filters | Smooths a noisy measurement with a gain that adapts to the estimate error. |
SlewRateLimiter | Filters | Limits how fast a value is allowed to change per second. |
LoopTimer | Timing | Measures the loop time, the loop frequency and a smoothed average. |
InterpLUT | Lookup | Interpolates between control points with a monotone cubic curve. |
MathFunctions | Math | Static helpers: clamp, angle wrapping, epsilon comparison, deadband and input modulus. |
Each class has its own section below, followed by a guide to choosing between the filters.
#Choosing a Filter
| Problem | Use |
|---|---|
| A digital sensor flickers when it changes. | Debouncer |
| You need to react once when a signal changes. | EdgeDetector |
| An analog reading has occasional wrong spikes. | MedianFilter |
| An analog reading has steady random noise. | MovingAverageFilter or LowPassFilter |
| You want smoothing that does not depend on the loop rate. | LowPassFilter |
| You want a filter that tunes how much it trusts the sensor. | SimpleKalmanFilter |
| A command must not change faster than the mechanism can handle. | SlewRateLimiter |
Filters can be combined. For example, a MedianFilter first removes spikes, and a LowPassFilter then smooths what is left.
#Common Mistakes
| Problem | Cause and fix |
|---|---|
| The filter output jumps between two signals. | One instance is shared by two signals. Create one instance per signal. |
| The output lags behind the real value. | Every smoothing filter adds delay. Use a smaller window or time constant. |
| The smoothing changes when the loop gets slower. | MedianFilter and MovingAverageFilter count samples, not time. Use LowPassFilter for time-based smoothing. |
| A filter starts with an old value after a mode change. | Call reset(), or create a new instance. |
Debouncer or EdgeDetector misses changes. | calculate() or update() is not called every cycle. Call it once per loop. |
InterpLUT throws an exception. | createLUT() was not called after the last add() or clear(), or it was called with fewer than two points. |
SlewRateLimiter does not move on the first call. | The first calculate(input) call has no earlier call to measure the time from. The output starts moving on the second call. |
LoopTimer shows 0.0. | tick() has been called only once. The values start at the second call. |
Última actualización 2026-11-16