Skip to content

Commit

Permalink
fix: change certain defaults to guesses in Blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
avinashresearch1 committed Apr 11, 2024
1 parent f2ddaa9 commit 27246f0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
10 changes: 5 additions & 5 deletions src/Blocks/continuous.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Initial value of integrator state ``x`` can be set with `x`
@mtkmodel Integrator begin
@extend u, y = siso = SISO()
@variables begin
x(t) = 0.0, [description = "State of Integrator"]
x(t), [guess = 0.0, description = "State of Integrator"]
end
@parameters begin
k = 1, [description = "Gain"]
Expand Down Expand Up @@ -65,7 +65,7 @@ Initial value of the state ``x`` can be set with `x`.
@mtkmodel Derivative begin
@extend u, y = siso = SISO()
@variables begin
x(t) = 0.0, [description = "Derivative-filter state"]
x(t), [guess = 0.0, description = "Derivative-filter state"]
end
@parameters begin
T = T, [description = "Time constant"]
Expand Down Expand Up @@ -122,7 +122,7 @@ See also [`SecondOrder`](@ref)
lowpass = true
end
@variables begin
x(t) = 0.0, [description = "State of FirstOrder filter"]
x(t), [guess = 0.0, description = "State of FirstOrder filter"]
end
@parameters begin
T = T, [description = "Time constant"]
Expand Down Expand Up @@ -545,7 +545,7 @@ linearized around the operating point `x₀, u₀`, we have `y0, u0 = h(x₀, u
end
@named input = RealInput(nin = nu)
@named output = RealOutput(nout = ny)
@variables x(t)[1:nx]=x [
@variables x(t)[1:nx]=x [ # FIXME: should it be guess = x, not default?

Check warning on line 548 in src/Blocks/continuous.jl

View check run for this annotation

Codecov / codecov/patch

src/Blocks/continuous.jl#L548

Added line #L548 was not covered by tests
description = "State variables of StateSpace system $name"
]
# pars = @parameters A=A B=B C=C D=D # This is buggy
Expand Down Expand Up @@ -618,7 +618,7 @@ See also [`StateSpace`](@ref) which handles MIMO systems, as well as [ControlSys
@parameters a_end = ifelse(a[end] > 100 * symbolic_eps(sqrt(a' * a)), a[end], 1.0)

pars = [collect(b); a; collect(bb); d; a_end]
@variables begin
@variables begin # FIXME: should it be guesses, not default?

Check warning on line 621 in src/Blocks/continuous.jl

View check run for this annotation

Codecov / codecov/patch

src/Blocks/continuous.jl#L621

Added line #L621 was not covered by tests
x(t)[1:nx] = zeros(nx),
[description = "State of transfer function on controller canonical form"]
x_scaled(t)[1:nx] = collect(x) * a_end, [description = "Scaled vector x"]
Expand Down
22 changes: 14 additions & 8 deletions src/Blocks/utils.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
@connector function RealInput(; name, nin = 1, u_start = nin > 1 ? zeros(nin) : 0.0)
if nin == 1
@variables u(t)=u_start [
@variables u(t) [

Check warning on line 3 in src/Blocks/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/Blocks/utils.jl#L3

Added line #L3 was not covered by tests
guess = u_start,
input = true,
description = "Inner variable in RealInput $name"
]
else
@variables u(t)[1:nin]=u_start [
@variables u(t)[1:nin] [

Check warning on line 9 in src/Blocks/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/Blocks/utils.jl#L9

Added line #L9 was not covered by tests
guess = u_start,
input = true,
description = "Inner variable in RealInput $name"
]
Expand All @@ -28,12 +30,14 @@ Connector with one input signal of type Real.

@connector function RealOutput(; name, nout = 1, u_start = nout > 1 ? zeros(nout) : 0.0)
if nout == 1
@variables u(t)=u_start [
@variables u(t) [

Check warning on line 33 in src/Blocks/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/Blocks/utils.jl#L33

Added line #L33 was not covered by tests
guess = u_start,
output = true,
description = "Inner variable in RealOutput $name"
]
else
@variables u(t)[1:nout]=u_start [
@variables u(t)[1:nout] [

Check warning on line 39 in src/Blocks/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/Blocks/utils.jl#L39

Added line #L39 was not covered by tests
guess = u_start,
output = true,
description = "Inner variable in RealOutput $name"
]
Expand Down Expand Up @@ -70,8 +74,8 @@ Single input single output (SISO) continuous system block.
y_start = 0.0
end
@variables begin
u(t) = u_start, [description = "Input of SISO system"]
y(t) = y_start, [description = "Output of SISO system"]
u(t), [guess = u_start, description = "Input of SISO system"]
y(t), [guess = y_start, description = "Output of SISO system"]
end
@components begin
input = RealInput(u_start = u_start)
Expand Down Expand Up @@ -99,8 +103,10 @@ Base class for a multiple input multiple output (MIMO) continuous system block.
y_start = zeros(nout))
@named input = RealInput(nin = nin, u_start = u_start)
@named output = RealOutput(nout = nout, u_start = y_start)
@variables(u(t)[1:nin]=u_start, [description = "Input of MIMO system $name"],
y(t)[1:nout]=y_start, [description = "Output of MIMO system $name"],)
@variables begin
u(t)[1:nin], [guess = u_start, description = "Input of MIMO system $name"]
y(t)[1:nout], [guess = y_start, description = "Output of MIMO system $name"]

Check warning on line 108 in src/Blocks/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/Blocks/utils.jl#L106-L108

Added lines #L106 - L108 were not covered by tests
end
eqs = [
[u[i] ~ input.u[i] for i in 1:nin]...,
[y[i] ~ output.u[i] for i in 1:nout]...
Expand Down

0 comments on commit 27246f0

Please sign in to comment.