Skip to content

Commit ca8f331

Browse files
committed
Test and fixes for hinfsyn. Needs fixed slycot.
Fixed call to sb10ad. Needs fixed slycot, e.g., [1] [1] roryyorke/Slycot@42cdeb8
1 parent cdd3e73 commit ca8f331

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

control/robust.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,12 @@ def hinfsyn(P,nmeas,ncon):
115115
K: controller to stabilize P (State-space sys)
116116
CL: closed loop system (State-space sys)
117117
gam: infinity norm of closed loop system
118-
info: info returned from siycot routine
118+
rcond: 4-vector, reciprocal condition estimates of:
119+
1: control transformation matrix
120+
2: measurement transformation matrix
121+
3: X-Ricatti equation
122+
4: Y-Ricatti equation
123+
TODO: document significance of rcond
119124
120125
Raises
121126
------
@@ -128,7 +133,7 @@ def hinfsyn(P,nmeas,ncon):
128133
129134
Examples
130135
--------
131-
>>> K, CL, gam, info = hinfsyn(P,nmeas,ncon)
136+
>>> K, CL, gam, rcond = hinfsyn(P,nmeas,ncon)
132137
133138
"""
134139

@@ -147,12 +152,11 @@ def hinfsyn(P,nmeas,ncon):
147152
except ImportError:
148153
raise ControlSlycot("can't find slycot subroutine sb10ad")
149154

150-
job = 3
151155
n = np.size(P.A,0)
152156
m = np.size(P.B,1)
153-
np = np.size(P.C,0)
157+
np_ = np.size(P.C,0)
154158
gamma = 1.e100
155-
out = sb10ad(job,n,m,np,ncon,nmeas,gamma,P.A,P.B,P.C,P.D)
159+
out = sb10ad(n,m,np_,ncon,nmeas,gamma,P.A,P.B,P.C,P.D)
156160
gam = out[0]
157161
Ak = out[1]
158162
Bk = out[2]
@@ -163,10 +167,8 @@ def hinfsyn(P,nmeas,ncon):
163167
Cc = out[7]
164168
Dc = out[8]
165169
rcond = out[9]
166-
info = out[10]
167170

168171
K = StateSpace(Ak, Bk, Ck, Dk)
169172
CL = StateSpace(Ac, Bc, Cc, Dc)
170173

171-
return K, CL, gam, info
172-
174+
return K, CL, gam, rcond

control/tests/robust_test.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import unittest
2+
import numpy as np
3+
import control
4+
import control.robust
5+
from control.exception import slycot_check
6+
7+
8+
class TestHinf(unittest.TestCase):
9+
@unittest.skipIf(not slycot_check(), "slycot not installed")
10+
def testHinfsyn(self):
11+
"Test hinfsyn"
12+
p = control.ss(-1, [1, 1], [[1], [1]], [[0, 1], [1, 0]])
13+
k, cl, gam, rcond = control.robust.hinfsyn(p, 1, 1)
14+
# from Octave, which also uses SB10AD:
15+
# a= -1; b1= 1; b2= 1; c1= 1; c2= 1; d11= 0; d12= 1; d21= 1; d22= 0;
16+
# g = ss(a,[b1,b2],[c1;c2],[d11,d12;d21,d22]);
17+
# [k,cl] = hinfsyn(g,1,1);
18+
np.testing.assert_array_almost_equal(k.A, [[-3]])
19+
np.testing.assert_array_almost_equal(k.B, [[1]])
20+
np.testing.assert_array_almost_equal(k.C, [[-1]])
21+
np.testing.assert_array_almost_equal(k.D, [[0]])
22+
np.testing.assert_array_almost_equal(cl.A, [[-1, -1], [1, -3]])
23+
np.testing.assert_array_almost_equal(cl.B, [[1], [1]])
24+
np.testing.assert_array_almost_equal(cl.C, [[1, -1]])
25+
np.testing.assert_array_almost_equal(cl.D, [[0]])
26+
27+
# TODO: add more interesting examples
28+
29+
30+
if __name__ == "__main__":
31+
unittest.main()

0 commit comments

Comments
 (0)