@@ -13,7 +13,7 @@ Outputs `y = ∫k*u dt`, corresponding to the transfer function `1/s`.
13
13
- `k`: Gain of integrator
14
14
- `x_start`: Initial value of integrator
15
15
"""
16
- function Integrator (; name, k = 1 , x_start = 0.0 )
16
+ @component function Integrator (; name, k = 1 , x_start = 0.0 )
17
17
@named siso = SISO ()
18
18
@unpack u, y = siso
19
19
sts = @variables x (t)= x_start [description = " State of Integrator $name " ]
@@ -51,7 +51,7 @@ A smaller `T` leads to a more ideal approximation of the derivative.
51
51
- `input`
52
52
- `output`
53
53
"""
54
- function Derivative (; name, k = 1 , T, x_start = 0.0 )
54
+ @component function Derivative (; name, k = 1 , T, x_start = 0.0 )
55
55
T > 0 || throw (ArgumentError (" Time constant `T` has to be strictly positive" ))
56
56
@named siso = SISO ()
57
57
@unpack u, y = siso
@@ -97,7 +97,7 @@ sT + 1 - k
97
97
98
98
See also [`SecondOrder`](@ref)
99
99
"""
100
- function FirstOrder (; name, k = 1 , T, x_start = 0.0 , lowpass = true )
100
+ @component function FirstOrder (; name, k = 1 , T, x_start = 0.0 , lowpass = true )
101
101
T > 0 || throw (ArgumentError (" Time constant `T` has to be strictly positive" ))
102
102
@named siso = SISO ()
103
103
@unpack u, y = siso
@@ -138,7 +138,7 @@ Critical damping corresponds to `d=1`, which yields the fastest step response wi
138
138
- `input`
139
139
- `output`
140
140
"""
141
- function SecondOrder (; name, k = 1 , w, d, x_start = 0.0 , xd_start = 0.0 )
141
+ @component function SecondOrder (; name, k = 1 , w, d, x_start = 0.0 , xd_start = 0.0 )
142
142
@named siso = SISO ()
143
143
@unpack u, y = siso
144
144
@variables x (t)= x_start [description = " State of SecondOrder filter $name " ]
@@ -170,7 +170,7 @@ Textbook version of a PI-controller without actuator saturation and anti-windup
170
170
171
171
See also [`LimPI`](@ref)
172
172
"""
173
- function PI (; name, k = 1 , T, x_start = 0.0 )
173
+ @component function PI (; name, k = 1 , T, x_start = 0.0 )
174
174
T > 0 || throw (ArgumentError (" Time constant `T` has to be strictly positive" ))
175
175
@named err_input = RealInput () # control error
176
176
@named ctr_output = RealOutput () # control signal
@@ -209,7 +209,8 @@ Text-book version of a PID-controller without actuator saturation and anti-windu
209
209
210
210
See also [`LimPID`](@ref)
211
211
"""
212
- function PID (; name, k = 1 , Ti = false , Td = false , Nd = 10 , xi_start = 0 , xd_start = 0 )
212
+ @component function PID (; name, k = 1 , Ti = false , Td = false , Nd = 10 , xi_start = 0 ,
213
+ xd_start = 0 )
213
214
with_I = ! isequal (Ti, false )
214
215
with_D = ! isequal (Td, false )
215
216
@named err_input = RealInput () # control error
@@ -228,7 +229,7 @@ function PID(; name, k = 1, Ti = false, Td = false, Nd = 10, xi_start = 0, xd_st
228
229
@named Izero = Constant (k = 0 )
229
230
end
230
231
if with_D
231
- @named der = Derivative (k = 1 / Td, T = 1 / Nd, x_start = xd_start)
232
+ @named der = Derivative (k = Td, T = 1 / Nd, x_start = xd_start)
232
233
else
233
234
@named Dzero = Constant (k = 0 )
234
235
end
@@ -280,7 +281,7 @@ Text-book version of a PI-controller with actuator saturation and anti-windup me
280
281
- `err_input`
281
282
- `ctr_output`
282
283
"""
283
- function LimPI (; name, k = 1 , T, u_max, u_min = - u_max, Ta, x_start = 0.0 )
284
+ @component function LimPI (; name, k = 1 , T, u_max, u_min = - u_max, Ta, x_start = 0.0 )
284
285
Ta > 0 || throw (ArgumentError (" Time constant `Ta` has to be strictly positive" ))
285
286
T > 0 || throw (ArgumentError (" Time constant `T` has to be strictly positive" ))
286
287
u_max ≥ u_min || throw (ArgumentError (" u_min must be smaller than u_max" ))
@@ -318,7 +319,7 @@ Proportional-Integral-Derivative (PID) controller with output saturation, set-po
318
319
The equation for the control signal is roughly
319
320
320
321
```
321
- k(ep + 1/Ti * ∫e + 1/ Td * d/dt(ed))
322
+ k(ep + 1/Ti * ∫e + Td * d/dt(ed))
322
323
e = u_r - u_y
323
324
ep = wp*u_r - u_y
324
325
ed = wd*u_r - u_y
@@ -343,14 +344,14 @@ where the transfer function for the derivative includes additional filtering, se
343
344
- `measurement`
344
345
- `ctr_output`
345
346
"""
346
- function LimPID (; name, k = 1 , Ti = false , Td = false , wp = 1 , wd = 1 ,
347
- Ni = Ti == 0 ? Inf : √ (max (Td / Ti, 1e-6 )),
348
- Nd = 10 ,
349
- u_max = Inf ,
350
- u_min = u_max > 0 ? - u_max : - Inf ,
351
- gains = false ,
352
- xi_start = 0.0 ,
353
- xd_start = 0.0 )
347
+ @component function LimPID (; name, k = 1 , Ti = false , Td = false , wp = 1 , wd = 1 ,
348
+ Ni = Ti == 0 ? Inf : √ (max (Td / Ti, 1e-6 )),
349
+ Nd = 10 ,
350
+ u_max = Inf ,
351
+ u_min = u_max > 0 ? - u_max : - Inf ,
352
+ gains = false ,
353
+ xi_start = 0.0 ,
354
+ xd_start = 0.0 )
354
355
with_I = ! isequal (Ti, false )
355
356
with_D = ! isequal (Td, false )
356
357
with_AWM = Ni != Inf
@@ -389,7 +390,7 @@ function LimPID(; name, k = 1, Ti = false, Td = false, wp = 1, wd = 1,
389
390
@named Izero = Constant (k = 0 )
390
391
end
391
392
if with_D
392
- @named der = Derivative (k = 1 / Td, T = 1 / Nd, x_start = xd_start)
393
+ @named der = Derivative (k = Td, T = 1 / Nd, x_start = xd_start)
393
394
@named addD = Add (k1 = wd, k2 = - 1 )
394
395
else
395
396
@named Dzero = Constant (k = 0 )
@@ -478,8 +479,8 @@ y &= h(x, u)
478
479
479
480
linearized around the operating point `x₀, u₀`, we have `y0, u0 = h(x₀, u₀), u₀`.
480
481
"""
481
- function StateSpace (; A, B, C, D = nothing , x_start = zeros (size (A, 1 )), name,
482
- u0 = zeros (size (B, 2 )), y0 = zeros (size (C, 1 )))
482
+ @component function StateSpace (; A, B, C, D = nothing , x_start = zeros (size (A, 1 )), name,
483
+ u0 = zeros (size (B, 2 )), y0 = zeros (size (C, 1 )))
483
484
nx, nu, ny = size (A, 1 ), size (B, 2 ), size (C, 1 )
484
485
size (A, 2 ) == nx || error (" `A` has to be a square matrix." )
485
486
size (B, 1 ) == nx || error (" `B` has to be of dimension ($nx x $nu )." )
0 commit comments