Skip to content

Commit 5271f77

Browse files
authored
Merge pull request #44 from baggepinnen/symin
allow symbols as inputs to `named_ss`
2 parents da606cf + 440c9aa commit 5271f77

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ControlSystemsMTK"
22
uuid = "687d7614-c7e5-45fc-bfc3-9ee385575c88"
33
authors = ["Fredrik Bagge Carlson"]
4-
version = "0.1.3"
4+
version = "0.1.4"
55

66
[deps]
77
ControlSystemsBase = "aaaaaaaa-a6ca-5380-bf3e-84a91bcd477e"

src/ode_system.jl

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -173,35 +173,40 @@ function RobustAndOptimalControl.named_ss(
173173
kwargs...,
174174
)
175175

176-
inputs = map(inputs) do inp
177-
if inp isa ODESystem
178-
@variables u(t)
179-
if u Set(states(inp))
180-
inp.u
176+
if inputs isa Symbol
177+
outputs isa Symbol || throw(ArgumentError("inputs and outputs must be either both symbols or both vectors of symbols"))
178+
nu = ny = 1
179+
else # map symbols to symbolic variables
180+
inputs = map(inputs) do inp
181+
if inp isa ODESystem
182+
@variables u(t)
183+
if u Set(states(inp))
184+
inp.u
185+
else
186+
error("Input $(inp.name) is an ODESystem and not a variable")
187+
end
181188
else
182-
error("Input $(inp.name) is an ODESystem and not a variable")
189+
inp
183190
end
184-
else
185-
inp
186191
end
187-
end
188-
outputs = map(outputs) do out
189-
if out isa ODESystem
190-
@variables u(t)
191-
if u Set(states(out))
192-
out.u
192+
outputs = map(outputs) do out
193+
if out isa ODESystem
194+
@variables u(t)
195+
if u Set(states(out))
196+
out.u
197+
else
198+
error("Outut $(out.name) is an ODESystem and not a variable")
199+
end
193200
else
194-
error("Outut $(out.name) is an ODESystem and not a variable")
201+
out
195202
end
196-
else
197-
out
198203
end
204+
nu = length(inputs)
205+
ny = length(outputs)
199206
end
200207
matrices, ssys = ModelingToolkit.linearize(sys, inputs, outputs; kwargs...)
201208
symstr(x) = Symbol(string(x))
202209
unames = symstr.(inputs)
203-
nu = length(inputs)
204-
ny = length(outputs)
205210
if size(matrices.B, 2) == 2nu
206211
nx = size(matrices.A, 1)
207212
# This indicates that input derivatives are present

0 commit comments

Comments
 (0)