Skip to content

Commit a0c7884

Browse files
committed
clean up unit test warnings + ignore deprecation warning in matlab.connect
1 parent b3693dc commit a0c7884

2 files changed

Lines changed: 61 additions & 6 deletions

File tree

control/matlab/wrappers.py

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
"""
44

55
import numpy as np
6+
from scipy.signal import zpk2tf
7+
import warnings
8+
from warnings import warn
9+
610
from ..statesp import ss
711
from ..xferfcn import tf
812
from ..lti import LTI
913
from ..exception import ControlArgument
10-
from scipy.signal import zpk2tf
11-
from warnings import warn
1214

13-
__all__ = ['bode', 'nyquist', 'ngrid', 'dcgain']
15+
__all__ = ['bode', 'nyquist', 'ngrid', 'dcgain', 'connect']
1416

1517
def bode(*args, **kwargs):
1618
"""bode(syslist[, omega, dB, Hz, deg, ...])
@@ -230,3 +232,56 @@ def dcgain(*args):
230232
else:
231233
raise ValueError("Function ``dcgain`` needs either 1, 2, 3 or 4 "
232234
"arguments.")
235+
236+
237+
from ..bdalg import connect as ct_connect
238+
def connect(*args):
239+
"""Index-based interconnection of an LTI system.
240+
241+
The system `sys` is a system typically constructed with `append`, with
242+
multiple inputs and outputs. The inputs and outputs are connected
243+
according to the interconnection matrix `Q`, and then the final inputs and
244+
outputs are trimmed according to the inputs and outputs listed in `inputv`
245+
and `outputv`.
246+
247+
NOTE: Inputs and outputs are indexed starting at 1 and negative values
248+
correspond to a negative feedback interconnection.
249+
250+
Parameters
251+
----------
252+
sys : :class:`InputOutputSystem`
253+
System to be connected.
254+
Q : 2D array
255+
Interconnection matrix. First column gives the input to be connected.
256+
The second column gives the index of an output that is to be fed into
257+
that input. Each additional column gives the index of an additional
258+
input that may be optionally added to that input. Negative
259+
values mean the feedback is negative. A zero value is ignored. Inputs
260+
and outputs are indexed starting at 1 to communicate sign information.
261+
inputv : 1D array
262+
list of final external inputs, indexed starting at 1
263+
outputv : 1D array
264+
list of final external outputs, indexed starting at 1
265+
266+
Returns
267+
-------
268+
out : :class:`InputOutputSystem`
269+
Connected and trimmed I/O system.
270+
271+
See Also
272+
--------
273+
append, feedback, interconnect, negate, parallel, series
274+
275+
Examples
276+
--------
277+
>>> G = ct.rss(7, inputs=2, outputs=2)
278+
>>> K = [[1, 2], [2, -1]] # negative feedback interconnection
279+
>>> T = ct.connect(G, K, [2], [1, 2])
280+
>>> T.ninputs, T.noutputs, T.nstates
281+
(1, 2, 7)
282+
283+
"""
284+
# Turn off the deprecation warning
285+
with warnings.catch_warnings():
286+
warnings.filterwarnings('ignore', message="`connect` is deprecated")
287+
return ct_connect(*args)

control/tests/iosys_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,7 +1897,7 @@ def test_nonuniform_timepts(nstates, noutputs, ninputs):
18971897

18981898
def test_ss_nonlinear():
18991899
"""Test ss() for creating nonlinear systems"""
1900-
with pytest.warns(PendingDeprecationWarning, match="use nlsys()"):
1900+
with pytest.warns(DeprecationWarning, match="use nlsys()"):
19011901
secord = ct.ss(secord_update, secord_output, inputs='u', outputs='y',
19021902
states = ['x1', 'x2'], name='secord')
19031903
assert secord.name == 'secord'
@@ -1918,12 +1918,12 @@ def test_ss_nonlinear():
19181918
np.testing.assert_almost_equal(ss_response.outputs, io_response.outputs)
19191919

19201920
# Make sure that optional keywords are allowed
1921-
with pytest.warns(PendingDeprecationWarning, match="use nlsys()"):
1921+
with pytest.warns(DeprecationWarning, match="use nlsys()"):
19221922
secord = ct.ss(secord_update, secord_output, dt=True)
19231923
assert ct.isdtime(secord)
19241924

19251925
# Make sure that state space keywords are flagged
1926-
with pytest.warns(PendingDeprecationWarning, match="use nlsys()"):
1926+
with pytest.warns(DeprecationWarning, match="use nlsys()"):
19271927
with pytest.raises(TypeError, match="unrecognized keyword"):
19281928
ct.ss(secord_update, remove_useless_states=True)
19291929

0 commit comments

Comments
 (0)