Skip to content

Commit c4c275f

Browse files
committed
remove imports and use ct.fcn instead
1 parent c913c8f commit c4c275f

27 files changed

+243
-360
lines changed

control/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,23 @@
4242
"""
4343
The Python Control Systems Library :mod:`control` provides common functions
4444
for analyzing and designing feedback control systems.
45+
46+
Documentation is available in two forms: docstrings provided with the code,
47+
and the python-control users guide, available from `the python-control
48+
homepage <https://www.python-control.org>`_.
49+
50+
The docstring examples assume that the following import commands::
51+
52+
>>> import numpy as np
53+
>>> import control as ct
54+
55+
Available subpackages
56+
---------------------
57+
flatsys
58+
Differentially flat systems
59+
optimal
60+
Optimization-based control
61+
4562
"""
4663

4764
# Import functions from within the control system library

control/bdalg.py

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,15 @@ def series(sys1, *sysn):
9999
100100
Examples
101101
--------
102-
>>> from control import rss, series
103-
104-
>>> G1 = rss(3)
105-
>>> G2 = rss(4)
106-
>>> G = series(G1, G2) # Same as sys3 = sys2 * sys1
102+
>>> G1 = ct.rss(3)
103+
>>> G2 = ct.rss(4)
104+
>>> G = ct.series(G1, G2) # Same as sys3 = sys2 * sys1
107105
>>> G.ninputs, G.noutputs, G.nstates
108106
(1, 1, 7)
109107
110-
>>> G1 = rss(2, inputs=2, outputs=3)
111-
>>> G2 = rss(3, inputs=3, outputs=1)
112-
>>> G = series(G1, G2) # Same as sys3 = sys2 * sys1
108+
>>> G1 = ct.rss(2, inputs=2, outputs=3)
109+
>>> G2 = ct.rss(3, inputs=3, outputs=1)
110+
>>> G = ct.series(G1, G2) # Same as sys3 = sys2 * sys1
113111
>>> G.ninputs, G.noutputs, G.nstates
114112
(2, 1, 5)
115113
@@ -156,17 +154,15 @@ def parallel(sys1, *sysn):
156154
157155
Examples
158156
--------
159-
>>> from control import parallel, rss
160-
161-
>>> G1 = rss(3)
162-
>>> G2 = rss(4)
163-
>>> G = parallel(G1, G2) # Same as sys3 = sys1 + sys2
157+
>>> G1 = ct.rss(3)
158+
>>> G2 = ct.rss(4)
159+
>>> G = ct.parallel(G1, G2) # Same as sys3 = sys1 + sys2
164160
>>> G.ninputs, G.noutputs, G.nstates
165161
(1, 1, 7)
166162
167-
>>> G1 = rss(3, inputs=3, outputs=4)
168-
>>> G2 = rss(4, inputs=3, outputs=4)
169-
>>> G = parallel(G1, G2) # Add another system
163+
>>> G1 = ct.rss(3, inputs=3, outputs=4)
164+
>>> G2 = ct.rss(4, inputs=3, outputs=4)
165+
>>> G = ct.parallel(G1, G2) # Add another system
170166
>>> G.ninputs, G.noutputs, G.nstates
171167
(3, 4, 7)
172168
@@ -194,13 +190,11 @@ def negate(sys):
194190
195191
Examples
196192
--------
197-
>>> from control import negate, tf
198-
199-
>>> G = tf([2],[1, 1])
193+
>>> G = ct.tf([2],[1, 1])
200194
>>> G.dcgain() > 0
201195
True
202196
203-
>>> Gn = negate(G) # Same as sys2 = -sys1.
197+
>>> Gn = ct.negate(G) # Same as sys2 = -sys1.
204198
>>> Gn.dcgain() < 0
205199
True
206200
@@ -252,11 +246,9 @@ def feedback(sys1, sys2=1, sign=-1):
252246
253247
Examples
254248
--------
255-
>>> from control import feedback, rss
256-
257-
>>> G = rss(3, inputs=2, outputs=5)
258-
>>> C = rss(4, inputs=5, outputs=2)
259-
>>> T = feedback(G, C, sign=1)
249+
>>> G = ct.rss(3, inputs=2, outputs=5)
250+
>>> C = ct.rss(4, inputs=5, outputs=2)
251+
>>> T = ct.feedback(G, C, sign=1)
260252
>>> T.ninputs, T.noutputs, T.nstates
261253
(2, 5, 7)
262254
@@ -316,17 +308,15 @@ def append(*sys):
316308
317309
Examples
318310
--------
319-
>>> from control import append, rss
320-
>>> G1 = rss(3)
321-
322-
>>> G2 = rss(4)
323-
>>> G = append(G1, G2)
311+
>>> G1 = ct.rss(3)
312+
>>> G2 = ct.rss(4)
313+
>>> G = ct.append(G1, G2)
324314
>>> G.ninputs, G.noutputs, G.nstates
325315
(2, 2, 7)
326316
327-
>>> G1 = rss(3, inputs=2, outputs=4)
328-
>>> G2 = rss(4, inputs=1, outputs=4)
329-
>>> G = append(G1, G2)
317+
>>> G1 = ct.rss(3, inputs=2, outputs=4)
318+
>>> G2 = ct.rss(4, inputs=1, outputs=4)
319+
>>> G = ct.append(G1, G2)
330320
>>> G.ninputs, G.noutputs, G.nstates
331321
(3, 8, 7)
332322
@@ -371,11 +361,9 @@ def connect(sys, Q, inputv, outputv):
371361
372362
Examples
373363
--------
374-
>>> from control import append, connect, rss
375-
376-
>>> G = rss(7, inputs=2, outputs=2)
364+
>>> G = ct.rss(7, inputs=2, outputs=2)
377365
>>> K = [[1, 2], [2, -1]] # negative feedback interconnection
378-
>>> T = connect(G, K, [2], [1, 2])
366+
>>> T = ct.connect(G, K, [2], [1, 2])
379367
>>> T.ninputs, T.noutputs, T.nstates
380368
(1, 2, 7)
381369

control/canonical.py

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,18 @@ def canonical_form(xsys, form='reachable'):
3939
4040
Examples
4141
--------
42-
>>> from control import canonical_form, tf, tf2ss
43-
44-
>>> G = tf([1],[1, 3, 2])
45-
>>> Gs = tf2ss(G)
46-
47-
>>> Gc, T = canonical_form(Gs) # default reachable
42+
>>> G = ct.tf([1],[1, 3, 2])
43+
>>> Gs = ct.tf2ss(G)
44+
>>> Gc, T = ct.canonical_form(Gs) # default reachable
4845
>>> Gc.B # doctest: +SKIP
4946
matrix([[1.],
5047
[0.]])
5148
52-
>>> Gc, T = canonical_form(Gs, 'observable')
49+
>>> Gc, T = ct.canonical_form(Gs, 'observable')
5350
>>> Gc.C # doctest: +SKIP
5451
matrix([[1., 0.]])
5552
56-
>>> Gc, T = canonical_form(Gs, 'modal')
53+
>>> Gc, T = ct.canonical_form(Gs, 'modal')
5754
>>> Gc.A # doctest: +SKIP
5855
matrix([[-2., 0.],
5956
[ 0., -1.]])
@@ -90,12 +87,9 @@ def reachable_form(xsys):
9087
9188
Examples
9289
--------
93-
>>> from control import reachable_form, tf, tf2ss
94-
95-
>>> G = tf([1],[1, 3, 2])
96-
>>> Gs = tf2ss(G)
97-
98-
>>> Gc, T = reachable_form(Gs) # default reachable
90+
>>> G = ct.tf([1],[1, 3, 2])
91+
>>> Gs = ct.tf2ss(G)
92+
>>> Gc, T = ct.reachable_form(Gs) # default reachable
9993
>>> Gc.B # doctest: +SKIP
10094
matrix([[1.],
10195
[0.]])
@@ -157,12 +151,9 @@ def observable_form(xsys):
157151
158152
Examples
159153
--------
160-
>>> from control import observable_form, tf, tf2ss
161-
162-
>>> G = tf([1],[1, 3, 2])
163-
>>> Gs = tf2ss(G)
164-
165-
>>> Gc, T = observable_form(Gs)
154+
>>> G = ct.tf([1],[1, 3, 2])
155+
>>> Gs = ct.tf2ss(G)
156+
>>> Gc, T = ct.observable_form(Gs)
166157
>>> Gc.C # doctest: +SKIP
167158
matrix([[1., 0.]])
168159
@@ -227,17 +218,14 @@ def similarity_transform(xsys, T, timescale=1, inverse=False):
227218
228219
Examples
229220
--------
230-
>>> import numpy as np
231-
>>> from control import similarity_transform, tf, tf2ss
232-
233-
>>> G = tf([1],[1, 3, 2])
234-
>>> Gs = tf2ss(G)
221+
>>> G = ct.tf([1],[1, 3, 2])
222+
>>> Gs = ct.tf2ss(G)
235223
>>> Gs.A # doctest: +SKIP
236224
matrix([[-3., -2.],
237225
[ 1., 0.]])
238226
239227
>>> T = np.array([[0,1],[1,0]])
240-
>>> Gt = similarity_transform(Gs, T)
228+
>>> Gt = ct.similarity_transform(Gs, T)
241229
>>> Gt.A # doctest: +SKIP
242230
matrix([[ 0., 1.],
243231
[-2., -3.]])
@@ -438,11 +426,9 @@ def bdschur(a, condmax=None, sort=None):
438426
439427
Examples
440428
--------
441-
>>> from control import bdschur, tf, tf2ss
442-
443-
>>> G = tf([1],[1, 3, 2])
444-
>>> Gs = tf2ss(G)
445-
>>> amodal, tmodal, blksizes = bdschur(Gs.A)
429+
>>> G = ct.tf([1],[1, 3, 2])
430+
>>> Gs = ct.tf2ss(G)
431+
>>> amodal, tmodal, blksizes = ct.bdschur(Gs.A)
446432
>>> amodal #doctest: +SKIP
447433
array([[-2., 0.],
448434
[ 0., -1.]])
@@ -516,12 +502,9 @@ def modal_form(xsys, condmax=None, sort=False):
516502
517503
Examples
518504
--------
519-
>>> from control import modal_form, tf, tf2ss
520-
521-
>>> G = tf([1],[1, 3, 2])
522-
>>> Gs = tf2ss((G))
523-
524-
>>> Gc, T = modal_form(Gs) # default reachable
505+
>>> G = ct.tf([1],[1, 3, 2])
506+
>>> Gs = ct.tf2ss((G))
507+
>>> Gc, T = ct.modal_form(Gs) # default reachable
525508
>>> Gc.A # doctest: +SKIP
526509
matrix([[-2., 0.],
527510
[ 0., -1.]])

control/config.py

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,15 @@ def set_defaults(module, **keywords):
6969
7070
Examples
7171
--------
72-
>>> from control import defaults, reset_defaults, set_defaults
73-
74-
>>> defaults['freqplot.number_of_samples']
72+
>>> ct.defaults['freqplot.number_of_samples']
7573
1000
76-
>>> set_defaults('freqplot', number_of_samples=100)
77-
>>> defaults['freqplot.number_of_samples']
74+
>>> ct.set_defaults('freqplot', number_of_samples=100)
75+
>>> ct.defaults['freqplot.number_of_samples']
7876
100
7977
8078
>>> # do some customized freqplotting
81-
>>> reset_defaults()
82-
>>> defaults['freqplot.number_of_samples']
79+
>>> ct.reset_defaults()
80+
>>> ct.defaults['freqplot.number_of_samples']
8381
1000
8482
8583
"""
@@ -97,17 +95,15 @@ def reset_defaults():
9795
9896
Examples
9997
--------
100-
>>> from control import defaults, reset_defaults, set_defaults
101-
102-
>>> defaults['freqplot.number_of_samples']
98+
>>> ct.defaults['freqplot.number_of_samples']
10399
1000
104-
>>> set_defaults('freqplot', number_of_samples=100)
105-
>>> defaults['freqplot.number_of_samples']
100+
>>> ct.set_defaults('freqplot', number_of_samples=100)
101+
>>> ct.defaults['freqplot.number_of_samples']
106102
100
107103
108104
>>> # do some customized freqplotting
109-
>>> reset_defaults()
110-
>>> defaults['freqplot.number_of_samples']
105+
>>> ct.reset_defaults()
106+
>>> ct.defaults['freqplot.number_of_samples']
111107
1000
112108
113109
"""
@@ -213,11 +209,9 @@ def use_matlab_defaults():
213209
214210
Examples
215211
--------
216-
>>> from control import use_matlab_defaults, reset_defaults
217-
218-
>>> use_matlab_defaults()
212+
>>> ct.use_matlab_defaults()
219213
>>> # do some matlab style plotting
220-
>>> reset_defaults()
214+
>>> ct.reset_defaults()
221215
222216
"""
223217
set_defaults('freqplot', dB=True, deg=True, Hz=False, grid=True)
@@ -235,11 +229,9 @@ def use_fbs_defaults():
235229
236230
Examples
237231
--------
238-
>>> from control import use_fbs_defaults, reset_defaults
239-
240-
>>> use_fbs_defaults()
232+
>>> ct.use_fbs_defaults()
241233
>>> # do some FBS style plotting
242-
>>> reset_defaults()
234+
>>> ct.reset_defaults()
243235
244236
"""
245237
set_defaults('freqplot', dB=False, deg=True, Hz=False, grid=False)
@@ -271,11 +263,9 @@ class and functions. If flat is `False`, then matrices are
271263
272264
Examples
273265
--------
274-
>>> from control import use_numpy_matrix, reset_defaults
275-
276-
>>> use_numpy_matrix(True, False)
266+
>>> ct.use_numpy_matrix(True, False)
277267
>>> # do some legacy calculations using np.matrix
278-
>>> reset_defaults()
268+
>>> ct.reset_defaults()
279269
280270
"""
281271
if flag and warn:
@@ -294,12 +284,10 @@ def use_legacy_defaults(version):
294284
295285
Examples
296286
--------
297-
>>> from control import use_legacy_defaults, reset_defaults
298-
299-
>>> use_legacy_defaults("0.9.0")
287+
>>> ct.use_legacy_defaults("0.9.0")
300288
(0, 9, 0)
301289
>>> # do some legacy style plotting
302-
>>> reset_defaults()
290+
>>> ct.reset_defaults()
303291
304292
"""
305293
import re

0 commit comments

Comments
 (0)