Skip to content

Commit f712096

Browse files
committed
ss, rss, drss return LinearIOSystem
1 parent e10855e commit f712096

8 files changed

Lines changed: 112 additions & 103 deletions

File tree

control/iosys.py

Lines changed: 97 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from warnings import warn
3333

3434
from .statesp import StateSpace, tf2ss, _convert_to_statespace
35+
from .statesp import _ss, _rss_generate
3536
from .xferfcn import TransferFunction
3637
from .timeresp import _check_convert_array, _process_time_response, \
3738
TimeResponseData
@@ -40,8 +41,8 @@
4041

4142
__all__ = ['InputOutputSystem', 'LinearIOSystem', 'NonlinearIOSystem',
4243
'InterconnectedSystem', 'LinearICSystem', 'input_output_response',
43-
'find_eqpt', 'linearize', 'ss2io', 'tf2io', 'interconnect',
44-
'summing_junction']
44+
'find_eqpt', 'linearize', 'ss', 'rss', 'drss', 'ss2io', 'tf2io',
45+
'interconnect', 'summing_junction']
4546

4647
# Define module default parameter values
4748
_iosys_defaults = {
@@ -181,7 +182,8 @@ def __init__(self, inputs=None, outputs=None, states=None, params={},
181182
nstates = 0
182183

183184
def __repr__(self):
184-
return self.name if self.name is not None else str(type(self))
185+
return str(type(self)) + ": " + self.name if self.name is not None \
186+
else str(type(self))
185187

186188
def __str__(self):
187189
"""String representation of an input/output system"""
@@ -853,6 +855,10 @@ def _out(self, t, x, u):
853855
+ self.D @ np.reshape(u, (-1, 1))
854856
return np.array(y).reshape((-1,))
855857

858+
def __str__(self):
859+
return InputOutputSystem.__str__(self) + "\n\n" \
860+
+ StateSpace.__str__(self)
861+
856862

857863
class NonlinearIOSystem(InputOutputSystem):
858864
"""Nonlinear I/O system.
@@ -2261,6 +2267,94 @@ def _find_size(sysval, vecval):
22612267
raise ValueError("Can't determine size of system component.")
22622268

22632269

2270+
# Define a state space object that is an I/O system
2271+
def ss(*args, **kwargs):
2272+
return LinearIOSystem(_ss(*args, **kwargs))
2273+
ss.__doc__ = _ss.__doc__
2274+
2275+
2276+
def rss(states=1, outputs=1, inputs=1, strictly_proper=False):
2277+
"""
2278+
Create a stable *continuous* random state space object.
2279+
2280+
Parameters
2281+
----------
2282+
states : int
2283+
Number of state variables
2284+
outputs : int
2285+
Number of system outputs
2286+
inputs : int
2287+
Number of system inputs
2288+
strictly_proper : bool, optional
2289+
If set to 'True', returns a proper system (no direct term).
2290+
2291+
Returns
2292+
-------
2293+
sys : StateSpace
2294+
The randomly created linear system
2295+
2296+
Raises
2297+
------
2298+
ValueError
2299+
if any input is not a positive integer
2300+
2301+
See Also
2302+
--------
2303+
drss
2304+
2305+
Notes
2306+
-----
2307+
If the number of states, inputs, or outputs is not specified, then the
2308+
missing numbers are assumed to be 1. The poles of the returned system
2309+
will always have a negative real part.
2310+
2311+
"""
2312+
2313+
return LinearIOSystem(_rss_generate(
2314+
states, inputs, outputs, 'c', strictly_proper=strictly_proper))
2315+
2316+
2317+
def drss(states=1, outputs=1, inputs=1, strictly_proper=False):
2318+
"""
2319+
Create a stable *discrete* random state space object.
2320+
2321+
Parameters
2322+
----------
2323+
states : int
2324+
Number of state variables
2325+
inputs : integer
2326+
Number of system inputs
2327+
outputs : int
2328+
Number of system outputs
2329+
strictly_proper: bool, optional
2330+
If set to 'True', returns a proper system (no direct term).
2331+
2332+
Returns
2333+
-------
2334+
sys : StateSpace
2335+
The randomly created linear system
2336+
2337+
Raises
2338+
------
2339+
ValueError
2340+
if any input is not a positive integer
2341+
2342+
See Also
2343+
--------
2344+
rss
2345+
2346+
Notes
2347+
-----
2348+
If the number of states, inputs, or outputs is not specified, then the
2349+
missing numbers are assumed to be 1. The poles of the returned system
2350+
will always have a magnitude less than 1.
2351+
2352+
"""
2353+
2354+
return LinearIOSystem(_rss_generate(
2355+
states, inputs, outputs, 'd', strictly_proper=strictly_proper))
2356+
2357+
22642358
# Convert a state space system into an input/output system (wrapper)
22652359
def ss2io(*args, **kwargs):
22662360
return LinearIOSystem(*args, **kwargs)

control/matlab/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262

6363
# Control system library
6464
from ..statesp import *
65+
from ..iosys import ss, rss, drss # moved from .statesp
6566
from ..xferfcn import *
6667
from ..lti import *
6768
from ..frdata import *

control/matlab/wrappers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44

55
import numpy as np
6-
from ..statesp import ss
6+
from ..iosys import ss
77
from ..xferfcn import tf
88
from ..ctrlutil import issys
99
from ..exception import ControlArgument

control/sisotool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from .timeresp import step_response
66
from .lti import issiso, isdtime
77
from .xferfcn import tf
8-
from .statesp import ss
8+
from .iosys import ss
99
from .bdalg import append, connect
1010
from .iosys import tf2io, ss2io, summing_junction, interconnect
1111
from control.statesp import _convert_to_statespace, StateSpace

control/statesp.py

Lines changed: 2 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@
6262
from . import config
6363
from copy import deepcopy
6464

65-
__all__ = ['StateSpace', 'ss', 'rss', 'drss', 'tf2ss', 'ssdata']
66-
65+
__all__ = ['StateSpace', 'tf2ss', 'ssdata']
6766

6867
# Define module default parameter values
6968
_statesp_defaults = {
@@ -1768,7 +1767,7 @@ def _mimo2simo(sys, input, warn_conversion=False):
17681767
return sys
17691768

17701769

1771-
def ss(*args, **kwargs):
1770+
def _ss(*args, **kwargs):
17721771
"""ss(A, B, C, D[, dt])
17731772
17741773
Create a state space system.
@@ -1932,89 +1931,6 @@ def tf2ss(*args):
19321931
raise ValueError("Needs 1 or 2 arguments; received %i." % len(args))
19331932

19341933

1935-
def rss(states=1, outputs=1, inputs=1, strictly_proper=False):
1936-
"""
1937-
Create a stable *continuous* random state space object.
1938-
1939-
Parameters
1940-
----------
1941-
states : int
1942-
Number of state variables
1943-
outputs : int
1944-
Number of system outputs
1945-
inputs : int
1946-
Number of system inputs
1947-
strictly_proper : bool, optional
1948-
If set to 'True', returns a proper system (no direct term).
1949-
1950-
Returns
1951-
-------
1952-
sys : StateSpace
1953-
The randomly created linear system
1954-
1955-
Raises
1956-
------
1957-
ValueError
1958-
if any input is not a positive integer
1959-
1960-
See Also
1961-
--------
1962-
drss
1963-
1964-
Notes
1965-
-----
1966-
If the number of states, inputs, or outputs is not specified, then the
1967-
missing numbers are assumed to be 1. The poles of the returned system
1968-
will always have a negative real part.
1969-
1970-
"""
1971-
1972-
return _rss_generate(states, inputs, outputs, 'c',
1973-
strictly_proper=strictly_proper)
1974-
1975-
1976-
def drss(states=1, outputs=1, inputs=1, strictly_proper=False):
1977-
"""
1978-
Create a stable *discrete* random state space object.
1979-
1980-
Parameters
1981-
----------
1982-
states : int
1983-
Number of state variables
1984-
inputs : integer
1985-
Number of system inputs
1986-
outputs : int
1987-
Number of system outputs
1988-
strictly_proper: bool, optional
1989-
If set to 'True', returns a proper system (no direct term).
1990-
1991-
1992-
Returns
1993-
-------
1994-
sys : StateSpace
1995-
The randomly created linear system
1996-
1997-
Raises
1998-
------
1999-
ValueError
2000-
if any input is not a positive integer
2001-
2002-
See Also
2003-
--------
2004-
rss
2005-
2006-
Notes
2007-
-----
2008-
If the number of states, inputs, or outputs is not specified, then the
2009-
missing numbers are assumed to be 1. The poles of the returned system
2010-
will always have a magnitude less than 1.
2011-
2012-
"""
2013-
2014-
return _rss_generate(states, inputs, outputs, 'd',
2015-
strictly_proper=strictly_proper)
2016-
2017-
20181934
def ssdata(sys):
20191935
"""
20201936
Return state space data objects for a system

control/tests/statesp_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
from control.config import defaults
1919
from control.dtime import sample_system
2020
from control.lti import evalfr
21-
from control.statesp import (StateSpace, _convert_to_statespace, drss,
22-
rss, ss, tf2ss, _statesp_defaults, _rss_generate)
21+
from control.statesp import StateSpace, _convert_to_statespace, tf2ss, \
22+
_statesp_defaults, _rss_generate
23+
from control.iosys import ss, rss, drss
2324
from control.tests.conftest import ismatarrayout, slycotonly
2425
from control.xferfcn import TransferFunction, ss2tf
2526

control/tests/type_conversion_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def sys_dict():
5959
rtype_list = ['ss', 'tf', 'frd', 'lio', 'ios', 'arr', 'flt']
6060
conversion_table = [
6161
# op left ss tf frd lio ios arr flt
62-
('add', 'ss', ['ss', 'ss', 'xrd', 'ss', 'xos', 'ss', 'ss' ]),
62+
('add', 'ss', ['ss', 'ss', 'xrd', 'ss', 'ios', 'ss', 'ss' ]),
6363
('add', 'tf', ['tf', 'tf', 'xrd', 'tf', 'xos', 'tf', 'tf' ]),
6464
('add', 'frd', ['xrd', 'xrd', 'frd', 'xrd', 'E', 'xrd', 'xrd']),
6565
('add', 'lio', ['lio', 'lio', 'xrd', 'lio', 'ios', 'lio', 'lio']),
@@ -68,7 +68,7 @@ def sys_dict():
6868
('add', 'flt', ['ss', 'tf', 'xrd', 'lio', 'ios', 'arr', 'flt']),
6969

7070
# op left ss tf frd lio ios arr flt
71-
('sub', 'ss', ['ss', 'ss', 'xrd', 'ss', 'xos', 'ss', 'ss' ]),
71+
('sub', 'ss', ['ss', 'ss', 'xrd', 'ss', 'ios', 'ss', 'ss' ]),
7272
('sub', 'tf', ['tf', 'tf', 'xrd', 'tf', 'xos', 'tf', 'tf' ]),
7373
('sub', 'frd', ['xrd', 'xrd', 'frd', 'xrd', 'E', 'xrd', 'xrd']),
7474
('sub', 'lio', ['lio', 'lio', 'xrd', 'lio', 'ios', 'lio', 'lio']),
@@ -77,7 +77,7 @@ def sys_dict():
7777
('sub', 'flt', ['ss', 'tf', 'xrd', 'lio', 'ios', 'arr', 'flt']),
7878

7979
# op left ss tf frd lio ios arr flt
80-
('mul', 'ss', ['ss', 'ss', 'xrd', 'ss', 'xos', 'ss', 'ss' ]),
80+
('mul', 'ss', ['ss', 'ss', 'xrd', 'ss', 'ios', 'ss', 'ss' ]),
8181
('mul', 'tf', ['tf', 'tf', 'xrd', 'tf', 'xos', 'tf', 'tf' ]),
8282
('mul', 'frd', ['xrd', 'xrd', 'frd', 'xrd', 'E', 'xrd', 'frd']),
8383
('mul', 'lio', ['lio', 'lio', 'xrd', 'lio', 'ios', 'lio', 'lio']),

control/tests/xferfcn_test.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@
88
import operator
99

1010
import control as ct
11-
from control.statesp import StateSpace, _convert_to_statespace, rss
12-
from control.xferfcn import TransferFunction, _convert_to_transfer_function, \
13-
ss2tf
14-
from control.lti import evalfr
11+
from control import StateSpace, TransferFunction, rss, ss2tf, evalfr
12+
from control import isctime, isdtime, sample_system, defaults
13+
from control.statesp import _convert_to_statespace
14+
from control.xferfcn import _convert_to_transfer_function
1515
from control.tests.conftest import slycotonly, nopython2, matrixfilter
16-
from control.lti import isctime, isdtime
17-
from control.dtime import sample_system
18-
from control.config import defaults
1916

2017

2118
class TestXferFcn:

0 commit comments

Comments
 (0)