Software · Controls

Signal Filter Lab

See how filters clean up noisy sensor readings, and how much delay each one adds.

Step 1 of 7

Distance sensor

Show all numbers

How each number is measured is under Go deeper.

Go deeper

In robot code

      

Make each filter once, as a field. Then call calculate() exactly once every loop. These filters assume a 20 ms loop: call one twice a loop, or skip loops, and its timing is wrong.

Where our code uses these
  • MW-Lib mechanisms (arm, elevator, roller, flywheel) smooth motor current with LinearFilter.singlePoleIIR(0.1, 0.02).
  • The 2026 shooter smooths flywheel speed with singlePoleIIR(0.15, 0.02).
  • "Shooter ready" uses new Debouncer(0.1, DebounceType.kRising): flywheel, hood and heading must all be on target for 0.1 s.
  • "Is shooting" uses new Debouncer(0.65, DebounceType.kFalling): it stays true for 0.65 s after the flywheel speed dip ends.
  • Motor, gyro and battery "connected" flags use new Debouncer(0.5) (Rising is the default), so one bad packet does not raise an alert.
  • The launch calculator averages hood angle over 0.1 s and heading over 0.8 s with LinearFilter.movingAverage(...).
  • Swerve teleop limits speed changes with MW-Lib's DynamicSlewRateLimiter (a SlewRateLimiter whose limit can change), 40 m/s² by default.

The WPILib class is Debouncer. Read more on the Signal Filtering page.

How the numbers are measured
  • Time to 90%: how long after a real step the output got 90% of the way there. The circles on the chart mark it.
  • Rule of thumb: moving average ≈ 0.9 × taps × 20 ms. IIR ≈ 2.3 × time constant. Median ≈ half the window. Slew rate ≈ 0.9 × step size ÷ rate. Debouncer = the debounce time.
  • Wobble left: how far the output still jumps around once the true value has been steady for 1 s (RMS error). Less wobble usually costs more time.
  • Delay on / off: how long after the real change the true/false output switched, the last time it happened.
  • False trigger: the output switched to something that isn't true, like a bounce counting as a second piece.
  • Missed: a real piece came and went and the output never saw it.
Things to try in free play
  1. Average vs. median. On Distance, turn spikes up to 2 per second and compare the two lines.
  2. Lag grows with smoothing. Drag moving-average taps from 5 to 50. Time to 90% goes from about 80 ms to about 880 ms.
  3. Rising vs. falling. On Beam break, switch the Debouncer between Rising, Falling and Both. Watch Delay on / off under Show all numbers.
  4. Different on and off times. On Current or Beam break, turn on Rising + falling: two chained debouncers, as in the docs.
  5. Slew rate is not a smoother. On Joystick, turn jitter up. The slew rate limiter passes small jitter straight through.
The Kalman filter

The Signal Filtering page also covers the Kalman filter. It mixes several sensors into one best guess, which is what WPILib's pose estimator does with odometry, the gyro and vision. Try it in the Pose Estimator Lab.