- Notifications
You must be signed in to change notification settings - Fork441
I/O system class restructuring#916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
18 commits Select commitHold shift + click to select a range
b881b22
initial refactoring of classes and modules
murrayrm4afda82
updated unit tests
murrayrm31f6574
updated documentation, examples, unit tests
murrayrm7273e11
iosys.py cleanup plus related subclass, docstring mods
murrayrm9d426e9
removed unused code; added unit tests for coverage
murrayrm0758426
reorganize and clean up statesp.py
murrayrm7dc92df
add nlsys() function for creating nonlinear I/O systems
murrayrme9e3a8e
allow bdalg fucntions (series, parallel, feedback) on general I/O sys…
murrayrm0ef2941
update time response functions to allow nonlinear systems
murrayrm4692b1e
remove unneeded code; clean up TODOs
murrayrm55fb775
add missing links for Jupyter notebooks in doc/
murrayrm9023de9
add flatsys() factory function
murrayrmde38612
fix bug in the way inputs were stored for MIMO step_response
murrayrmb3693dc
updates per @sawyerbfuller review comments
murrayrma0c7884
clean up unit test warnings + ignore deprecation warning in matlab.co…
murrayrmfc19cd6
add back ss2io and tf2io, with deprecation warnings
murrayrm0b3ae85
set names of ct.s and ct.z to 's' and 'z'
murrayrm39404c4
fix bug in the way LinearICSystem.__call__ was implemented (with unit…
murrayrmFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
15 changes: 9 additions & 6 deletionscontrol/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
157 changes: 85 additions & 72 deletionscontrol/bdalg.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -53,10 +53,13 @@ | ||
""" | ||
from functools import reduce | ||
import numpy as np | ||
from warnings import warn | ||
from . import xferfcn as tf | ||
from . import statesp as ss | ||
from . import frdata as frd | ||
from .iosys import InputOutputSystem | ||
__all__ = ['series', 'parallel', 'negate', 'feedback', 'append', 'connect'] | ||
@@ -68,12 +71,13 @@ def series(sys1, *sysn): | ||
Parameters | ||
---------- | ||
sys1, sys2, ..., sysn: scalar,array,or:class:`InputOutputSystem` | ||
I/O systems to combine. | ||
Returns | ||
------- | ||
out : scalar, array, or :class:`InputOutputSystem` | ||
Series interconnection of the systems. | ||
Raises | ||
------ | ||
@@ -83,14 +87,15 @@ def series(sys1, *sysn): | ||
See Also | ||
-------- | ||
append, feedback, interconnect, negate, parallel | ||
Notes | ||
----- | ||
This function is a wrapper for the __mul__ function in the appropriate | ||
:class:`NonlinearIOSystem`, :class:`StateSpace`, | ||
:class:`TransferFunction`, or other I/O system class. The output type | ||
is the type of `sys1` unless a more general type is required based on | ||
type type of `sys2`. | ||
If both systems have a defined timebase (dt = 0 for continuous time, | ||
dt > 0 for discrete time), then the timebase for both systems must | ||
@@ -112,8 +117,7 @@ def series(sys1, *sysn): | ||
(2, 1, 5) | ||
""" | ||
return reduce(lambda x, y: y * x, sysn, sys1) | ||
def parallel(sys1, *sysn): | ||
@@ -123,12 +127,13 @@ def parallel(sys1, *sysn): | ||
Parameters | ||
---------- | ||
sys1, sys2, ..., sysn: scalar,array,or:class:`InputOutputSystem` | ||
I/O systems to combine. | ||
Returns | ||
------- | ||
out : scalar, array, or :class:`InputOutputSystem` | ||
Parallel interconnection of the systems. | ||
Raises | ||
------ | ||
@@ -137,8 +142,7 @@ def parallel(sys1, *sysn): | ||
See Also | ||
-------- | ||
append, feedback, interconnect, negate, series | ||
Notes | ||
----- | ||
@@ -167,8 +171,7 @@ def parallel(sys1, *sysn): | ||
(3, 4, 7) | ||
""" | ||
return reduce(lambda x, y: x + y, sysn, sys1) | ||
def negate(sys): | ||
@@ -177,17 +180,23 @@ def negate(sys): | ||
Parameters | ||
---------- | ||
sys: scalar, array, or :class:`InputOutputSystem` | ||
I/O systems to negate. | ||
Returns | ||
------- | ||
out : scalar, array, or :class:`InputOutputSystem` | ||
Negated system. | ||
Notes | ||
----- | ||
This function is a wrapper for the __neg__ function in the StateSpace and | ||
TransferFunction classes. The output type is the same as the input type. | ||
See Also | ||
-------- | ||
append, feedback, interconnect, parallel, series | ||
Examples | ||
-------- | ||
>>> G = ct.tf([2], [1, 1]) | ||
@@ -202,24 +211,23 @@ def negate(sys): | ||
return -sys | ||
#! TODO: expand to allow sys2 default to work in MIMO case? | ||
#! TODO: allow renaming of signals (for all bdalg operations) | ||
def feedback(sys1, sys2=1, sign=-1): | ||
"""Feedback interconnection between two I/O systems. | ||
Parameters | ||
---------- | ||
sys1, sys2: scalar, array, or :class:`InputOutputSystem` | ||
I/O systems to combine. | ||
sign: scalar | ||
The sign of feedback. `sign` = -1 indicates negative feedback, and | ||
`sign` = 1 indicates positive feedback. `sign` is an optional | ||
argument; it assumes a value of -1 if not specified. | ||
Returns | ||
------- | ||
out : scalar, array, or :class:`InputOutputSystem` | ||
Feedback interconnection of the systems. | ||
Raises | ||
------ | ||
@@ -232,17 +240,14 @@ def feedback(sys1, sys2=1, sign=-1): | ||
See Also | ||
-------- | ||
append, interconnect, negate, parallel, series | ||
Notes | ||
----- | ||
This function is a wrapper for the `feedback` function in the I/O | ||
system classes. It calls sys1.feedback if `sys1` is an I/O system | ||
object. If `sys1` is a scalar, then it is converted to `sys2`'s type, | ||
and the corresponding feedback function is used. | ||
Examples | ||
-------- | ||
@@ -254,57 +259,55 @@ def feedback(sys1, sys2=1, sign=-1): | ||
""" | ||
# Allow anything with a feedback function to call that function | ||
# TODO: rewrite to allow __rfeedback__ | ||
try: | ||
return sys1.feedback(sys2, sign) | ||
except(AttributeError, TypeError): | ||
pass | ||
# Check for correct input types | ||
if not isinstance(sys1, (int, float, complex, np.number, np.ndarray, | ||
InputOutputSystem)): | ||
raise TypeError("sys1 must be an I/O system, scalar, or array") | ||
elif not isinstance(sys2, (int, float, complex, np.number, np.ndarray, | ||
InputOutputSystem)): | ||
raise TypeError("sys2 must be an I/O system, scalar, or array") | ||
# If sys1 is a scalar or ndarray, use the type of sys2 to figure | ||
# out how to convert sys1, using transfer functions whenever possible. | ||
if isinstance(sys1, (int, float, complex, np.number, np.ndarray)): | ||
if isinstance(sys2, (int, float, complex, np.number, np.ndarray, | ||
tf.TransferFunction)): | ||
sys1 = tf._convert_to_transfer_function(sys1) | ||
elif isinstance(sys2, frd.FRD): | ||
sys1 = frd._convert_to_FRD(sys1, sys2.omega) | ||
else: | ||
sys1 = ss._convert_to_statespace(sys1) | ||
return sys1.feedback(sys2, sign) | ||
def append(*sys): | ||
"""append(sys1, sys2, [..., sysn]) | ||
GroupLTI state spacemodels by appending their inputs and outputs. | ||
Forms an augmented system model, and appends the inputs and | ||
outputs together. | ||
Parameters | ||
---------- | ||
sys1, sys2, ..., sysn: scalar, array, or :class:`StateSpace` | ||
I/O systems to combine. | ||
Returns | ||
------- | ||
out: :class:`StateSpace` | ||
Combined system, with input/output vectors consisting of all | ||
input/output vectors appended. | ||
See Also | ||
-------- | ||
interconnect, feedback, negate, parallel, series | ||
Examples | ||
-------- | ||
@@ -329,6 +332,10 @@ def append(*sys): | ||
def connect(sys, Q, inputv, outputv): | ||
"""Index-based interconnection of an LTI system. | ||
.. deprecated:: 0.10.0 | ||
`connect` will be removed in a future version of python-control in | ||
favor of `interconnect`, which works with named signals. | ||
The system `sys` is a system typically constructed with `append`, with | ||
multiple inputs and outputs. The inputs and outputs are connected | ||
according to the interconnection matrix `Q`, and then the final inputs and | ||
@@ -340,8 +347,8 @@ def connect(sys, Q, inputv, outputv): | ||
Parameters | ||
---------- | ||
sys ::class:`InputOutputSystem` | ||
System to be connected. | ||
Q : 2D array | ||
Interconnection matrix. First column gives the input to be connected. | ||
The second column gives the index of an output that is to be fed into | ||
@@ -356,8 +363,12 @@ def connect(sys, Q, inputv, outputv): | ||
Returns | ||
------- | ||
out : :class:`InputOutputSystem` | ||
Connected and trimmed I/O system. | ||
See Also | ||
-------- | ||
append, feedback, interconnect, negate, parallel, series | ||
Examples | ||
-------- | ||
@@ -369,12 +380,14 @@ def connect(sys, Q, inputv, outputv): | ||
Notes | ||
----- | ||
The :func:`~control.interconnect` function in the :ref:`input/output | ||
systems <iosys-module>` module allows the use of named signals and | ||
provides an alternative method for interconnecting multiple systems. | ||
""" | ||
# TODO: maintain `connect` for use in MATLAB submodule (?) | ||
murrayrm marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
warn("`connect` is deprecated; use `interconnect`", DeprecationWarning) | ||
inputv, outputv, Q = \ | ||
np.atleast_1d(inputv), np.atleast_1d(outputv), np.atleast_1d(Q) | ||
# check indices | ||
9 changes: 3 additions & 6 deletionscontrol/config.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.