Skip to content

Commit

Permalink
add show_construction for named systems
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Oct 22, 2024
1 parent 87cff6e commit a7b581b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ function show_construction(io::IO, sys::LTISystem; name = "temp", letb = true)
nothing
end

function show_construction(io::IO, sys::NamedStateSpace; name = "temp", letb = true)
# sys = StateSpace(sys)
letb && println(io, "$name = let")
prestr = letb ? " " : ""
println(io, prestr*"$(name)A = ", sys.A)
println(io, prestr*"$(name)B = ", sys.B)
println(io, prestr*"$(name)C = ", sys.C)
println(io, prestr*"$(name)D = ", sys.D)
letb || print(io, "$name = ")
if isdiscrete(sys)
println(io, prestr*"named_ss(ss($(name)A, $(name)B, $(name)C, $(name)D), $(sys.Ts), x=$(sys.x), u=$(sys.u), y=$(sys.y))")
else
println(io, prestr*"named_ss(ss($(name)A, $(name)B, $(name)C, $(name)D), x=$(sys.x), u=$(sys.u), y=$(sys.y))")
end
letb && println(io, "end")
nothing
end

function Base.vec(sys::LTISystem)
[vec(sys.A); vec(sys.B); vec(sys.C); vec(sys.D)]
end
Expand Down
2 changes: 2 additions & 0 deletions test/test_named_systems2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ s_autoname = named_ss(G1, :G)
@test s_autoname.y == [:Gy]
@test s_autoname.u == [:Gu]

@test_nowarn RobustAndOptimalControl.show_construction(s_autoname)

@test ControlSystemsBase.state_names(s_autoname) == string.(s_autoname.x)
@test ControlSystemsBase.input_names(s_autoname, 1) == string.(s_autoname.u[])
@test_throws BoundsError ControlSystemsBase.output_names(s_autoname, 2)
Expand Down

0 comments on commit a7b581b

Please sign in to comment.