Skip to content

Fix pid_ss_2dof N-to-Tf conversion to match documented Tf = Td/N - #1067

Merged
baggepinnen merged 1 commit into
masterfrom
fbc/pid-2dof-tf-n
Jul 22, 2026
Merged

Fix pid_ss_2dof N-to-Tf conversion to match documented Tf = Td/N#1067
baggepinnen merged 1 commit into
masterfrom
fbc/pid-2dof-tf-n

Conversation

@baggepinnen

@baggepinnen baggepinnen commented Jul 22, 2026

Copy link
Copy Markdown
Member

Problem

The pid_2dof/pid_ss_2dof docstring states that Tf defaults to Td/N, but the code computed Tf = kd/N using the parallel-form derivative gain kd (units gain·time rather than time). The two agree only when kp == 1, so for any other proportional gain the derivative filter obtained from N was off by a factor kp.

Fix

Compute Tf = kd/(kp*N) = Td/N (with Td = kd/kp, the standard-form derivative time constant), matching the docstring. When N is given with zero proportional gain, Td is undefined and a descriptive ArgumentError asks for an explicit Tf instead.

This is technically breaking for callers who passed N with kp ≠ 1 and relied on the previous (undocumented) behavior.

Tests

  • Updated the existing pid_ss_2dof N test to the corrected relation and added a standard-form check that passing N equals passing Tf = Td/N with kp ≠ 1, plus the kp == 0 error case.
  • Added tests pinning the Tf filter semantics of pid: with filter_order = 1 the derivative term is Kd·s/(Tf·s + 1); with filter_order = 2 the whole controller is filtered by 1/((s·Tf)²/(4d²) + s·Tf + 1) with default d = 1/√2, in both tf and ss forms and in standard form.

lib/ControlSystemsBase/test/test_pid_design.jl passes (152/152).

🤖 Generated with Claude Code

https://claude.ai/code/session_014QR4FuuvxZU9a3UrTJjg5X

The docstring states that Tf defaults to Td/N, but the code computed
Tf = kd/N using the parallel-form derivative gain kd (units gain*time
rather than time). The two agree only when kp == 1. Compute
Tf = kd/(kp*N) = Td/N instead, and throw a descriptive error when N is
given with zero proportional gain, where Td is undefined.

Also add tests pinning the Tf filter semantics of pid: with
filter_order = 1 the derivative term is Kd*s/(Tf*s + 1), and with
filter_order = 2 the whole controller is filtered by
1/((s*Tf)^2/(4d^2) + s*Tf + 1) with default d = 1/sqrt(2).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014QR4FuuvxZU9a3UrTJjg5X
@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

@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

@baggepinnen
baggepinnen merged commit 4a91837 into master Jul 22, 2026
5 checks passed
@baggepinnen
baggepinnen deleted the fbc/pid-2dof-tf-n branch July 22, 2026 11:04
@codecov

codecov Bot commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.63%. Comparing base (7ea561f) to head (1a4faa8).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1067      +/-   ##
==========================================
- Coverage   91.68%   91.63%   -0.05%     
==========================================
  Files          42       42              
  Lines        5712     5714       +2     
==========================================
- Hits         5237     5236       -1     
- Misses        475      478       +3     

☔ View full report in Codecov by Harness.
📢 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.

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