Skip to content

Commit d266780

Browse files
author
Brad Carman
committed
format
1 parent b2f6c93 commit d266780

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

src/Blocks/nonlinear.jl

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
112122
end

0 commit comments

Comments
 (0)