Skip to content

Fix pid_tf coefficients for Ki=0 with first-order derivative filter#1058

Merged
baggepinnen merged 2 commits into
masterfrom
fix/pid_tf-kp-coefficients
May 16, 2026
Merged

Fix pid_tf coefficients for Ki=0 with first-order derivative filter#1058
baggepinnen merged 2 commits into
masterfrom
fix/pid_tf-kp-coefficients

Conversation

@baggepinnen
Copy link
Copy Markdown
Member

Summary

For pid_tf with Ki = 0, first-order derivative filter, and a non-nothing Tf, the returned transfer function should be

C(s) = Kp + Kd*s / (Tf*s + 1) = ((Kp*Tf + Kd)*s + Kp) / (Tf*s + 1)

i.e. numerator [Kp*Tf + Kd, Kp]. The code instead produced [Kd*Tf + Kd, Kd]Kp was dropped entirely and substituted with Kd. The returned controller therefore contained no proportional term.

The adjacent branch (Ki != 0, filter_order == 1) uses the correct form [Kd + Kp*Tf, Ki*Tf + Kp, Ki]; collapsing that for Ki = 0 agrees with the fix.

Test plan

  • Compare pid_tf(Kp, 0, Kd; Tf, filter_order=1) against the analytical transfer function above (Kp=2, Kd=0.5, Tf=0.1).
  • Existing tests in test_pid_design.jl still pass.

🤖 Generated with Claude Code

For Kp + Kd*s/(Tf*s+1) the numerator polynomial is
((Kp*Tf + Kd)*s + Kp), but the code was using
[Kd*Tf + Kd, Kd] — Kp dropped entirely and replaced by Kd. The
returned transfer function therefore did not contain the proportional
term. The other branches in the same function (Ki!=0/filter_order=1
on the next line) use the correct form, which this brings into line.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@JuliaControlBot
Copy link
Copy Markdown

This is an automated message.
Plots were compared to references. 4/11 images have changed, see differences below.
After pulling this PR, please update the reference images by creating a PR to ControlExamplePlots.jl here.

Difference Reference Image New Image
✔️ 0.0 Reference New
✔️ 0.0 Reference New
✔️ 0.0 Reference New
✔️ 0.0 Reference New

@codecov
Copy link
Copy Markdown

codecov Bot commented May 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.64%. Comparing base (0aa6e4c) to head (850b8e7).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1058      +/-   ##
==========================================
+ Coverage   91.61%   91.64%   +0.02%     
==========================================
  Files          42       42              
  Lines        5653     5659       +6     
==========================================
+ Hits         5179     5186       +7     
+ Misses        474      473       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Cross-check the transfer-function PID controller against the state-space
realization, and against the analytical numerator [Kp*Tf+Kd, Kp]. On
master both checks failed because the implementation emitted
[Kd*Tf+Kd, Kd] (Kp dropped and replaced with Kd).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@baggepinnen baggepinnen merged commit 40ab726 into master May 16, 2026
5 checks passed
@baggepinnen baggepinnen deleted the fix/pid_tf-kp-coefficients branch May 16, 2026 04:57
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.

2 participants