Skip to content

Commit ff96564

Browse files
committed
fix up examples and document list vs tuple more carefully
1 parent 8ad1e74 commit ff96564

File tree

3 files changed

+54
-53
lines changed

3 files changed

+54
-53
lines changed

control/iosys.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2724,12 +2724,13 @@ def interconnect(
27242724
'sysname.signal[i:j]' range of signal names, i through j-1
27252725
'sysname.signal[:]' all signals with given prefix
27262726
2727-
It is possible to replace lists in most of arguments with tuples
2728-
instead, but strictly speaking the only use of tuples should be in the
2727+
While in many Python functions tuples can be used in place of lists,
2728+
for the interconnect() function the only use of tuples should be in the
27292729
specification of an input- or output-signal via the tuple notation
27302730
`(subsys_i, signal_j, gain)` (where `gain` is optional). If you get an
2731-
unexpected error message about a specification being of the wrong type,
2732-
check your use of tuples.
2731+
unexpected error message about a specification being of the wrong type
2732+
or not being found, check to make sure you are not using a tuple where
2733+
you should be using a list.
27332734
27342735
In addition to its use for general nonlinear I/O systems, the
27352736
:func:`~control.interconnect` function allows linear systems to be

examples/cruise-control.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,13 @@ def motor_torque(omega, params={}):
140140
# Outputs: v (vehicle velocity)
141141
cruise_tf = ct.InterconnectedSystem(
142142
(control_tf, vehicle), name='cruise',
143-
connections=(
143+
connections=[
144144
['control.u', '-vehicle.v'],
145-
['vehicle.u', 'control.y']),
146-
inplist=('control.u', 'vehicle.gear', 'vehicle.theta'),
147-
inputs=('vref', 'gear', 'theta'),
148-
outlist=('vehicle.v', 'vehicle.u'),
149-
outputs=('v', 'u'))
145+
['vehicle.u', 'control.y']],
146+
inplist=['control.u', 'vehicle.gear', 'vehicle.theta'],
147+
inputs=['vref', 'gear', 'theta'],
148+
outlist=['vehicle.v', 'vehicle.u'],
149+
outputs=['v', 'u'])
150150

151151
# Define the time and input vectors
152152
T = np.linspace(0, 25, 101)
@@ -280,11 +280,11 @@ def pi_output(t, x, u, params={}):
280280
# Create the closed loop system
281281
cruise_pi = ct.InterconnectedSystem(
282282
(vehicle, control_pi), name='cruise',
283-
connections=(
283+
connections=[
284284
['vehicle.u', 'control.u'],
285-
['control.v', 'vehicle.v']),
286-
inplist=('control.vref', 'vehicle.gear', 'vehicle.theta'),
287-
outlist=('control.u', 'vehicle.v'), outputs=['u', 'v'])
285+
['control.v', 'vehicle.v']],
286+
inplist=['control.vref', 'vehicle.gear', 'vehicle.theta'],
287+
outlist=['control.u', 'vehicle.v'], outputs=['u', 'v'])
288288

289289
# Figure 4.3b shows the response of the closed loop system. The figure shows
290290
# that even if the hill is so steep that the throttle changes from 0.17 to
@@ -409,12 +409,12 @@ def sf_output(t, z, u, params={}):
409409
# Create the closed loop system for the state space controller
410410
cruise_sf = ct.InterconnectedSystem(
411411
(vehicle, control_sf), name='cruise',
412-
connections=(
412+
connections=[
413413
['vehicle.u', 'control.u'],
414414
['control.x', 'vehicle.v'],
415-
['control.y', 'vehicle.v']),
416-
inplist=('control.r', 'vehicle.gear', 'vehicle.theta'),
417-
outlist=('control.u', 'vehicle.v'), outputs=['u', 'v'])
415+
['control.y', 'vehicle.v']],
416+
inplist=['control.r', 'vehicle.gear', 'vehicle.theta'],
417+
outlist=['control.u', 'vehicle.v'], outputs=['u', 'v'])
418418

419419
# Compute the linearization of the dynamics around the equilibrium point
420420

examples/cruise.ipynb

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,13 @@
328328
"\n",
329329
"# Create the closed loop system for the state space controller\n",
330330
"cruise_sf = ct.InterconnectedSystem(\n",
331-
" (vehicle, control_sf), name='cruise',\n",
332-
" connections=(\n",
333-
" ('vehicle.u', 'control.u'),\n",
334-
" ('control.x', 'vehicle.v'),\n",
335-
" ('control.y', 'vehicle.v')),\n",
336-
" inplist=('control.r', 'vehicle.gear', 'vehicle.theta'),\n",
337-
" outlist=('control.u', 'vehicle.v'), outputs=['u', 'v'])\n",
331+
" [vehicle, control_sf], name='cruise',\n",
332+
" connections=[\n",
333+
" ['vehicle.u', 'control.u'],\n",
334+
" ['control.x', 'vehicle.v'],\n",
335+
" ['control.y', 'vehicle.v']],\n",
336+
" inplist=['control.r', 'vehicle.gear', 'vehicle.theta'],\n",
337+
" outlist=['control.u', 'vehicle.v'], outputs=['u', 'v'])\n",
338338
"\n",
339339
"# Define the time and input vectors\n",
340340
"T = np.linspace(0, 25, 501)\n",
@@ -460,14 +460,14 @@
460460
"# Construct the closed loop system and plot the response\n",
461461
"# Create the closed loop system for the state space controller\n",
462462
"cruise_pz = ct.InterconnectedSystem(\n",
463-
" (vehicle, control_pz), name='cruise_pz',\n",
464-
" connections = (\n",
465-
" ('control.u', '-vehicle.v'),\n",
466-
" ('vehicle.u', 'control.y')),\n",
467-
" inplist = ('control.u', 'vehicle.gear', 'vehicle.theta'),\n",
468-
" inputs = ('vref', 'gear', 'theta'),\n",
469-
" outlist = ('vehicle.v', 'vehicle.u'),\n",
470-
" outputs = ('v', 'u'))\n",
463+
" [vehicle, control_pz], name='cruise_pz',\n",
464+
" connections = [\n",
465+
" ['control.u', '-vehicle.v'],\n",
466+
" ['vehicle.u', 'control.y']],\n",
467+
" inplist = ['control.u', 'vehicle.gear', 'vehicle.theta'],\n",
468+
" inputs = ['vref', 'gear', 'theta'],\n",
469+
" outlist = ['vehicle.v', 'vehicle.u'],\n",
470+
" outputs = ['v', 'u'])\n",
471471
"\n",
472472
"# Find the equilibrium point\n",
473473
"X0, U0 = ct.find_eqpt(\n",
@@ -546,11 +546,11 @@
546546
" \n",
547547
" # Construct the closed loop system by interconnecting process and controller\n",
548548
" cruise_tf = ct.InterconnectedSystem(\n",
549-
" (vehicle, control_tf), name='cruise',\n",
550-
" connections = [('control.u', '-vehicle.v'), ('vehicle.u', 'control.y')],\n",
551-
" inplist = ('control.u', 'vehicle.gear', 'vehicle.theta'), \n",
552-
" inputs = ('vref', 'gear', 'theta'),\n",
553-
" outlist = ('vehicle.v', 'vehicle.u'), outputs = ('v', 'u'))\n",
549+
" [vehicle, control_tf], name='cruise',\n",
550+
" connections = [['control.u', '-vehicle.v'], ['vehicle.u', 'control.y']],\n",
551+
" inplist = ['control.u', 'vehicle.gear', 'vehicle.theta'], \n",
552+
" inputs = ['vref', 'gear', 'theta'],\n",
553+
" outlist = ['vehicle.v', 'vehicle.u'], outputs = ['v', 'u'])\n",
554554
"\n",
555555
" # Plot the velocity response\n",
556556
" X0, U0 = ct.find_eqpt(\n",
@@ -593,11 +593,11 @@
593593
" \n",
594594
" # Construct the closed loop system by interconnecting process and controller\n",
595595
" cruise_tf = ct.InterconnectedSystem(\n",
596-
" (vehicle, control_tf), name='cruise',\n",
597-
" connections = [('control.u', '-vehicle.v'), ('vehicle.u', 'control.y')],\n",
598-
" inplist = ('control.u', 'vehicle.gear', 'vehicle.theta'), \n",
599-
" inputs = ('vref', 'gear', 'theta'),\n",
600-
" outlist = ('vehicle.v', 'vehicle.u'), outputs = ('v', 'u'))\n",
596+
" [vehicle, control_tf], name='cruise',\n",
597+
" connections = [['control.u', '-vehicle.v'], ['vehicle.u', 'control.y']],\n",
598+
" inplist = ['control.u', 'vehicle.gear', 'vehicle.theta'], \n",
599+
" inputs = ['vref', 'gear', 'theta'],\n",
600+
" outlist = ['vehicle.v', 'vehicle.u'], outputs = ['v', 'u'])\n",
601601
"\n",
602602
" # Plot the velocity response\n",
603603
" X0, U0 = ct.find_eqpt(\n",
@@ -630,10 +630,10 @@
630630
" name='control', inputs='u', outputs='y')\n",
631631
"\n",
632632
"cruise_tf = ct.InterconnectedSystem(\n",
633-
" (vehicle, control_tf), name='cruise',\n",
634-
" connections = [('control.u', '-vehicle.v'), ('vehicle.u', 'control.y')],\n",
635-
" inplist = ('control.u', 'vehicle.gear', 'vehicle.theta'), inputs = ('vref', 'gear', 'theta'),\n",
636-
" outlist = ('vehicle.v', 'vehicle.u'), outputs = ('v', 'u'))"
633+
" [vehicle, control_tf], name='cruise',\n",
634+
" connections = [['control.u', '-vehicle.v'], ['vehicle.u', 'control.y']],\n",
635+
" inplist = ['control.u', 'vehicle.gear', 'vehicle.theta'], inputs = ['vref', 'gear', 'theta'],\n",
636+
" outlist = ['vehicle.v', 'vehicle.u'], outputs = ['v', 'u'])"
637637
]
638638
},
639639
{
@@ -750,12 +750,12 @@
750750
"\n",
751751
"# Create the closed loop system\n",
752752
"cruise_pi = ct.InterconnectedSystem(\n",
753-
" (vehicle, control_pi), name='cruise',\n",
754-
" connections=(\n",
755-
" ('vehicle.u', 'control.u'),\n",
756-
" ('control.v', 'vehicle.v')),\n",
757-
" inplist=('control.vref', 'vehicle.gear', 'vehicle.theta'),\n",
758-
" outlist=('control.u', 'vehicle.v'), outputs=['u', 'v'])"
753+
" [vehicle, control_pi], name='cruise',\n",
754+
" connections=[\n",
755+
" ['vehicle.u', 'control.u'],\n",
756+
" ['control.v', 'vehicle.v']],\n",
757+
" inplist=['control.vref', 'vehicle.gear', 'vehicle.theta'],\n",
758+
" outlist=['control.u', 'vehicle.v'], outputs=['u', 'v'])"
759759
]
760760
},
761761
{

0 commit comments

Comments
 (0)