Skip to content

Commit b7e49a7

Browse files
committed
add constructors and tests
1 parent 9c73a9e commit b7e49a7

File tree

4 files changed

+46
-7
lines changed

4 files changed

+46
-7
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "RobustAndOptimalControl"
22
uuid = "21fd56a4-db03-40ee-82ee-a87907bee541"
33
authors = ["Fredrik Bagge Carlson", "Marcus Greiff"]
4-
version = "0.2.4"
4+
version = "0.2.5"
55

66
[deps]
77
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"

src/named_systems2.jl

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,20 @@ function named_ss(sys::AbstractStateSpace{T};
140140
NamedStateSpace{T, typeof(sys)}(sys, x, u, y)
141141
end
142142

143+
"""
144+
named_ss(sys::AbstractStateSpace, name)
145+
146+
If a single name is provided, the outputs, inputs and states will be automatically named
147+
`y,u,x` with `name` as prefix.
148+
"""
149+
function named_ss(sys::AbstractStateSpace, name)
150+
named_ss(sys,
151+
x = Symbol(string(name)*"x"),
152+
y = Symbol(string(name)*"y"),
153+
u = Symbol(string(name)*"u"),
154+
)
155+
end
156+
143157
ControlSystems.ss(sys::NamedStateSpace) = ss(sys.sys)
144158

145159
iterable(s::Symbol) = [s]
@@ -510,12 +524,27 @@ function ExtendedStateSpace(P::NamedStateSpace; z=[], y=[], w=[], u=[])
510524
P.D[zi, wi], P.D[zi, ui], P.D[yi, wi], P.D[yi, ui], P.timeevol)
511525
end
512526

513-
function named_ss(sys::ExtendedStateSpace{T};
514-
x = [Symbol("x$i") for i in 1:sys.nx],
515-
u = [Symbol("u$i") for i in 1:sys.nu],
516-
y = [Symbol("y$i") for i in 1:sys.ny],
517-
w = [Symbol("w$i") for i in 1:sys.nw],
518-
z = [Symbol("z$i") for i in 1:sys.nz],
527+
"""
528+
named_ss(sys::ExtendedStateSpace; kwargs...)
529+
named_ss(sys::ExtendedStateSpace, name; kwargs...)
530+
531+
Assign names to an ExtendedStateSpace. If no specific names are provided for signals
532+
`z,y,w,u` and states`x`, names will be generated automatically.
533+
534+
# Arguments:
535+
- `name`: Prefix to add to all automatically generated names.
536+
- `x`
537+
- `u`
538+
- `y`
539+
- `w`
540+
- `z`
541+
"""
542+
function named_ss(sys::ExtendedStateSpace{T}, name="";
543+
x = Symbol(string(name)*"x"),
544+
u = Symbol(string(name)*"u"),
545+
y = Symbol(string(name)*"y"),
546+
w = Symbol(string(name)*"w"),
547+
z = Symbol(string(name)*"z"),
519548
) where T
520549
x = expand_symbol(x, sys.nx)
521550
u = expand_symbol(u, sys.nu)

test/test_extendedstatespace.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,8 @@ Ge = convert(ExtendedStateSpace{Continuous, Float64}, G)
3131
@test system_mapping(Ge) == G
3232
@test size(performance_mapping(Ge)) == (0,0)
3333
@test ss(Ge) == G
34+
35+
Ge2, G2 = promote(Ge, G)
36+
@test Ge2 == Ge
37+
@test G2 == partition(G, 0, 0) # Promoted to ess with empty performance model.
38+

test/test_named_systems2.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ s1 = named_ss(G1, x = [:x], u = :u, y=:y) # test providing only symbol
99
s2 = named_ss(G2, x = [:z], u = [:u], y=[:y])
1010
@show s1
1111

12+
s_autoname = named_ss(G1, :G)
13+
@test s_autoname.x == [:Gx]
14+
@test s_autoname.y == [:Gy]
15+
@test s_autoname.u == [:Gu]
16+
1217
@test s1[:y, :u] == s1
1318
@test s1[[:y], [:u]] == s1
1419

0 commit comments

Comments
 (0)