Skip to content

Commit 87157cd

Browse files
author
Brad Carman
committed
format
1 parent 4cdc9d9 commit 87157cd

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

src/Blocks/continuous.jl

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,9 @@ Text-book version of a PID-controller without actuator saturation and anti-windu
234234
235235
See also [`LimPID`](@ref)
236236
"""
237-
@component function PID(with_I = true, with_D = true; name, k = 1, Ti = 0.1, Td = 0.1, Nd = 10, int__x = 0,
237+
@component function PID(with_I = true, with_D = true; name, k = 1, Ti = 0.1, Td = 0.1,
238+
Nd = 10, int__x = 0,
238239
der__x = 0)
239-
240240
pars = @parameters begin
241241
k = k
242242
Ti = Ti
@@ -250,24 +250,26 @@ See also [`LimPID`](@ref)
250250
@named ctr_output = RealOutput() # control signal
251251

252252
with_I &&
253-
(@symcheck Ti 0 || throw(ArgumentError("Ti out of bounds, got $(Ti) but expected Ti ≥ 0")))
253+
(@symcheck Ti 0 ||
254+
throw(ArgumentError("Ti out of bounds, got $(Ti) but expected Ti ≥ 0")))
254255
with_D &&
255-
(@symcheck Td 0 || throw(ArgumentError("Td out of bounds, got $(Td) but expected Td ≥ 0")))
256+
(@symcheck Td 0 ||
257+
throw(ArgumentError("Td out of bounds, got $(Td) but expected Td ≥ 0")))
256258

257259
@symcheck Nd > 0 ||
258-
throw(ArgumentError("Nd out of bounds, got $(Nd) but expected Nd ≥ 0"))
260+
throw(ArgumentError("Nd out of bounds, got $(Nd) but expected Nd ≥ 0"))
259261

260262
@named gainPID = Gain(; k)
261263
@named addPID = Add3()
262264
if with_I
263-
@named int = Integrator(;k = 1 / Ti, x = int__x)
265+
@named int = Integrator(; k = 1 / Ti, x = int__x)
264266
else
265-
@named Izero = Constant(;k = 0)
267+
@named Izero = Constant(; k = 0)
266268
end
267269
if with_D
268-
@named der = Derivative(;k = Td, T = 1 / Nd, x = der__x)
270+
@named der = Derivative(; k = Td, T = 1 / Nd, x = der__x)
269271
else
270-
@named Dzero = Constant(;k = 0)
272+
@named Dzero = Constant(; k = 0)
271273
end
272274
sys = [err_input, ctr_output, gainPID, addPID]
273275
if with_I
@@ -303,9 +305,9 @@ end
303305
with_I(type::Union{AbstractString, Symbol}) = contains(lowercase(string(type)), "i")
304306
with_D(type::Union{AbstractString, Symbol}) = contains(lowercase(string(type)), "d")
305307

306-
PID(type::Union{AbstractString, Symbol}; kwargs...) = PID(with_I(type), with_D(type); kwargs...)
307-
308-
308+
function PID(type::Union{AbstractString, Symbol}; kwargs...)
309+
PID(with_I(type), with_D(type); kwargs...)
310+
end
309311

310312
"""
311313
LimPI(; name, k = 1.0, T, Ta, int__x = 0.0, u_max = 1.0, u_min = -u_max)

test/Blocks/continuous.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,11 @@ end
172172
end
173173

174174
@testset "PID" begin
175-
176-
@parameters Ti=0.5 Td=1/100
175+
@parameters Ti=0.5 Td=1 / 100
177176
@named pid_controller = PID(; k = 3, Ti, Td)
178177

179178
re_val = 2
180-
@named ref = Constant(; k = re_val)
179+
@named ref = Constant(; k = re_val)
181180
@named plant = Plant()
182181
@named fb = Feedback()
183182
@named model = ODESystem([
@@ -290,7 +289,8 @@ end
290289
@testset "LimPID" begin
291290
re_val = 1
292291
@named ref = Constant(; k = re_val)
293-
@named pid_controller = LimPID(; k = 3, Ti = 0.5, Td = 1 / 100, u_max = 1.5, u_min = -1.5,
292+
@named pid_controller = LimPID(; k = 3, Ti = 0.5, Td = 1 / 100, u_max = 1.5,
293+
u_min = -1.5,
294294
Ni = 0.1 / 0.5)
295295
@named plant = Plant()
296296
@named model = ODESystem([
@@ -331,7 +331,7 @@ end
331331
@test all(-1.5 .<= sol[pid_controller.ctr_output.u] .<= 1.5) # test limit
332332
end
333333
@testset "PD" begin
334-
@named pid_controller = LimPID(; k = 10, Ti = false, Td = 1, u_max = 1.5,
334+
@named pid_controller = LimPID(; k = 10, Ti = false, Td = 1, u_max = 1.5,
335335
u_min = -1.5)
336336
@named model = ODESystem([
337337
connect(ref.output, pid_controller.reference),

test/runtests.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ using ModelingToolkitStandardLibrary
66
@parameters x = 1
77
@symcheck x > 0
88

9-
109
# Blocks
1110
@safetestset "Blocks: math" begin
1211
include("Blocks/math.jl")

0 commit comments

Comments
 (0)