Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,15 @@
except ImportError:
__version__ = "dev"

# patch the LTI class with function aliases for convenience functions
# this needs to be done after the fact since the modules that contain the functions
# all heavily depend on the LTI class
LTI.to_ss = ss
LTI.to_tf = tf
LTI.feedback = feedback
LTI.bode_plot = bode_plot
LTI.nyquist_plot = nyquist_plot
LTI.nichols_plot = nichols_plot

# Initialize default parameter values
reset_defaults()
32 changes: 30 additions & 2 deletions control/lti.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from warnings import warn
from . import config
from .iosys import InputOutputSystem
import control
from typing import Callable

__all__ = ['poles', 'zeros', 'damp', 'evalfr', 'frequency_response',
'freqresp', 'dcgain', 'bandwidth', 'LTI']
Expand Down Expand Up @@ -76,9 +78,10 @@ def frequency_response(self, omega=None, squeeze=None):

Parameters
----------
omega : float or 1D array_like
omega : float or 1D array_like, optional
A list, tuple, array, or scalar value of frequencies in
radians/sec at which the system will be evaluated.
radians/sec at which the system will be evaluated. If None (default),
a set of frequencies is computed based on the system dynamics.
squeeze : bool, optional
If squeeze=True, remove single-dimensional entries from the shape
of the output even if the system is not SISO. If squeeze=False,
Expand Down Expand Up @@ -107,6 +110,11 @@ def frequency_response(self, omega=None, squeeze=None):
"""
from .frdata import FrequencyResponseData

if omega is None:
# Use default frequency range
from .freqplot import _default_frequency_range
omega = _default_frequency_range(self)

omega = np.sort(np.array(omega, ndmin=1))
if self.isdtime(strict=True):
# Convert the frequency to discrete time
Expand Down Expand Up @@ -203,6 +211,26 @@ def ispassive(self):
from control.passivity import ispassive
return ispassive(self)

# convenience aliases
# most function are only forward declaraed and patched in the __init__.py to avoid circular imports

# conversions
to_ss: Callable
to_tf: Callable

# system interconnections
feedback: Callable

# freq domain plotting
bode_plot: Callable
nyquist_plot: Callable
nichols_plot: Callable

# time domain simulation
forced_response = control.timeresp.forced_response
impulse_response = control.timeresp.impulse_response
step_response = control.timeresp.step_response
Comment on lines +217 to +240

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add (short) docstrings for these. Since these are initialized as assigned member variables instead of standard function (using def), we will have to use the doc-comment format (lines starting with #: before the variable). See InputOutputSystem.nstates for an example.

I think these can be short, perhaps of the form: "Bode plot; see bode_plot function for more information".



def poles(sys):
"""
Expand Down
4 changes: 4 additions & 0 deletions control/statesp.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
common_timebase, isdtime, issiso
from .lti import LTI, _process_frequency_response
from .nlsys import InterconnectedSystem, NonlinearIOSystem
import control

try:
from slycot import ab13dd
Expand Down Expand Up @@ -1467,6 +1468,9 @@ def output(self, t, x, u=None, params=None):
raise ValueError("len(u) must be equal to number of inputs")
return (self.C @ x).reshape((-1,)) \
+ (self.D @ u).reshape((-1,)) # return as row vector

# convenience aliase, import needs to go over the submodule to avoid circular imports
initial_response = control.timeresp.initial_response


class LinearICSystem(InterconnectedSystem, StateSpace):
Expand Down
4 changes: 4 additions & 0 deletions control/tests/kwargs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ def test_response_plot_kwargs(data_fcn, plot_fcn, mimo):
'append': test_unrecognized_kwargs,
'bode': test_response_plot_kwargs,
'bode_plot': test_response_plot_kwargs,
'LTI.bode_plot': test_response_plot_kwargs,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a comment at the end of this line (and the equivalent lines below) indicating that this is tested via bode_plot since there is not a separate test for the member function (and it really isn't needed, since it is the same object).

'create_estimator_iosystem': stochsys_test.test_estimator_errors,
'create_statefbk_iosystem': statefbk_test.TestStatefbk.test_statefbk_errors,
'describing_function_plot': test_matplotlib_kwargs,
Expand All @@ -253,6 +254,7 @@ def test_response_plot_kwargs(data_fcn, plot_fcn, mimo):
'dlqr': test_unrecognized_kwargs,
'drss': test_unrecognized_kwargs,
'feedback': test_unrecognized_kwargs,
'LTI.feedback': test_unrecognized_kwargs,
'find_eqpt': iosys_test.test_find_operating_point,
'find_operating_point': iosys_test.test_find_operating_point,
'flatsys.flatsys': test_unrecognized_kwargs,
Expand All @@ -267,11 +269,13 @@ def test_response_plot_kwargs(data_fcn, plot_fcn, mimo):
'lqr': test_unrecognized_kwargs,
'negate': test_unrecognized_kwargs,
'nichols_plot': test_matplotlib_kwargs,
'LTI.nichols_plot': test_matplotlib_kwargs,
'nichols': test_matplotlib_kwargs,
'nlsys': test_unrecognized_kwargs,
'nyquist': test_matplotlib_kwargs,
'nyquist_response': test_response_plot_kwargs,
'nyquist_plot': test_matplotlib_kwargs,
'LTI.nyquist_plot': test_matplotlib_kwargs,
'phase_plane_plot': test_matplotlib_kwargs,
'parallel': test_unrecognized_kwargs,
'pole_zero_plot': test_unrecognized_kwargs,
Expand Down