Skip to content

Commit 9edb6c6

Browse files
committed
Merge branch 'master' of https://github.com/python-control/python-control into lqe-consistent-lqr
2 parents 8bb11c4 + 120a926 commit 9edb6c6

4 files changed

Lines changed: 520 additions & 279 deletions

File tree

control/bdalg.py

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,16 @@ def connect(sys, Q, inputv, outputv):
302302
sys : StateSpace Transferfunction
303303
System to be connected
304304
Q : 2D array
305-
Interconnection matrix. First column gives the input to be connected
306-
second column gives the output to be fed into this input. Negative
307-
values for the second column mean the feedback is negative, 0 means
308-
no connection is made. Inputs and outputs are indexed starting at 1.
305+
Interconnection matrix. First column gives the input to be connected.
306+
The second column gives the index of an output that is to be fed into
307+
that input. Each additional column gives the index of an additional
308+
input that may be optionally added to that input. Negative
309+
values mean the feedback is negative. A zero value is ignored. Inputs
310+
and outputs are indexed starting at 1 to communicate sign information.
309311
inputv : 1D array
310-
list of final external inputs
312+
list of final external inputs, indexed starting at 1
311313
outputv : 1D array
312-
list of final external outputs
314+
list of final external outputs, indexed starting at 1
313315
314316
Returns
315317
-------
@@ -325,15 +327,34 @@ def connect(sys, Q, inputv, outputv):
325327
>>> sysc = connect(sys, Q, [2], [1, 2])
326328
327329
"""
330+
inputv, outputv, Q = np.asarray(inputv), np.asarray(outputv), np.asarray(Q)
331+
# check indices
332+
index_errors = (inputv - 1 > sys.inputs) | (inputv < 1)
333+
if np.any(index_errors):
334+
raise IndexError(
335+
"inputv index %s out of bounds" % inputv[np.where(index_errors)])
336+
index_errors = (outputv - 1 > sys.outputs) | (outputv < 1)
337+
if np.any(index_errors):
338+
raise IndexError(
339+
"outputv index %s out of bounds" % outputv[np.where(index_errors)])
340+
index_errors = (Q[:,0:1] - 1 > sys.inputs) | (Q[:,0:1] < 1)
341+
if np.any(index_errors):
342+
raise IndexError(
343+
"Q input index %s out of bounds" % Q[np.where(index_errors)])
344+
index_errors = (np.abs(Q[:,1:]) - 1 > sys.outputs)
345+
if np.any(index_errors):
346+
raise IndexError(
347+
"Q output index %s out of bounds" % Q[np.where(index_errors)])
348+
328349
# first connect
329350
K = np.zeros((sys.inputs, sys.outputs))
330351
for r in np.array(Q).astype(int):
331352
inp = r[0]-1
332353
for outp in r[1:]:
333-
if outp > 0 and outp <= sys.outputs:
334-
K[inp,outp-1] = 1.
335-
elif outp < 0 and -outp >= -sys.outputs:
354+
if outp < 0:
336355
K[inp,-outp-1] = -1.
356+
elif outp > 0:
357+
K[inp,outp-1] = 1.
337358
sys = sys.feedback(np.array(K), sign=1)
338359

339360
# now trim

0 commit comments

Comments
 (0)