Fix pid_ss_2dof N-to-Tf conversion to match documented Tf = Td/N - #1067
Merged
Conversation
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
|
This is an automated message.
|
|
This is an automated message.
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.












Problem
The
pid_2dof/pid_ss_2dofdocstring states thatTfdefaults toTd/N, but the code computedTf = kd/Nusing the parallel-form derivative gainkd(units gain·time rather than time). The two agree only whenkp == 1, so for any other proportional gain the derivative filter obtained fromNwas off by a factorkp.Fix
Compute
Tf = kd/(kp*N) = Td/N(withTd = kd/kp, the standard-form derivative time constant), matching the docstring. WhenNis given with zero proportional gain,Tdis undefined and a descriptiveArgumentErrorasks for an explicitTfinstead.This is technically breaking for callers who passed
Nwithkp ≠ 1and relied on the previous (undocumented) behavior.Tests
pid_ss_2dofNtest to the corrected relation and added a standard-form check that passingNequals passingTf = Td/Nwithkp ≠ 1, plus thekp == 0error case.Tffilter semantics ofpid: withfilter_order = 1the derivative term isKd·s/(Tf·s + 1); withfilter_order = 2the whole controller is filtered by1/((s·Tf)²/(4d²) + s·Tf + 1)with defaultd = 1/√2, in bothtfandssforms and in standard form.lib/ControlSystemsBase/test/test_pid_design.jlpasses (152/152).🤖 Generated with Claude Code
https://claude.ai/code/session_014QR4FuuvxZU9a3UrTJjg5X