@@ -56,19 +56,22 @@ If the input is within `u_min` ... `u_max`, the output is zero. Outside of this
56
56
- `input`
57
57
- `output`
58
58
"""
59
- @component function DeadZone (; name, u_max, u_min = - u_max)
60
- if ! ModelingToolkit. isvariable (u_max)
61
- u_max ≥ u_min || throw (ArgumentError (" `u_min` must be smaller than `u_max`" ))
59
+ @mtkmodel DeadZone begin
60
+ @parameters begin
61
+ u_max, [description = " Upper limit of dead zone of DeadZone" ]
62
+ u_min = - u_max, [description = " Lower limit of dead zone of DeadZone" ]
63
+ end
64
+ begin
65
+ if ! ModelingToolkit. isvariable (u_max)
66
+ u_max ≥ u_min || throw (ArgumentError (" `u_min` must be smaller than `u_max`" ))
67
+ end
68
+ end
69
+
70
+ @extend u, y = siso = SISO ()
71
+
72
+ @equations begin
73
+ y ~ _dead_zone (u, u_min, u_max)
62
74
end
63
- @named siso = SISO ()
64
- @unpack u, y = siso
65
- pars = @parameters u_max= u_max [
66
- description = " Upper limit of dead zone of DeadZone $name " ,
67
- ] u_min= u_min [description = " Lower limit of dead zone of DeadZone $name " ]
68
- eqs = [
69
- y ~ _dead_zone (u, u_min, u_max),
70
- ]
71
- extend (ODESystem (eqs, t, [], pars; name = name), siso)
72
75
end
73
76
74
77
"""
@@ -87,19 +90,19 @@ Limits the slew rate of a signal.
87
90
- `input`
88
91
- `output`
89
92
"""
90
- @component function SlewRateLimiter (; name, rising = 1 , falling = - rising, Td = 0.001 ,
91
- y_start = 0.0 )
92
- rising ≥ falling || throw ( ArgumentError ( " `rising` must be smaller than `falling` " ))
93
- Td > 0 || throw ( ArgumentError ( " Time constant `Td` must be strictly positive " ))
94
- @named siso = SISO (y_start = y_start)
95
- @unpack u, y = siso
96
- pars = @parameters rising = rising [
97
- description = " Maximum rising slew rate of SlewRateLimiter $name " ,
98
- ] falling = falling [description = " Maximum falling slew rate of SlewRateLimiter $name " ] Td = Td [
99
- description = " Derivative time constant of SlewRateLimiter $name " ,
100
- ]
101
- eqs = [
102
- D (y) ~ max ( min ((u - y) / Td, rising), falling),
103
- ]
104
- extend ( ODESystem (eqs, t, [], pars; name = name), siso)
93
+ @mtkmodel SlewRateLimiter begin
94
+
95
+ @parameters begin
96
+ rising = 1 , [description = " Maximum rising slew rate of SlewRateLimiter " ]
97
+ falling = - rising, [description = " Derivative time constant of SlewRateLimiter " ]
98
+ Td = 0.001
99
+ end
100
+ begin
101
+ getdefault (rising) ≥ getdefault ( falling) || throw ( ArgumentError ( " `rising` must be smaller than `falling` " ))
102
+ getdefault (Td) > 0 || throw ( ArgumentError ( " Time constant `Td` must be strictly positive " ))
103
+ end
104
+ @extend u, y = siso = SISO (y = 0.0 )
105
+ @equations begin
106
+ D (y) ~ max ( min ((u - y) / Td, rising), falling)
107
+ end
105
108
end
0 commit comments