Skip to content

Commit ada3eb2

Browse files
committed
automatic signal summing and splitting (fix)
1 parent d75c395 commit ada3eb2

File tree

2 files changed

+20
-24
lines changed

2 files changed

+20
-24
lines changed

control/iosys.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,25 +2042,25 @@ def interconnect(syslist, connections=None, inplist=[], outlist=[],
20422042
inplist = [inplist]
20432043
new_inplist = []
20442044
for signal in inplist:
2045+
# Create an empty connection and append to inplist
2046+
connection = []
2047+
20452048
# Check for signal names without a system name
20462049
if isinstance(signal, str) and len(signal.split('.')) == 1:
20472050
# Get the signal name
20482051
name = signal[1:] if signal[0] == '-' else signal
20492052
sign = '-' if signal[0] == '-' else ""
20502053

20512054
# Look for the signal name as a system input
2052-
new_name = None
20532055
for sys in syslist:
20542056
if name in sys.input_index.keys():
2055-
if new_name is not None:
2056-
raise ValueError("signal %s is not unique" % name)
2057-
new_name = sign + sys.name + "." + name
2057+
connection.append(sign + sys.name + "." + name)
20582058

20592059
# Make sure we found the name
2060-
if new_name is None:
2060+
if len(connection) == 0:
20612061
raise ValueError("could not find signal %s" % name)
20622062
else:
2063-
new_inplist.append(new_name)
2063+
new_inplist.append(connection)
20642064
else:
20652065
new_inplist.append(signal)
20662066
inplist = new_inplist
@@ -2070,25 +2070,25 @@ def interconnect(syslist, connections=None, inplist=[], outlist=[],
20702070
outlist = [outlist]
20712071
new_outlist = []
20722072
for signal in outlist:
2073+
# Create an empty connection and append to inplist
2074+
connection = []
2075+
20732076
# Check for signal names without a system name
20742077
if isinstance(signal, str) and len(signal.split('.')) == 1:
20752078
# Get the signal name
20762079
name = signal[1:] if signal[0] == '-' else signal
20772080
sign = '-' if signal[0] == '-' else ""
20782081

20792082
# Look for the signal name as a system output
2080-
new_name = None
20812083
for sys in syslist:
20822084
if name in sys.output_index.keys():
2083-
if new_name is not None:
2084-
raise ValueError("signal %s is not unique" % name)
2085-
new_name = sign + sys.name + "." + name
2085+
connection.append(sign + sys.name + "." + name)
20862086

20872087
# Make sure we found the name
2088-
if new_name is None:
2088+
if len(connection) == 0:
20892089
raise ValueError("could not find signal %s" % name)
20902090
else:
2091-
new_outlist.append(new_name)
2091+
new_outlist.append(connection)
20922092
else:
20932093
new_outlist.append(signal)
20942094
outlist = new_outlist

control/tests/interconnect_test.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,14 @@ def test_interconnect_implicit():
119119
# inputs=['r', '-y'], output='e', dimension=2)
120120
# S = control.interconnect([P, C, sumblk], inplist='r', outlist='y')
121121

122-
# Make sure that repeated inplist/outlist names generate an error
123-
# Input not unique
124-
Cbad = ct.tf2io(ct.tf(10, [1, 1]), inputs='r', outputs='x', name='C')
125-
with pytest.raises(ValueError, match="not unique"):
126-
Tio_sum = ct.interconnect(
127-
(Cbad, P, sumblk), inplist=['r'], outlist=['y'])
128-
129-
# Output not unique
130-
Cbad = ct.tf2io(ct.tf(10, [1, 1]), inputs='e', outputs='y', name='C')
131-
with pytest.raises(ValueError, match="not unique"):
132-
Tio_sum = ct.interconnect(
133-
(Cbad, P, sumblk), inplist=['r'], outlist=['y'])
122+
# Make sure that repeated inplist/outlist names work
123+
pi_io = ct.interconnect(
124+
(kp_io, ki_io), inplist=['e'], outlist=['u'])
125+
pi_ss = ct.tf2ss(kp + ki)
126+
np.testing.assert_almost_equal(pi_io.A, pi_ss.A)
127+
np.testing.assert_almost_equal(pi_io.B, pi_ss.B)
128+
np.testing.assert_almost_equal(pi_io.C, pi_ss.C)
129+
np.testing.assert_almost_equal(pi_io.D, pi_ss.D)
134130

135131
# Signal not found
136132
with pytest.raises(ValueError, match="could not find"):

0 commit comments

Comments
 (0)