@@ -258,13 +258,21 @@ See also [`LimPID`](@ref)
258
258
with_D = ! isequal (Td, false )
259
259
@named err_input = RealInput () # control error
260
260
@named ctr_output = RealOutput () # control signal
261
- ! isequal (Ti, false ) &&
262
- (Ti ≥ 0 || throw (ArgumentError (" Ti out of bounds, got $(Ti) but expected Ti ≥ 0" )))
263
- ! isequal (Td, false ) &&
264
- (Td ≥ 0 || throw (ArgumentError (" Td out of bounds, got $(Td) but expected Td ≥ 0" )))
265
- Nd > 0 || throw (ArgumentError (" Nd out of bounds, got $(Nd) but expected Nd > 0" ))
261
+ @symcheck Ti ≥ 0 ||
262
+ throw (ArgumentError (" Ti out of bounds, got $(Ti) but expected Ti ≥ 0" ))
263
+ @symcheck Td ≥ 0 ||
264
+ throw (ArgumentError (" Td out of bounds, got $(Td) but expected Td ≥ 0" ))
265
+ @symcheck Nd > 0 ||
266
+ throw (ArgumentError (" Nd out of bounds, got $(Nd) but expected Nd > 0" ))
267
+
268
+ pars = @parameters begin
269
+ k = k, [description = " Proportional gain" ]
270
+ Ti = Ti, [description = " Integrator time constant" ]
271
+ Td = Td, [description = " Derivative time constant" ]
272
+ Nd = Nd, [description = " Derivative limit" ]
273
+ end
266
274
267
- @named gainPID = Gain (k)
275
+ @named gainPID = Gain (; k)
268
276
@named addPID = Add3 ()
269
277
if with_I
270
278
@named int = Integrator (k = 1 / Ti, x = int__x)
@@ -304,7 +312,7 @@ See also [`LimPID`](@ref)
304
312
else
305
313
push! (eqs, connect (Dzero. output, addPID. input3))
306
314
end
307
- ODESystem (eqs, t, [], [] ; name = name, systems = sys)
315
+ ODESystem (eqs, t, [], pars ; name = name, systems = sys)
308
316
end
309
317
310
318
"""
@@ -334,15 +342,22 @@ The simplified expression above is given without the anti-windup protection.
334
342
throw (ArgumentError (" Time constant `Ta` has to be strictly positive" ))
335
343
@symcheck T > 0 || throw (ArgumentError (" Time constant `T` has to be strictly positive" ))
336
344
@symcheck u_max ≥ u_min || throw (ArgumentError (" u_min must be smaller than u_max" ))
345
+ pars = @parameters begin
346
+ k = k, [description = " Proportional gain" ]
347
+ T = T, [description = " Integrator time constant" ]
348
+ Ta = Ta, [description = " Tracking time constant" ]
349
+ u_max = u_max, [description = " Upper saturation limit" ]
350
+ u_min = u_min, [description = " Lower saturation limit" ]
351
+ end
337
352
@named err_input = RealInput () # control error
338
353
@named ctr_output = RealOutput () # control signal
339
- @named gainPI = Gain (k)
354
+ @named gainPI = Gain (; k)
340
355
@named addPI = Add ()
341
356
@named addTrack = Add ()
342
357
@named int = Integrator (k = 1 / T, x = int__x)
343
358
@named limiter = Limiter (y_max = u_max, y_min = u_min)
344
359
@named addSat = Add (k1 = 1 , k2 = - 1 )
345
- @named gainTrack = Gain (1 / Ta)
360
+ @named gainTrack = Gain (k = 1 / Ta)
346
361
sys = [err_input, ctr_output, gainPI, addPI, int, addTrack, limiter, addSat, gainTrack]
347
362
eqs = [
348
363
connect (err_input, addPI. input1),
@@ -357,7 +372,7 @@ The simplified expression above is given without the anti-windup protection.
357
372
connect (addTrack. output, int. input),
358
373
connect (int. output, addPI. input2)
359
374
]
360
- ODESystem (eqs, t, [], [] ; name = name, systems = sys)
375
+ ODESystem (eqs, t, [], pars ; name = name, systems = sys)
361
376
end
362
377
363
378
"""
@@ -408,18 +423,25 @@ where the transfer function for the derivative includes additional filtering, se
408
423
Ti = k / Ti
409
424
Td = Td / k
410
425
end
411
- 0 ≤ wp ≤ 1 ||
412
- throw (ArgumentError (" wp out of bounds, got $(wp) but expected wp ∈ [0, 1]" ))
413
- 0 ≤ wd ≤ 1 ||
414
- throw (ArgumentError (" wd out of bounds, got $(wd) but expected wd ∈ [0, 1]" ))
415
- ! isequal (Ti, false ) &&
416
- (Ti ≥ 0 || throw (ArgumentError (" Ti out of bounds, got $(Ti) but expected Ti ≥ 0" )))
417
- ! isequal (Td, false ) &&
418
- (Td ≥ 0 || throw (ArgumentError (" Td out of bounds, got $(Td) but expected Td ≥ 0" )))
426
+ @symcheck Ti ≥ 0 ||
427
+ throw (ArgumentError (" Ti out of bounds, got $(Ti) but expected Ti ≥ 0" ))
428
+ @symcheck Td ≥ 0 ||
429
+ throw (ArgumentError (" Td out of bounds, got $(Td) but expected Td ≥ 0" ))
419
430
@symcheck u_max ≥ u_min || throw (ArgumentError (" u_min must be smaller than u_max" ))
420
431
@symcheck Nd > 0 ||
421
432
throw (ArgumentError (" Nd out of bounds, got $(Nd) but expected Nd > 0" ))
422
433
434
+ pars = @parameters begin
435
+ k = k, [description = " Proportional gain" ]
436
+ Ti = Ti, [description = " Integrator time constant" ]
437
+ Td = Td, [description = " Derivative time constant" ]
438
+ wp = wp, [description = " Set-point weighting in the proportional part" ]
439
+ wd = wd, [description = " Set-point weighting in the derivative part" ]
440
+ Ni = Ni, [description = " Anti-windup tracking gain" ]
441
+ Nd = Nd, [description = " Derivative limit" ]
442
+ u_max = u_max, [description = " Upper saturation limit" ]
443
+ u_min = u_min, [description = " Lower saturation limit" ]
444
+ end
423
445
@named reference = RealInput ()
424
446
@named measurement = RealInput ()
425
447
@named ctr_output = RealOutput () # control signal
@@ -431,7 +453,7 @@ where the transfer function for the derivative includes additional filtering, se
431
453
if with_AWM
432
454
@named addI = Add3 (k1 = 1 , k2 = - 1 , k3 = 1 )
433
455
@named addSat = Add (k1 = 1 , k2 = - 1 )
434
- @named gainTrack = Gain (1 / (k * Ni))
456
+ @named gainTrack = Gain (k = 1 / (k * Ni))
435
457
else
436
458
@named addI = Add (k1 = 1 , k2 = - 1 )
437
459
end
@@ -492,7 +514,7 @@ where the transfer function for the derivative includes additional filtering, se
492
514
push! (eqs, connect (Dzero. output, addPID. input2))
493
515
end
494
516
495
- ODESystem (eqs, t, [], [] ; name = name, systems = sys)
517
+ ODESystem (eqs, t, [], pars ; name = name, systems = sys)
496
518
end
497
519
498
520
"""
@@ -611,13 +633,13 @@ See also [`StateSpace`](@ref) which handles MIMO systems, as well as [ControlSys
611
633
description = " Denominator coefficients of transfer function (e.g., `s² + 2ωs + ω^2` is specified as [1, 2ω, ω^2])"
612
634
]
613
635
bb[1 : (nbb + nb)] = [zeros (nbb); b]
614
- d = bb[1 ] / a[1 ], [description = " Direct feedthrough gain" ]
615
636
end
637
+ d = bb[1 ] / a[1 ]# , [description = "Direct feedthrough gain"]
616
638
617
639
a = collect (a)
618
- @parameters a_end = ifelse (a[end ] > 100 * symbolic_eps (sqrt (a' * a)), a[end ], 1.0 )
640
+ a_end = ifelse (a[end ] > 100 * symbolic_eps (sqrt (a' * a)), a[end ], 1.0 )
619
641
620
- pars = [collect (b); a; collect (bb); d; a_end ]
642
+ pars = [collect (b); a; collect (bb)]
621
643
@variables begin
622
644
x (t)[1 : nx] = zeros (nx),
623
645
[description = " State of transfer function on controller canonical form" ]
0 commit comments