Skip to content

fix: reject a PID d_filter_alpha of 0 - #20

Merged
aajll merged 1 commit into
masterfrom
19-fix-reject-alpha-zero
Oct 15, 2026
Merged

aajll merged 1 commit into
masterfrom
19-fix-reject-alpha-zero

Conversation

@aajll

@aajll aajll commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Layer 1 of 1. A separate PR fixes the bumpless-transfer integral step.

What and why

fxp_lerp(D, R, 0) returns D, so a d_filter_alpha of 0 froze the derivative term: it stayed 0 after fpc_pid_init, and after fpc_pid_set_config the last term stayed as a constant output offset that only fpc_pid_reset cleared. fpc_pid_derive now rejects d_filter_alpha <= 0, so the range is (0, 1.0]. This matches the existing rule that a nonzero gain must not round to an inert term.

  • test_invalid_config_rejected rejects 0 through init and accepts the smallest positive value, FXP_RAW(1).
  • test_set_config_clamps_state rejects 0 through set_config and checks that the state is unchanged.
  • The header, docs/api.md and docs/design.md state the range (0, 1.0], and the CHANGELOG has a Fixed entry.

Acceptance criteria

  • A configuration cannot leave the derivative term frozen at a nonzero value. Every accepted alpha is at least one LSB, so D moves towards the raw derivative on every step.
  • A test covers alpha = 0 through both init and set_config. With the old < 0 check, the suite fails.
  • The header, docs/api.md and docs/design.md state the range that is accepted.

Checks

  • meson test under ASan and UBSan: 2/2. The coverage gate is 100% of lines and branches.
  • misch run --baseline, misch deviations, scripts/format.sh.
  • cl2000 22.6.2 and 25.11.1, COFF and EABI, with -Dwerror=true: all build.

Refs #19

With alpha 0 the derivative filter never moved, so the derivative gain had no effect after init and the last derivative term stayed as a constant output offset after set_config. The accepted range is now (0, 1.0]; init and set_config return FPC_STATUS_INVALID_PARAM for 0.

Refs #19
@aajll aajll linked an issue Oct 15, 2026 that may be closed by this pull request
3 tasks done
@aajll
aajll merged commit 596c611 into master Oct 15, 2026
10 checks passed
@aajll
aajll deleted the 19-fix-reject-alpha-zero branch October 15, 2026 15:25
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.

d_filter_alpha of 0 freezes the derivative term

1 participant