Skip to content

Commit 6a09473

Browse files
committed
refactor: update the arglist of non-dsl components to match the style of dsl components
- this will allow upgradation of those without breaking again
1 parent 518df2b commit 6a09473

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

src/Blocks/continuous.jl

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ See also [`LimPI`](@ref)
214214
end
215215

216216
"""
217-
PID(;name, k=1, Ti=false, Td=false, Nd=10, xi_start=0, xd_start=0)
217+
PID(;name, k=1, Ti=false, Td=false, Nd=10, int__x=0, der__x=0)
218218
219219
Text-book version of a PID-controller without actuator saturation and anti-windup measure.
220220
@@ -224,8 +224,8 @@ Text-book version of a PID-controller without actuator saturation and anti-windu
224224
- `Ti`: [s] Integrator time constant (Ti>0 required). If set to false, no integral action is used.
225225
- `Td`: [s] Derivative time constant (Td>0 required). If set to false, no derivative action is used.
226226
- `Nd`: [s] Time constant for the derivative approximation (Nd>0 required; Nd=0 is ideal derivative).
227-
- `x_start`: Initial value for the integrator.
228-
- `xd_start`: Initial value for the derivative state.
227+
- `int__x`: Initial value for the integrator.
228+
- `der__x`: Initial value for the derivative state.
229229
230230
# Connectors:
231231
@@ -234,8 +234,8 @@ Text-book version of a PID-controller without actuator saturation and anti-windu
234234
235235
See also [`LimPID`](@ref)
236236
"""
237-
@component function PID(; name, k = 1, Ti = false, Td = false, Nd = 10, xi_start = 0,
238-
xd_start = 0)
237+
@component function PID(; name, k = 1, Ti = false, Td = false, Nd = 10, int__x = 0,
238+
der__x = 0)
239239
with_I = !isequal(Ti, false)
240240
with_D = !isequal(Td, false)
241241
@named err_input = RealInput() # control error
@@ -249,12 +249,12 @@ See also [`LimPID`](@ref)
249249
@named gainPID = Gain(k)
250250
@named addPID = Add3()
251251
if with_I
252-
@named int = Integrator(k = 1 / Ti, x = xi_start)
252+
@named int = Integrator(k = 1 / Ti, x = int__x)
253253
else
254254
@named Izero = Constant(k = 0)
255255
end
256256
if with_D
257-
@named der = Derivative(k = Td, T = 1 / Nd, x = xd_start)
257+
@named der = Derivative(k = Td, T = 1 / Nd, x = der__x)
258258
else
259259
@named Dzero = Constant(k = 0)
260260
end
@@ -290,11 +290,9 @@ See also [`LimPID`](@ref)
290290
end
291291

292292
"""
293-
LimPI(; name, T, Ta, k = 1.0, x_start = 0.0, u_max = 1.0, u_min = -u_max)
293+
LimPI(; name, T, Ta, k = 1.0, int__x = 0.0, u_max = 1.0, u_min = -u_max)
294294
295295
Text-book version of a PI-controller with actuator saturation and anti-windup measure.
296-
Initial value of gain can be set with `gainPI.k`
297-
Initial value of integrator state `x` can be set with `int.x`
298296
299297
# Parameters:
300298
@@ -306,7 +304,7 @@ Initial value of integrator state `x` can be set with `int.x`
306304
- `err_input`
307305
- `ctr_output`
308306
"""
309-
@component function LimPI(; name, k = 1, T, u_max, u_min = -u_max, Ta, x_start = 0.0)
307+
@component function LimPI(; name, k = 1, T, u_max, u_min = -u_max, Ta, int__x = 0.0)
310308
@symcheck Ta > 0 ||
311309
throw(ArgumentError("Time constant `Ta` has to be strictly positive"))
312310
@symcheck T > 0 || throw(ArgumentError("Time constant `T` has to be strictly positive"))
@@ -316,7 +314,7 @@ Initial value of integrator state `x` can be set with `int.x`
316314
@named gainPI = Gain(k)
317315
@named addPI = Add()
318316
@named addTrack = Add()
319-
@named int = Integrator(k = 1 / T, x = x_start)
317+
@named int = Integrator(k = 1 / T, x = int__x)
320318
@named limiter = Limiter(y_max = u_max, y_min = u_min)
321319
@named addSat = Add(k1 = 1, k2 = -1)
322320
@named gainTrack = Gain(1 / Ta)
@@ -376,8 +374,8 @@ where the transfer function for the derivative includes additional filtering, se
376374
u_max = Inf,
377375
u_min = u_max > 0 ? -u_max : -Inf,
378376
gains = false,
379-
xi_start = 0.0,
380-
xd_start = 0.0)
377+
int__x = 0.0,
378+
der__x = 0.0)
381379
with_I = !isequal(Ti, false)
382380
with_D = !isequal(Td, false)
383381
with_AWM = Ni != Inf
@@ -412,12 +410,12 @@ where the transfer function for the derivative includes additional filtering, se
412410
else
413411
@named addI = Add(k1 = 1, k2 = -1)
414412
end
415-
@named int = Integrator(k = 1 / Ti, x = xi_start)
413+
@named int = Integrator(k = 1 / Ti, x = int__x)
416414
else
417415
@named Izero = Constant(k = 0)
418416
end
419417
if with_D
420-
@named der = Derivative(k = Td, T = 1 / Nd, x = xd_start)
418+
@named der = Derivative(k = Td, T = 1 / Nd, x = der__x)
421419
@named addD = Add(k1 = wd, k2 = -1)
422420
else
423421
@named Dzero = Constant(k = 0)
@@ -473,7 +471,7 @@ where the transfer function for the derivative includes additional filtering, se
473471
end
474472

475473
"""
476-
StateSpace(A, B, C, D=0; x_start=zeros(size(A,1)), u0=zeros(size(B,2)), y0=zeros(size(C,1)), name)
474+
StateSpace(A, B, C, D = 0; x = zeros(size(A,1)), u0 = zeros(size(B,2)), y0 = zeros(size(C,1)), name)
477475
478476
A linear, time-invariant state-space system on the form.
479477
@@ -506,7 +504,7 @@ y &= h(x, u)
506504
507505
linearized around the operating point `x₀, u₀`, we have `y0, u0 = h(x₀, u₀), u₀`.
508506
"""
509-
@component function StateSpace(; A, B, C, D = nothing, x_start = zeros(size(A, 1)), name,
507+
@component function StateSpace(; A, B, C, D = nothing, x = zeros(size(A, 1)), name,
510508
u0 = zeros(size(B, 2)), y0 = zeros(size(C, 1)))
511509
nx, nu, ny = size(A, 1), size(B, 2), size(C, 1)
512510
size(A, 2) == nx || error("`A` has to be a square matrix.")
@@ -522,7 +520,7 @@ linearized around the operating point `x₀, u₀`, we have `y0, u0 = h(x₀, u
522520
end
523521
@named input = RealInput(nin = nu)
524522
@named output = RealOutput(nout = ny)
525-
@variables x(t)[1:nx]=x_start [
523+
@variables x(t)[1:nx]=x [
526524
description = "State variables of StateSpace system $name",
527525
]
528526
# pars = @parameters A=A B=B C=C D=D # This is buggy

test/Blocks/continuous.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ end
9292
B = [0, 1]
9393
C = [0.9 1;]
9494
D = [0;;]
95-
@named ss = StateSpace(; A, B, C, D, x_start = zeros(2))
95+
@named ss = StateSpace(; A, B, C, D, x = zeros(2))
9696
@named c = Constant(; k = 1)
9797
@named model = ODESystem([
9898
connect(c.output, ss.input),
@@ -113,7 +113,7 @@ end
113113
# non-zero operating point
114114
u0 = [1] # This causes no effective input to the system since c.k = 1
115115
y0 = [2]
116-
@named ss = StateSpace(; A, B, C, D, x_start = zeros(2), u0, y0)
116+
@named ss = StateSpace(; A, B, C, D, x = zeros(2), u0, y0)
117117
@named model = ODESystem([
118118
connect(c.output, ss.input),
119119
],
@@ -133,11 +133,11 @@ end
133133
"""
134134
Second order demo plant
135135
"""
136-
@component function Plant(; name, x_start = zeros(2))
136+
@component function Plant(; name, x = zeros(2))
137137
@named input = RealInput()
138138
@named output = RealOutput()
139139
D = Differential(t)
140-
sts = @variables x1(t)=x_start[1] x2(t)=x_start[2]
140+
sts = @variables x1(t)=x[1] x2(t)=x[2]
141141
eqs = [D(x1) ~ x2
142142
D(x2) ~ -x1 - 0.5 * x2 + input.u
143143
output.u ~ 0.9 * x1 + x2]

0 commit comments

Comments
 (0)