45
45
from .statesp import StateSpace
46
46
from .statefbk import *
47
47
48
- def h2syn (P ,nmeas ,ncon ):
48
+
49
+ def h2syn (P , nmeas , ncon ):
49
50
"""H_2 control synthesis for plant P.
50
51
51
52
Parameters
@@ -72,25 +73,25 @@ def h2syn(P,nmeas,ncon):
72
73
>>> K = h2syn(P,nmeas,ncon)
73
74
74
75
"""
75
- #Check for ss system object, need a utility for this?
76
-
77
- #TODO: Check for continous or discrete, only continuous supported right now
78
- # if isCont():
79
- # dico = 'C'
80
- # elif isDisc():
81
- # dico = 'D'
82
- # else:
76
+ # Check for ss system object, need a utility for this?
77
+
78
+ # TODO: Check for continous or discrete, only continuous supported right now
79
+ # if isCont():
80
+ # dico = 'C'
81
+ # elif isDisc():
82
+ # dico = 'D'
83
+ # else:
83
84
dico = 'C'
84
85
85
86
try :
86
87
from slycot import sb10hd
87
88
except ImportError :
88
89
raise ControlSlycot ("can't find slycot subroutine sb10hd" )
89
90
90
- n = np .size (P .A ,0 )
91
- m = np .size (P .B ,1 )
92
- np_ = np .size (P .C ,0 )
93
- out = sb10hd (n ,m , np_ ,ncon ,nmeas ,P .A ,P .B ,P .C ,P .D )
91
+ n = np .size (P .A , 0 )
92
+ m = np .size (P .B , 1 )
93
+ np_ = np .size (P .C , 0 )
94
+ out = sb10hd (n , m , np_ , ncon , nmeas , P .A , P .B , P .C , P .D )
94
95
Ak = out [0 ]
95
96
Bk = out [1 ]
96
97
Ck = out [2 ]
@@ -100,7 +101,8 @@ def h2syn(P,nmeas,ncon):
100
101
101
102
return K
102
103
103
- def hinfsyn (P ,nmeas ,ncon ):
104
+
105
+ def hinfsyn (P , nmeas , ncon ):
104
106
"""H_{inf} control synthesis for plant P.
105
107
106
108
Parameters
@@ -136,26 +138,26 @@ def hinfsyn(P,nmeas,ncon):
136
138
137
139
"""
138
140
139
- #Check for ss system object, need a utility for this?
141
+ # Check for ss system object, need a utility for this?
140
142
141
- #TODO: Check for continous or discrete, only continuous supported right now
142
- # if isCont():
143
- # dico = 'C'
144
- # elif isDisc():
145
- # dico = 'D'
146
- # else:
143
+ # TODO: Check for continous or discrete, only continuous supported right now
144
+ # if isCont():
145
+ # dico = 'C'
146
+ # elif isDisc():
147
+ # dico = 'D'
148
+ # else:
147
149
dico = 'C'
148
150
149
151
try :
150
152
from slycot import sb10ad
151
153
except ImportError :
152
154
raise ControlSlycot ("can't find slycot subroutine sb10ad" )
153
155
154
- n = np .size (P .A ,0 )
155
- m = np .size (P .B ,1 )
156
- np_ = np .size (P .C ,0 )
156
+ n = np .size (P .A , 0 )
157
+ m = np .size (P .B , 1 )
158
+ np_ = np .size (P .C , 0 )
157
159
gamma = 1.e100
158
- out = sb10ad (n ,m , np_ ,ncon ,nmeas ,gamma ,P .A ,P .B ,P .C ,P .D )
160
+ out = sb10ad (n , m , np_ , ncon , nmeas , gamma , P .A , P .B , P .C , P .D )
159
161
gam = out [0 ]
160
162
Ak = out [1 ]
161
163
Bk = out [2 ]
@@ -202,21 +204,21 @@ def _size_as_needed(w, wname, n):
202
204
"""
203
205
from . import append , ss
204
206
if w is not None :
205
- if not isinstance (w ,StateSpace ):
207
+ if not isinstance (w , StateSpace ):
206
208
w = ss (w )
207
- if 1 == w .inputs and 1 == w .outputs :
208
- w = append (* (w ,)* n )
209
+ if 1 == w .inputs and 1 == w .outputs :
210
+ w = append (* (w ,) * n )
209
211
else :
210
212
if w .inputs != n :
211
- msg = ("{}: weighting function has {} inputs, expected {}" .
212
- format (wname ,w .inputs ,n ))
213
+ msg = ("{}: weighting function has {} inputs, expected {}" .
214
+ format (wname , w .inputs , n ))
213
215
raise ValueError (msg )
214
216
else :
215
- w = ss ([],[],[],[])
217
+ w = ss ([], [], [], [])
216
218
return w
217
219
218
220
219
- def augw (g ,w1 = None ,w2 = None ,w3 = None ):
221
+ def augw (g , w1 = None , w2 = None , w3 = None ):
220
222
"""Augment plant for mixed sensitivity problem.
221
223
222
224
Parameters
@@ -254,12 +256,12 @@ def augw(g,w1=None,w2=None,w3=None):
254
256
ny = g .outputs
255
257
nu = g .inputs
256
258
257
- w1 ,w2 ,w3 = [_size_as_needed (w ,wname ,n )
258
- for w ,wname ,n in zip ((w1 ,w2 ,w3 ),
259
- ('w1' ,'w2' ,'w3' ),
260
- (ny ,nu ,ny ))]
259
+ w1 , w2 , w3 = [_size_as_needed (w , wname , n )
260
+ for w , wname , n in zip ((w1 , w2 , w3 ),
261
+ ('w1' , 'w2' , 'w3' ),
262
+ (ny , nu , ny ))]
261
263
262
- if not isinstance (g ,StateSpace ):
264
+ if not isinstance (g , StateSpace ):
263
265
g = ss (g )
264
266
265
267
# w u
@@ -270,11 +272,11 @@ def augw(g,w1=None,w2=None,w3=None):
270
272
# v [ I | -g ]
271
273
272
274
# error summer: inputs are -y and r=w
273
- Ie = ss ([],[],[],np .eye (ny ))
275
+ Ie = ss ([], [], [], np .eye (ny ))
274
276
# control: needed to "distribute" control input
275
- Iu = ss ([],[],[],np .eye (nu ))
277
+ Iu = ss ([], [], [], np .eye (nu ))
276
278
277
- sysall = append (w1 ,w2 ,w3 ,Ie ,g , Iu )
279
+ sysall = append (w1 , w2 , w3 , Ie , g , Iu )
278
280
279
281
niw1 = w1 .inputs
280
282
niw2 = w2 .inputs
@@ -284,43 +286,45 @@ def augw(g,w1=None,w2=None,w3=None):
284
286
now2 = w2 .outputs
285
287
now3 = w3 .outputs
286
288
287
- q = np .zeros ((niw1 + niw2 + niw3 + ny + nu ,2 ))
288
- q [:,0 ] = np .arange (1 ,q .shape [0 ]+ 1 )
289
+ q = np .zeros ((niw1 + niw2 + niw3 + ny + nu , 2 ))
290
+ q [:, 0 ] = np .arange (1 , q .shape [0 ] + 1 )
289
291
290
292
# Ie -> w1
291
- q [:niw1 ,1 ] = np .arange (1 + now1 + now2 + now3 ,
292
- 1 + now1 + now2 + now3 + niw1 )
293
+ q [:niw1 , 1 ] = np .arange (1 + now1 + now2 + now3 ,
294
+ 1 + now1 + now2 + now3 + niw1 )
293
295
294
296
# Iu -> w2
295
- q [niw1 :niw1 + niw2 ,1 ] = np .arange (1 + now1 + now2 + now3 + 2 * ny ,
296
- 1 + now1 + now2 + now3 + 2 * ny + niw2 )
297
+ q [niw1 :niw1 + niw2 , 1 ] = np .arange (1 + now1 + now2 + now3 + 2 * ny ,
298
+ 1 + now1 + now2 + now3 + 2 * ny + niw2 )
297
299
298
300
# y -> w3
299
- q [niw1 + niw2 :niw1 + niw2 + niw3 ,1 ] = np .arange (1 + now1 + now2 + now3 + ny ,
300
- 1 + now1 + now2 + now3 + ny + niw3 )
301
+ q [niw1 + niw2 :niw1 + niw2 + niw3 , 1 ] = np .arange (1 + now1 + now2 + now3 + ny ,
302
+ 1 + now1 + now2 + now3 + ny + niw3 )
301
303
302
304
# -y -> Iy; note the leading -
303
- q [niw1 + niw2 + niw3 :niw1 + niw2 + niw3 + ny ,1 ] = - np .arange (1 + now1 + now2 + now3 + ny ,
304
- 1 + now1 + now2 + now3 + 2 * ny )
305
+ q [niw1 + niw2 + niw3 :niw1 + niw2 + niw3 + ny , 1 ] = - np .arange (1 + now1 + now2 + now3 + ny ,
306
+ 1 + now1 + now2 + now3 + 2 * ny )
305
307
306
308
# Iu -> G
307
- q [niw1 + niw2 + niw3 + ny :niw1 + niw2 + niw3 + ny + nu ,1 ] = np .arange (1 + now1 + now2 + now3 + 2 * ny ,
308
- 1 + now1 + now2 + now3 + 2 * ny + nu )
309
+ q [niw1 + niw2 + niw3 + ny :niw1 + niw2 + niw3 + ny + nu , 1 ] = np .arange (
310
+ 1 + now1 + now2 + now3 + 2 * ny ,
311
+ 1 + now1 + now2 + now3 + 2 * ny + nu )
309
312
310
313
# input indices: to Ie and Iu
311
- ii = np .hstack ((np .arange (1 + now1 + now2 + now3 ,
312
- 1 + now1 + now2 + now3 + ny ),
313
- np .arange (1 + now1 + now2 + now3 + ny + nu ,
314
- 1 + now1 + now2 + now3 + ny + nu + nu )))
314
+ ii = np .hstack ((np .arange (1 + now1 + now2 + now3 ,
315
+ 1 + now1 + now2 + now3 + ny ),
316
+ np .arange (1 + now1 + now2 + now3 + ny + nu ,
317
+ 1 + now1 + now2 + now3 + ny + nu + nu )))
315
318
316
319
# output indices
317
- oi = np .arange (1 ,1 + now1 + now2 + now3 + ny )
320
+ oi = np .arange (1 , 1 + now1 + now2 + now3 + ny )
318
321
319
- p = connect (sysall ,q , ii ,oi )
322
+ p = connect (sysall , q , ii , oi )
320
323
321
324
return p
322
325
323
- def mixsyn (g ,w1 = None ,w2 = None ,w3 = None ):
326
+
327
+ def mixsyn (g , w1 = None , w2 = None , w3 = None ):
324
328
"""Mixed-sensitivity H-infinity synthesis.
325
329
326
330
mixsyn(g,w1,w2,w3) -> k,cl,info
@@ -356,8 +360,8 @@ def mixsyn(g,w1=None,w2=None,w3=None):
356
360
"""
357
361
nmeas = g .outputs
358
362
ncon = g .inputs
359
- p = augw (g ,w1 ,w2 ,w3 )
363
+ p = augw (g , w1 , w2 , w3 )
360
364
361
- k ,cl ,gamma ,rcond = hinfsyn (p ,nmeas ,ncon )
362
- info = gamma ,rcond
363
- return k ,cl ,info
365
+ k , cl , gamma , rcond = hinfsyn (p , nmeas , ncon )
366
+ info = gamma , rcond
367
+ return k , cl , info
0 commit comments