Controller Design & Tuning¶
controllers
¶
PID controller design and tuning module for Linear Time-Invariant systems.
PID
¶
Construct a continuous-time PID controller as a TransferFunction.
The controller transfer function in standard form with derivative filter is:
.. math::
C(s) = K_p + \frac{K_i}{s} + \frac{K_d s}{T_f s + 1}
where :math:T_f is the derivative filter time constant. Alternatively,
if the filter coefficient :math:N is specified, the filter time constant is
computed as :math:T_f = \frac{K_d}{N K_p} (for :math:K_p > 0).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Kp
|
float
|
Proportional gain, default is 1.0. |
1.0
|
Ki
|
float
|
Integral gain, default is 0.0. |
0.0
|
Kd
|
float
|
Derivative gain, default is 0.0. |
0.0
|
Tf
|
float
|
Derivative filter time constant (:math: |
0.0
|
N
|
float | None
|
Derivative filter coefficient (:math: |
None
|
Returns:
| Type | Description |
|---|---|
TransferFunction
|
Continuous-time transfer function representing the PID controller. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If Tf is negative or N is non-positive. |
Source code in src/ctrlpy/controllers.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
pid
¶
Construct a continuous-time PID controller as a TransferFunction.
.. math::
C(s) = K_p + \frac{K_i}{s} + \frac{K_d s}{T_f s + 1}
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Kp
|
float
|
Proportional gain \(K_p\), default is 1.0. |
1.0
|
Ki
|
float
|
Integral gain \(K_i\), default is 0.0. |
0.0
|
Kd
|
float
|
Derivative gain \(K_d\), default is 0.0. |
0.0
|
Tf
|
float
|
Derivative filter time constant \(T_f \ge 0\), default is 0.0. |
0.0
|
N
|
float | None
|
Derivative filter coefficient \(N > 0\), default is None. |
None
|
Returns:
| Type | Description |
|---|---|
TransferFunction
|
Continuous-time transfer function representing the PID controller. |
Source code in src/ctrlpy/controllers.py
pi
¶
Construct a continuous-time Proportional-Integral (PI) controller.
.. math::
C(s) = K_p + \frac{K_i}{s} = \frac{K_p s + K_i}{s}
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Kp
|
float
|
Proportional gain \(K_p\), default is 1.0. |
1.0
|
Ki
|
float
|
Integral gain \(K_i\), default is 0.0. |
0.0
|
Returns:
| Type | Description |
|---|---|
TransferFunction
|
Continuous-time PI controller transfer function. |
Source code in src/ctrlpy/controllers.py
pd
¶
Construct a continuous-time Proportional-Derivative (PD) controller.
.. math::
C(s) = K_p + \frac{K_d s}{T_f s + 1}
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Kp
|
float
|
Proportional gain \(K_p\), default is 1.0. |
1.0
|
Kd
|
float
|
Derivative gain \(K_d\), default is 0.0. |
0.0
|
Tf
|
float
|
Derivative filter time constant \(T_f \ge 0\), default is 0.0. |
0.0
|
N
|
float | None
|
Derivative filter coefficient \(N > 0\), default is None. |
None
|
Returns:
| Type | Description |
|---|---|
TransferFunction
|
Continuous-time PD controller transfer function. |
Source code in src/ctrlpy/controllers.py
tune_ziegler_nichols
¶
Tune a PID controller using the Ziegler-Nichols reaction curve (step response) heuristic.
Determines apparent dead time :math:L and reaction rate (maximum slope) :math:R
from the open-loop step response of a stable plant.
Tuning rules:
- P: :math:K_p = \frac{1}{R L}
- PI: :math:K_p = \frac{0.9}{R L}, :math:K_i = \frac{K_p}{3.33 L}
- PID: :math:K_p = \frac{1.2}{R L}, :math:K_i = \frac{K_p}{2 L}, :math:K_d = 0.5 L K_p
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sys
|
LinearTimeInvariant
|
Open-loop SISO LTI system. Must be stable. |
required |
method
|
'step'
|
Tuning method, default is "step" (open-loop reaction curve method). |
"step"
|
controller_type
|
('pid', 'pi', 'p')
|
Controller structure to generate, default is "pid". |
"pid"
|
Returns:
| Type | Description |
|---|---|
TransferFunction
|
Tuned controller transfer function. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If method or controller_type is unsupported, or if the system is not SISO. |
UnstableSystemError
|
If the open-loop plant is unstable. |
Source code in src/ctrlpy/controllers.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | |