Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/ControlSystemsBase/src/pid_design.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,23 @@
end

function pid_ss_2dof(param_p, param_i, param_d=zero(typeof(param_p)); form=:standard, b = 1, c = 0, Tf=nothing, N=nothing, balance=true)
kp, ki, kd = convert_pidparams_to_parallel(param_p, param_i, param_d, form)
if kd == 0
if ki == 0
return ss([kp -kp])

Check warning on line 181 in lib/ControlSystemsBase/src/pid_design.jl

View check run for this annotation

Codecov / codecov/patch

lib/ControlSystemsBase/src/pid_design.jl#L181

Added line #L181 was not covered by tests
else
A = [0.0;;]
B = [ki -ki]
C = [1.0;;] # Ti == 0 would result in division by zero, but typically indicates that the user wants no integral action
D = [b*kp -kp]
return ss(A, B, C, D)
end
end
# On standard form we use N
Tf !== nothing && N !== nothing && throw(ArgumentError("Cannot supply both Tf and N"))
if Tf === nothing && N === nothing
N = 10 # Default value
end
kp, ki, kd = convert_pidparams_to_parallel(param_p, param_i, param_d, form)
Tf = @something(Tf, kd / N)
Tf <= 0 && throw(ArgumentError("Tf must be strictly positive"))
if ki == 0
Expand Down
6 changes: 6 additions & 0 deletions lib/ControlSystemsBase/test/test_pid_design.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ Ktf = [(kp*b + kd*s*c/(Tf*s + 1)) -(kp + kd*s/(Tf*s + 1))]
Kss = ControlSystemsBase.pid_ss_2dof(kp, ki, kd; Tf, b, c, form=:parallel)
@test freqresptest(Kss, Ktf) < 1e-10

kp, ki, kd, b, c, Tf = rand(6)
kd = 0
Ktf = [(kp*b + ki/s + kd*s*c/(Tf*s + 1)) -(kp + ki/s + kd*s/(Tf*s + 1))]
Kss = ControlSystemsBase.pid_ss_2dof(kp, ki, kd; Tf, b, c, form=:parallel)
@test freqresptest(Kss, Ktf) < 1e-10

kp, ki, kd, b, c, Tf = rand(6)
Ktf = [(kp*b + ki/s + kd*s*c/(Tf*s + 1)) -(kp + ki/s + kd*s/(Tf*s + 1))]
Kss = ControlSystemsBase.pid_ss_2dof(kp, ki, kd; Tf, b, c, form=:parallel)
Expand Down
Loading