@@ -93,20 +93,30 @@ Initial value of state `Y` can be set with `int.y`
9393 - `input`
9494 - `output`
9595"""
96- @mtkmodel SlewRateLimiter begin
97- @parameters begin
98- rising = 1.0 , [description = " Maximum rising slew rate of SlewRateLimiter" ]
99- falling = - rising, [description = " Derivative time constant of SlewRateLimiter" ]
100- Td = 0.001 , [description = " Derivative time constant" ]
101- end
102- begin
103- getdefault (rising) ≥ getdefault (falling) ||
104- throw (ArgumentError (" `rising` must be smaller than `falling`" ))
105- getdefault (Td) > 0 ||
106- throw (ArgumentError (" Time constant `Td` must be strictly positive" ))
96+ @component function SlewRateLimiter (;
97+ name, y_start = 0.0 , rising = 1.0 , falling = - rising, Td = 0.001 )
98+ pars = @parameters begin
99+ rising = rising, [description = " Maximum rising slew rate of SlewRateLimiter" ]
100+ falling = falling, [description = " Derivative time constant of SlewRateLimiter" ]
101+ Td = Td, [description = " Derivative time constant" ]
102+ y_start = y_start
107103 end
108- @extend u, y = siso = SISO (; y_start)
109- @equations begin
104+
105+ getdefault (rising) ≥ getdefault (falling) ||
106+ throw (ArgumentError (" `rising` must be smaller than `falling`" ))
107+ getdefault (Td) > 0 ||
108+ throw (ArgumentError (" Time constant `Td` must be strictly positive" ))
109+
110+ @named siso = SISO (; y_start)
111+ @unpack y, u = siso
112+
113+ eqs = [
110114 D (y) ~ max (min ((u - y) / Td, rising), falling)
111- end
115+ ]
116+
117+ initialization_eqs = [
118+ y ~ y_start
119+ ]
120+
121+ return extend (ODESystem (eqs, t, [], pars; name, initialization_eqs), siso)
112122end
0 commit comments