Skip to content

Commit 27246f0

Browse files
fix: change certain defaults to guesses in Blocks
1 parent f2ddaa9 commit 27246f0

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

src/Blocks/continuous.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Initial value of integrator state ``x`` can be set with `x`
2020
@mtkmodel Integrator begin
2121
@extend u, y = siso = SISO()
2222
@variables begin
23-
x(t) = 0.0, [description = "State of Integrator"]
23+
x(t), [guess = 0.0, description = "State of Integrator"]
2424
end
2525
@parameters begin
2626
k = 1, [description = "Gain"]
@@ -65,7 +65,7 @@ Initial value of the state ``x`` can be set with `x`.
6565
@mtkmodel Derivative begin
6666
@extend u, y = siso = SISO()
6767
@variables begin
68-
x(t) = 0.0, [description = "Derivative-filter state"]
68+
x(t), [guess = 0.0, description = "Derivative-filter state"]
6969
end
7070
@parameters begin
7171
T = T, [description = "Time constant"]
@@ -122,7 +122,7 @@ See also [`SecondOrder`](@ref)
122122
lowpass = true
123123
end
124124
@variables begin
125-
x(t) = 0.0, [description = "State of FirstOrder filter"]
125+
x(t), [guess = 0.0, description = "State of FirstOrder filter"]
126126
end
127127
@parameters begin
128128
T = T, [description = "Time constant"]
@@ -545,7 +545,7 @@ linearized around the operating point `x₀, u₀`, we have `y0, u0 = h(x₀, u
545545
end
546546
@named input = RealInput(nin = nu)
547547
@named output = RealOutput(nout = ny)
548-
@variables x(t)[1:nx]=x [
548+
@variables x(t)[1:nx]=x [ # FIXME: should it be guess = x, not default?
549549
description = "State variables of StateSpace system $name"
550550
]
551551
# pars = @parameters A=A B=B C=C D=D # This is buggy
@@ -618,7 +618,7 @@ See also [`StateSpace`](@ref) which handles MIMO systems, as well as [ControlSys
618618
@parameters a_end = ifelse(a[end] > 100 * symbolic_eps(sqrt(a' * a)), a[end], 1.0)
619619

620620
pars = [collect(b); a; collect(bb); d; a_end]
621-
@variables begin
621+
@variables begin # FIXME: should it be guesses, not default?
622622
x(t)[1:nx] = zeros(nx),
623623
[description = "State of transfer function on controller canonical form"]
624624
x_scaled(t)[1:nx] = collect(x) * a_end, [description = "Scaled vector x"]

src/Blocks/utils.jl

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
@connector function RealInput(; name, nin = 1, u_start = nin > 1 ? zeros(nin) : 0.0)
22
if nin == 1
3-
@variables u(t)=u_start [
3+
@variables u(t) [
4+
guess = u_start,
45
input = true,
56
description = "Inner variable in RealInput $name"
67
]
78
else
8-
@variables u(t)[1:nin]=u_start [
9+
@variables u(t)[1:nin] [
10+
guess = u_start,
911
input = true,
1012
description = "Inner variable in RealInput $name"
1113
]
@@ -28,12 +30,14 @@ Connector with one input signal of type Real.
2830

2931
@connector function RealOutput(; name, nout = 1, u_start = nout > 1 ? zeros(nout) : 0.0)
3032
if nout == 1
31-
@variables u(t)=u_start [
33+
@variables u(t) [
34+
guess = u_start,
3235
output = true,
3336
description = "Inner variable in RealOutput $name"
3437
]
3538
else
36-
@variables u(t)[1:nout]=u_start [
39+
@variables u(t)[1:nout] [
40+
guess = u_start,
3741
output = true,
3842
description = "Inner variable in RealOutput $name"
3943
]
@@ -70,8 +74,8 @@ Single input single output (SISO) continuous system block.
7074
y_start = 0.0
7175
end
7276
@variables begin
73-
u(t) = u_start, [description = "Input of SISO system"]
74-
y(t) = y_start, [description = "Output of SISO system"]
77+
u(t), [guess = u_start, description = "Input of SISO system"]
78+
y(t), [guess = y_start, description = "Output of SISO system"]
7579
end
7680
@components begin
7781
input = RealInput(u_start = u_start)
@@ -99,8 +103,10 @@ Base class for a multiple input multiple output (MIMO) continuous system block.
99103
y_start = zeros(nout))
100104
@named input = RealInput(nin = nin, u_start = u_start)
101105
@named output = RealOutput(nout = nout, u_start = y_start)
102-
@variables(u(t)[1:nin]=u_start, [description = "Input of MIMO system $name"],
103-
y(t)[1:nout]=y_start, [description = "Output of MIMO system $name"],)
106+
@variables begin
107+
u(t)[1:nin], [guess = u_start, description = "Input of MIMO system $name"]
108+
y(t)[1:nout], [guess = y_start, description = "Output of MIMO system $name"]
109+
end
104110
eqs = [
105111
[u[i] ~ input.u[i] for i in 1:nin]...,
106112
[y[i] ~ output.u[i] for i in 1:nout]...

0 commit comments

Comments
 (0)