@@ -878,6 +878,70 @@ See also [ControlSystemsMTK.jl](https://juliacontrol.github.io/ControlSystemsMTK
878
878
# compose(ODESystem(eqs, t, sts, pars; name = name), input, output)
879
879
# end
880
880
881
+
882
+ """
883
+ DiscreteSlewRateLimiter(rate = 1.0, rate_negative = rate)
884
+
885
+ A discrete-time slew rate limiter that limits the rate of change of the input signal.
886
+
887
+ Note, the sample interval is not taken into account when computing the rate of change, the difference between two consequetive samples is saturated.
888
+
889
+ # Parameters:
890
+ - `rate`: Slew rate limit (in positive/increasing direction). Must be a positive number.
891
+ - `rate_negative`: Negative slew rate limit, defaults to `rate`. Must be a positive number.
892
+
893
+ # Variables
894
+ - `d`: Unsaturated rate of change of the input signal
895
+ - `u`: Input signal
896
+ - `y`: Output signal (saturated slew rate)
897
+
898
+ # Connectors:
899
+ - `input`
900
+ - `output`
901
+
902
+ # Example
903
+ ```
904
+ cl = Clock(0.1)
905
+ z = ShiftIndex(cl)
906
+ @mtkmodel SlweRateLimiterModel begin
907
+ @components begin
908
+ input = Sine(amplitude=1, frequency=0.8)
909
+ limiter = DiscreteSlewRateLimiter(; z, rate=0.4, rate_negative = 0.3)
910
+ end
911
+ @variables begin
912
+ x(t) = 0 # Dummy variable to workaround JSCompiler bug
913
+ end
914
+ @equations begin
915
+ connect(input.output, limiter.input)
916
+ D(x) ~ 0.1x + Hold(limiter.y)
917
+ end
918
+ end
919
+ @named m = SlweRateLimiterModel()
920
+ m = complete(m)
921
+ ssys = structural_simplify(IRSystem(m))
922
+ prob = ODEProblem(ssys, [m.limiter.y(z-1) => 0], (0.0, 2.0))
923
+ sol = solve(prob, Tsit5(), dtmax=0.01)
924
+ plot(sol, idxs=[m.input.output.u, m.limiter.y], title="Slew rate limited sine wave")
925
+ ```
926
+ """
927
+ @mtkmodel DiscreteSlewRateLimiter begin
928
+ @extend u, y = siso = SISO ()
929
+ @structural_parameters begin
930
+ z = ShiftIndex ()
931
+ end
932
+ @parameters begin
933
+ rate = 1.0 , [description = " Slew rate limit" ]
934
+ rate_negative = rate, [description = " Negative slew rate limit" ]
935
+ end
936
+ @variables begin
937
+ d (t)
938
+ end
939
+ @equations begin
940
+ d (z) ~ u (z) - y (z- 1 )
941
+ y (z) ~ y (z- 1 ) + clamp (d (z), - rate_negative, rate)
942
+ end
943
+ end
944
+
881
945
"""
882
946
Quantization
883
947
0 commit comments