Skip to content
Prev Previous commit
Next Next commit
remove imports and use ct.fcn instead
  • Loading branch information
murrayrm committed Mar 25, 2023
commit c4c275fd639b995c96b931a52e41dfb14af86862
17 changes: 17 additions & 0 deletions control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@
"""
The Python Control Systems Library :mod:`control` provides common functions
for analyzing and designing feedback control systems.

Documentation is available in two forms: docstrings provided with the code,
and the python-control users guide, available from `the python-control
homepage <https://www.python-control.org>`_.

The docstring examples assume that the following import commands::

>>> import numpy as np
>>> import control as ct

Available subpackages
---------------------
flatsys
Differentially flat systems
optimal
Optimization-based control

"""

# Import functions from within the control system library
Expand Down
62 changes: 25 additions & 37 deletions control/bdalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,15 @@ def series(sys1, *sysn):

Examples
--------
>>> from control import rss, series

>>> G1 = rss(3)
>>> G2 = rss(4)
>>> G = series(G1, G2) # Same as sys3 = sys2 * sys1
>>> G1 = ct.rss(3)
>>> G2 = ct.rss(4)
>>> G = ct.series(G1, G2) # Same as sys3 = sys2 * sys1
>>> G.ninputs, G.noutputs, G.nstates
(1, 1, 7)
Comment thread
murrayrm marked this conversation as resolved.

>>> G1 = rss(2, inputs=2, outputs=3)
>>> G2 = rss(3, inputs=3, outputs=1)
>>> G = series(G1, G2) # Same as sys3 = sys2 * sys1
>>> G1 = ct.rss(2, inputs=2, outputs=3)
>>> G2 = ct.rss(3, inputs=3, outputs=1)
>>> G = ct.series(G1, G2) # Same as sys3 = sys2 * sys1
>>> G.ninputs, G.noutputs, G.nstates
(2, 1, 5)

Expand Down Expand Up @@ -156,17 +154,15 @@ def parallel(sys1, *sysn):

Examples
--------
>>> from control import parallel, rss

>>> G1 = rss(3)
>>> G2 = rss(4)
>>> G = parallel(G1, G2) # Same as sys3 = sys1 + sys2
>>> G1 = ct.rss(3)
>>> G2 = ct.rss(4)
>>> G = ct.parallel(G1, G2) # Same as sys3 = sys1 + sys2
>>> G.ninputs, G.noutputs, G.nstates
(1, 1, 7)

>>> G1 = rss(3, inputs=3, outputs=4)
>>> G2 = rss(4, inputs=3, outputs=4)
>>> G = parallel(G1, G2) # Add another system
>>> G1 = ct.rss(3, inputs=3, outputs=4)
>>> G2 = ct.rss(4, inputs=3, outputs=4)
>>> G = ct.parallel(G1, G2) # Add another system
>>> G.ninputs, G.noutputs, G.nstates
(3, 4, 7)

Expand Down Expand Up @@ -194,13 +190,11 @@ def negate(sys):

Examples
--------
>>> from control import negate, tf

>>> G = tf([2],[1, 1])
>>> G = ct.tf([2],[1, 1])
>>> G.dcgain() > 0
True

>>> Gn = negate(G) # Same as sys2 = -sys1.
>>> Gn = ct.negate(G) # Same as sys2 = -sys1.
>>> Gn.dcgain() < 0
True

Expand Down Expand Up @@ -252,11 +246,9 @@ def feedback(sys1, sys2=1, sign=-1):

Examples
--------
>>> from control import feedback, rss

>>> G = rss(3, inputs=2, outputs=5)
>>> C = rss(4, inputs=5, outputs=2)
>>> T = feedback(G, C, sign=1)
>>> G = ct.rss(3, inputs=2, outputs=5)
>>> C = ct.rss(4, inputs=5, outputs=2)
>>> T = ct.feedback(G, C, sign=1)
>>> T.ninputs, T.noutputs, T.nstates
(2, 5, 7)

Expand Down Expand Up @@ -316,17 +308,15 @@ def append(*sys):

Examples
--------
>>> from control import append, rss
>>> G1 = rss(3)

>>> G2 = rss(4)
>>> G = append(G1, G2)
>>> G1 = ct.rss(3)
>>> G2 = ct.rss(4)
>>> G = ct.append(G1, G2)
>>> G.ninputs, G.noutputs, G.nstates
(2, 2, 7)

>>> G1 = rss(3, inputs=2, outputs=4)
>>> G2 = rss(4, inputs=1, outputs=4)
>>> G = append(G1, G2)
>>> G1 = ct.rss(3, inputs=2, outputs=4)
>>> G2 = ct.rss(4, inputs=1, outputs=4)
>>> G = ct.append(G1, G2)
>>> G.ninputs, G.noutputs, G.nstates
(3, 8, 7)

Expand Down Expand Up @@ -371,11 +361,9 @@ def connect(sys, Q, inputv, outputv):

Examples
--------
>>> from control import append, connect, rss

>>> G = rss(7, inputs=2, outputs=2)
>>> G = ct.rss(7, inputs=2, outputs=2)
>>> K = [[1, 2], [2, -1]] # negative feedback interconnection
>>> T = connect(G, K, [2], [1, 2])
>>> T = ct.connect(G, K, [2], [1, 2])
>>> T.ninputs, T.noutputs, T.nstates
(1, 2, 7)

Expand Down
57 changes: 20 additions & 37 deletions control/canonical.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,18 @@ def canonical_form(xsys, form='reachable'):

Examples
--------
>>> from control import canonical_form, tf, tf2ss

>>> G = tf([1],[1, 3, 2])
>>> Gs = tf2ss(G)

>>> Gc, T = canonical_form(Gs) # default reachable
>>> G = ct.tf([1],[1, 3, 2])
>>> Gs = ct.tf2ss(G)
>>> Gc, T = ct.canonical_form(Gs) # default reachable
>>> Gc.B # doctest: +SKIP
matrix([[1.],
[0.]])

>>> Gc, T = canonical_form(Gs, 'observable')
>>> Gc, T = ct.canonical_form(Gs, 'observable')
>>> Gc.C # doctest: +SKIP
matrix([[1., 0.]])

>>> Gc, T = canonical_form(Gs, 'modal')
>>> Gc, T = ct.canonical_form(Gs, 'modal')
>>> Gc.A # doctest: +SKIP
matrix([[-2., 0.],
[ 0., -1.]])
Expand Down Expand Up @@ -90,12 +87,9 @@ def reachable_form(xsys):

Examples
--------
>>> from control import reachable_form, tf, tf2ss

>>> G = tf([1],[1, 3, 2])
>>> Gs = tf2ss(G)

>>> Gc, T = reachable_form(Gs) # default reachable
>>> G = ct.tf([1],[1, 3, 2])
>>> Gs = ct.tf2ss(G)
>>> Gc, T = ct.reachable_form(Gs) # default reachable
>>> Gc.B # doctest: +SKIP
matrix([[1.],
[0.]])
Expand Down Expand Up @@ -157,12 +151,9 @@ def observable_form(xsys):

Examples
--------
>>> from control import observable_form, tf, tf2ss

>>> G = tf([1],[1, 3, 2])
>>> Gs = tf2ss(G)

>>> Gc, T = observable_form(Gs)
>>> G = ct.tf([1],[1, 3, 2])
>>> Gs = ct.tf2ss(G)
>>> Gc, T = ct.observable_form(Gs)
>>> Gc.C # doctest: +SKIP
matrix([[1., 0.]])

Expand Down Expand Up @@ -227,17 +218,14 @@ def similarity_transform(xsys, T, timescale=1, inverse=False):

Examples
--------
>>> import numpy as np
>>> from control import similarity_transform, tf, tf2ss

>>> G = tf([1],[1, 3, 2])
>>> Gs = tf2ss(G)
>>> G = ct.tf([1],[1, 3, 2])
>>> Gs = ct.tf2ss(G)
>>> Gs.A # doctest: +SKIP
matrix([[-3., -2.],
[ 1., 0.]])

>>> T = np.array([[0,1],[1,0]])
>>> Gt = similarity_transform(Gs, T)
>>> Gt = ct.similarity_transform(Gs, T)
>>> Gt.A # doctest: +SKIP
matrix([[ 0., 1.],
[-2., -3.]])
Expand Down Expand Up @@ -438,11 +426,9 @@ def bdschur(a, condmax=None, sort=None):

Examples
--------
>>> from control import bdschur, tf, tf2ss

>>> G = tf([1],[1, 3, 2])
>>> Gs = tf2ss(G)
>>> amodal, tmodal, blksizes = bdschur(Gs.A)
>>> G = ct.tf([1],[1, 3, 2])
>>> Gs = ct.tf2ss(G)
>>> amodal, tmodal, blksizes = ct.bdschur(Gs.A)
>>> amodal #doctest: +SKIP
array([[-2., 0.],
[ 0., -1.]])
Expand Down Expand Up @@ -516,12 +502,9 @@ def modal_form(xsys, condmax=None, sort=False):

Examples
--------
>>> from control import modal_form, tf, tf2ss

>>> G = tf([1],[1, 3, 2])
>>> Gs = tf2ss((G))

>>> Gc, T = modal_form(Gs) # default reachable
>>> G = ct.tf([1],[1, 3, 2])
>>> Gs = ct.tf2ss((G))
>>> Gc, T = ct.modal_form(Gs) # default reachable
>>> Gc.A # doctest: +SKIP
matrix([[-2., 0.],
[ 0., -1.]])
Expand Down
48 changes: 18 additions & 30 deletions control/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,15 @@ def set_defaults(module, **keywords):

Examples
--------
>>> from control import defaults, reset_defaults, set_defaults

>>> defaults['freqplot.number_of_samples']
>>> ct.defaults['freqplot.number_of_samples']
1000
>>> set_defaults('freqplot', number_of_samples=100)
>>> defaults['freqplot.number_of_samples']
>>> ct.set_defaults('freqplot', number_of_samples=100)
>>> ct.defaults['freqplot.number_of_samples']
100

>>> # do some customized freqplotting
>>> reset_defaults()
>>> defaults['freqplot.number_of_samples']
>>> ct.reset_defaults()
>>> ct.defaults['freqplot.number_of_samples']
1000

"""
Expand All @@ -97,17 +95,15 @@ def reset_defaults():

Examples
--------
>>> from control import defaults, reset_defaults, set_defaults

>>> defaults['freqplot.number_of_samples']
>>> ct.defaults['freqplot.number_of_samples']
1000
>>> set_defaults('freqplot', number_of_samples=100)
>>> defaults['freqplot.number_of_samples']
>>> ct.set_defaults('freqplot', number_of_samples=100)
>>> ct.defaults['freqplot.number_of_samples']
100

>>> # do some customized freqplotting
>>> reset_defaults()
>>> defaults['freqplot.number_of_samples']
>>> ct.reset_defaults()
>>> ct.defaults['freqplot.number_of_samples']
1000

"""
Expand Down Expand Up @@ -213,11 +209,9 @@ def use_matlab_defaults():

Examples
--------
>>> from control import use_matlab_defaults, reset_defaults

>>> use_matlab_defaults()
>>> ct.use_matlab_defaults()
>>> # do some matlab style plotting
>>> reset_defaults()
>>> ct.reset_defaults()

"""
set_defaults('freqplot', dB=True, deg=True, Hz=False, grid=True)
Expand All @@ -235,11 +229,9 @@ def use_fbs_defaults():

Examples
--------
>>> from control import use_fbs_defaults, reset_defaults

>>> use_fbs_defaults()
>>> ct.use_fbs_defaults()
>>> # do some FBS style plotting
>>> reset_defaults()
>>> ct.reset_defaults()

"""
set_defaults('freqplot', dB=False, deg=True, Hz=False, grid=False)
Expand Down Expand Up @@ -271,11 +263,9 @@ class and functions. If flat is `False`, then matrices are

Examples
--------
>>> from control import use_numpy_matrix, reset_defaults

>>> use_numpy_matrix(True, False)
>>> ct.use_numpy_matrix(True, False)
>>> # do some legacy calculations using np.matrix
>>> reset_defaults()
>>> ct.reset_defaults()

"""
if flag and warn:
Expand All @@ -294,12 +284,10 @@ def use_legacy_defaults(version):

Examples
--------
>>> from control import use_legacy_defaults, reset_defaults

>>> use_legacy_defaults("0.9.0")
>>> ct.use_legacy_defaults("0.9.0")
(0, 9, 0)
>>> # do some legacy style plotting
>>> reset_defaults()
>>> ct.reset_defaults()

"""
import re
Expand Down
Loading