Skip to content

Joystick: Fix EMA filter sticking and slew buttons not repeating#2440

Open
cfuture81 wants to merge 1 commit into
indilib:masterfrom
cfuture81:fix-joystick-ema-and-slew-buttons
Open

Joystick: Fix EMA filter sticking and slew buttons not repeating#2440
cfuture81 wants to merge 1 commit into
indilib:masterfrom
cfuture81:fix-joystick-ema-and-slew-buttons

Conversation

@cfuture81

Copy link
Copy Markdown
Contributor

Problem

Two issues reported after the joystick driver refactor (906f3a0):

  1. D-pad axes get stuck after release: When using "Two Separate Axes" mode for mount motion, pressing and releasing the D-pad starts motion but it never stops. The user has to press Stop manually.

  2. Slew Rate Up/Down buttons only work once: First press changes the speed, subsequent presses are ignored.

Root Cause

Issue 1: EMA filter residual on HAT axes

The EMA low-pass filter in axisEvent() computes:

EMA = alpha * value + (1 - alpha) * EMA_prev

HAT/D-pad axes only emit events on press (value=32767) and release (value=0). After release:

  • EMA = 0.5 * 0 + 0.5 * 16383 = 8192
  • No more events arrive, so EMA never reaches zero
  • Value stays above dead zone (default=5) indefinitely
  • Telescope processAxis() sees perpetual non-zero = perpetual motion

Issue 2: One-shot gate never re-arms for button events

processButton() calls processSlewPresets(1, angle) which has a one-shot gate (m_slewPresetArmed). The gate re-arms only when mag < 0.5 — designed for analog joystick pairs returning to center. Button-driven calls always pass mag=1.0, so after the first press fires and disarms, subsequent presses are blocked.

Fix

  1. When the raw axis value is exactly 0, snap EMA to zero immediately. Preserves smoothing for analog sticks while ensuring digital axes return to idle on release.

  2. Set m_slewPresetArmed = true before calling processSlewPresets from the button path.

Testing

  • Issue 1 confirmed by user setting EMA alpha=1.0 as workaround (motion stops correctly)
  • Issue 2 is a pure logic bug confirmed by code analysis (no user workaround possible)
  • Reporter: Pti-Jean (AstroArch, Raspberry Pi aarch64, Hori Fighting Commander ONE controller)

@cfuture81 cfuture81 force-pushed the fix-joystick-ema-and-slew-buttons branch from cd19709 to e2bdb78 Compare July 6, 2026 14:11
Two issues reported after the joystick driver refactor (906f3a0):

1. D-pad (HAT) axes get stuck in non-zero state after release when
   using 'Two Separate Axes' mode for mount motion. Also affects
   analog sticks where the EMA delays the return to zero.

   Root cause: The EMA low-pass filter in axisEvent() doesn't track
   zero-ward movement quickly enough. For digital HAT axes (which
   only emit events on press/release), the EMA lingers above the
   dead zone indefinitely. For analog sticks, the EMA delays the
   zero-crossing, causing sticky motion.

   Fix: Apply EMA smoothing only on deflection (magnitude increasing
   away from center). On release (magnitude decreasing toward center),
   track the raw value instantly. This preserves jitter smoothing
   during stick deflection while ensuring both analog sticks and
   digital D-pads reach zero without delay.

2. Slew Rate Up/Down buttons only register the first press.

   Root cause: processButton() calls processSlewPresets(1, angle)
   which has a one-shot gate (m_slewPresetArmed). The gate is
   re-armed only when mag < 0.5 — a path designed for analog
   joystick pairs returning to center. Button-driven calls always
   pass mag=1.0, so the re-arm condition is never reached after the
   first press fires and disarms.

   Fix: Set m_slewPresetArmed = true before calling processSlewPresets
   from the button path.

Tested-by: Pti-Jean (AstroArch, Hori Fighting Commander ONE)
- Setting EMA alpha=1.0 confirmed as workaround for issue 1
- Issue 2 is a pure logic bug with no user workaround
@cfuture81 cfuture81 force-pushed the fix-joystick-ema-and-slew-buttons branch from e2bdb78 to 1ab6cca Compare July 8, 2026 11:03
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

Successfully merging this pull request may close these issues.

1 participant