Skip to content

Commit dbe0208

Browse files
committed
add hinf tests
1 parent aa29df2 commit dbe0208

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

test/runtests.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ using Test
5050
include("test_hinf_design.jl")
5151
end
5252

53+
@testset "manual_hinf" begin
54+
@info "Testing manual_hinf"
55+
include("test_manual_hinf.jl")
56+
end
57+
5358
@testset "H2 design" begin
5459
@info "Testing H2 design"
5560
include("test_h2_design.jl")

test/test_manual_hinf.jl

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using RobustAndOptimalControl, ControlSystems, Plots
2+
P = named_ss(ss(tf(1, [1, 0.1, 1])), :P)
3+
We = named_ss(makeweight(10, 1, 0.1), :We, u=:y, y=:e) # We care a lot about the error on low frequencies
4+
Wu = named_ss(0.01makeweight(1e-3, 10, 10), :Wu, u=:Wu, y=:uw) # Above ω=100, we want to limit the control effort
5+
# Wd = named_ss(makeweight(1, 1, 1e-3), :Wd, u=:do, y=:d) # d is low frequency
6+
Wd = named_ss(ss(1), :Wd, u=:do, y=:d)
7+
8+
sumP = sumblock("y = Py + d")
9+
10+
11+
split_u = splitter(:u, 2)
12+
13+
14+
connections = [
15+
:u1 => :Wu # splitter to input of Wu
16+
:u2 => :Pu # splitter to input of P
17+
:Py => :Py # P output to first input of sumblock
18+
:d => :d # output of Wd to second input of sumblock
19+
:y => :y # output of sumblock to input of We
20+
];
21+
22+
w1 = [ # External inputs
23+
:do, :u
24+
]
25+
z1 = [ # External outputs
26+
:e, :uw, :y
27+
];
28+
29+
G = connect([P,We,Wu,Wd,sumP,split_u], connections; z1, w1)
30+
31+
Gsyn = partition(G, u = [:u], y = [:y]) # You can provide either u or w, and either y or z
32+
K, γ, info = hinfsynthesize(Gsyn, γrel=1.001, interval = (0.1, 20), transform=false)
33+
34+
35+
Gsyn2 = hinfpartition(P, We.sys, Wu.sys, [])
36+
K2, γ2 = hinfsynthesize(Gsyn2, γrel=1.001, interval = (0.1, 20), transform=false)
37+
38+
@test γ 0.3148 atol=1e-2 # value by slicot
39+
@test γ γ2 atol=1e-3
40+
41+
@test hinfnorm2(lft(Gsyn, K))[1] γ atol=1e-2
42+
@test hinfnorm2(lft(Gsyn2, K2))[1] γ2 atol=1e-2
43+
44+
45+
@test hinfnorm2(K+K2)[1] < 1e-6
46+
47+
48+
Pcl, S, CS, T = hinfsignals(Gsyn, P, K)
49+
50+
@test hinfnorm2(Pcl)[1] γ atol=1e-2
51+
@test hinfnorm2(lft(Gsyn, K))[1] γ atol=1e-2
52+
@test hinfnorm2(lft(Gsyn2, K2))[1] γ2 atol=1e-2
53+
54+
55+
# Controller by slicot, test if hinfnorm is the same
56+
Km = let
57+
tempA = [0.0 1.0 0.0 0.0; -227.5648 -32.5972 -703.6977 -117.9357; 0.0 0.0 -0.1 0.0; -226.5648 -32.4972 -703.6977 -217.4345]
58+
tempB = [-0.0; -0.0; 1.0; 0.0;;]
59+
tempC = [-226.5648 -32.4972 -703.6977 -117.9357]
60+
tempD = [0.0;;]
61+
ss(tempA, tempB, tempC, tempD)
62+
end
63+
64+
@test hinfnorm2(lft(Gsyn, Km))[1] 0.3148 atol=1e-3
65+
@test hinfnorm(lft(Gsyn, Km))[1] 0.3148 atol=1e-3
66+
67+
68+

0 commit comments

Comments
 (0)