|
43 | 43 | function pid_tf(param_p, param_i, param_d=zero(typeof(param_p)); form=:standard, Ts=nothing, Tf=nothing) |
44 | 44 | Kp, Ti, Td = convert_pidparams_to_standard(param_p, param_i, param_d, form) |
45 | 45 | TE = isnothing(Ts) ? Continuous() : Discrete(Ts) |
| 46 | + ia = Ti != Inf && Ti != 0 # integral action, 0 would result in division by zero, but typically indicates that the user wants no integral action |
46 | 47 | if isnothing(Tf) |
47 | | - if Ti != Inf |
| 48 | + if ia |
48 | 49 | return tf([Kp * Td, Kp, Kp / Ti], [1, 0], TE) |
49 | 50 | else |
50 | 51 | return tf([Kp * Td, Kp], [1], TE) |
51 | 52 | end |
52 | 53 | else |
53 | | - if Ti != Inf |
| 54 | + if ia |
54 | 55 | return tf([Kp * Td, Kp, Kp / Ti], [Tf^2/2, Tf, 1, 0], TE) |
55 | 56 | else |
56 | 57 | return tf([Kp * Td, Kp], [Tf^2/2, Tf, 1], TE) |
|
61 | 62 | function pid_ss(param_p, param_i, param_d=zero(typeof(param_p)); form=:standard, Ts=nothing, Tf=nothing) |
62 | 63 | Kp, Ti, Td = convert_pidparams_to_standard(param_p, param_i, param_d, form) |
63 | 64 | TE = isnothing(Ts) ? Continuous() : Discrete(Ts) |
| 65 | + ia = Ti != Inf && Ti != 0 # integral action, 0 would result in division by zero, but typically indicates that the user wants no integral action |
64 | 66 | if !isnothing(Tf) |
65 | | - A = [0 1 0; 0 0 1; 0 -2/Tf^2 -2/Tf] |
66 | | - B = [0; 0; 1] |
67 | | - C = 2 * Kp / Tf^2 * [1/Ti 1 Td] |
| 67 | + if ia |
| 68 | + A = [0 1 0; 0 0 1; 0 -2/Tf^2 -2/Tf] |
| 69 | + B = [0; 0; 1] |
| 70 | + C = 2 * Kp / Tf^2 * [1/Ti 1 Td] |
| 71 | + else |
| 72 | + A = [0 1; -2/Tf^2 -2/Tf] |
| 73 | + B = [0; 1] |
| 74 | + C = 2 * Kp / Tf^2 * [1 Td] |
| 75 | + end |
68 | 76 | D = 0 |
69 | 77 | elseif Td == 0 |
70 | | - A = 0 |
71 | | - B = 1 |
72 | | - C = Kp / Ti |
73 | | - D = Kp |
| 78 | + if ia |
| 79 | + A = 0 |
| 80 | + B = 1 |
| 81 | + C = Kp / Ti # Ti == 0 would result in division by zero, but typically indicates that the user wants no integral action |
| 82 | + D = Kp |
| 83 | + else |
| 84 | + return StateSpace([Kp], TE) |
| 85 | + end |
74 | 86 | else |
75 | 87 | throw(DomainError("cannot create controller as a state space if Td != 0 without a filter. Either create the controller as a transfer function, pid(TransferFunction; params...), or supply Tf to create a filter.")) |
76 | 88 | end |
|
0 commit comments