@@ -2219,7 +2219,7 @@ def interconnect(
2219
2219
... inplist=['C'], outlist=['P'])
2220
2220
2221
2221
A feedback system can also be constructed using the
2222
- :func:`~control.summing_block ` function and the ability to
2222
+ :func:`~control.summing_junction ` function and the ability to
2223
2223
automatically interconnect signals with the same names:
2224
2224
2225
2225
>>> P = ct.tf(1, [1, 0], inputs='u', outputs='y')
@@ -2425,15 +2425,22 @@ def interconnect(
2425
2425
elif not found_system :
2426
2426
raise ValueError ("could not find signal %s" % sname )
2427
2427
else :
2428
- # Regular signal specification
2429
- if not isinstance (connection ,list ):
2430
- dprint (f" converting item to list" )
2431
- connection = [connection ]
2432
- for spec in connection :
2433
- isys ,indices ,gain = _parse_spec (syslist ,spec ,'input' )
2428
+ # TODO: refactor code to remove duplication
2429
+ if isinstance (connection ,list ):
2430
+ # Passed a list => create input map
2431
+ dprint (f" detected input list" )
2432
+ new_inplist .append ([])
2433
+ for spec in connection :
2434
+ isys ,indices ,gain = _parse_spec (syslist ,spec ,'input' )
2435
+ for isig in indices :
2436
+ new_inplist [- 1 ].append ((isys ,isig ,gain ))
2437
+ dprint (f" adding input{ (isys ,isig ,gain )} " )
2438
+ else :
2439
+ # Passed a single single => single input
2440
+ isys ,indices ,gain = _parse_spec (syslist ,connection ,'input' )
2434
2441
for isig in indices :
2435
- dprint (f" adding input{ (isys ,isig ,gain )} " )
2436
2442
new_inplist .append ((isys ,isig ,gain ))
2443
+ dprint (f" adding input{ (isys ,isig ,gain )} " )
2437
2444
inplist ,inputs = new_inplist ,new_inputs
2438
2445
dprint (f"{ inplist = } \n { inputs = } " )
2439
2446
@@ -2499,14 +2506,36 @@ def interconnect(
2499
2506
elif not found_system :
2500
2507
raise ValueError ("could not find signal %s" % sname )
2501
2508
else :
2502
- # Regular signal specification
2503
- if not isinstance (connection ,list ):
2504
- dprint (f" converting item to list" )
2505
- connection = [connection ]
2506
- for spec in connection :
2509
+ # TODO: refactor code to remove duplication
2510
+ if isinstance (connection ,list ):
2511
+ # Passed a list => create input map
2512
+ dprint (f" detected output list" )
2513
+ new_outlist .append ([])
2514
+ for spec in connection :
2515
+ try :
2516
+ # First trying looking in the output signals
2517
+ osys ,indices ,gain = _parse_spec (
2518
+ syslist ,spec ,'output' )
2519
+ for osig in indices :
2520
+ dprint (f" adding output{ (osys ,osig ,gain )} " )
2521
+ new_outlist [- 1 ].append ((osys ,osig ,gain ))
2522
+ except ValueError :
2523
+ # If not, see if we can find it in inputs
2524
+ isys ,indices ,gain = _parse_spec (
2525
+ syslist ,spec ,'input or output' ,
2526
+ dictname = 'input_index' )
2527
+ for isig in indices :
2528
+ # Use string form to allow searching input list
2529
+ dprint (f" adding input{ (isys ,isig ,gain )} " )
2530
+ new_outlist [- 1 ].append (
2531
+ (syslist [isys ].name ,
2532
+ syslist [isys ].input_labels [isig ],gain ))
2533
+ else :
2534
+ spec = connection
2507
2535
try :
2508
2536
# First trying looking in the output signals
2509
- osys ,indices ,gain = _parse_spec (syslist ,spec ,'output' )
2537
+ osys ,indices ,gain = _parse_spec (
2538
+ syslist ,spec ,'output' )
2510
2539
for osig in indices :
2511
2540
dprint (f" adding output{ (osys ,osig ,gain )} " )
2512
2541
new_outlist .append ((osys ,osig ,gain ))