Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit02080e0

Browse files
committed
BugFix: tf2ss now handles static MIMO gains with no Slycot
Check for static-gain (i.e., constant) transfer function matrix, andhandle specially.Added unit tests for static SISO and MIMO plants.
1 parent8caf661 commit02080e0

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

‎control/statesp.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
# Python 3 compatibility (needs to go here)
1212
from __future__importprint_function
13+
from __future__importdivision# for _convertToStateSpace
1314

1415
"""Copyright (c) 2010 by California Institute of Technology
1516
All rights reserved.
@@ -647,6 +648,7 @@ def _convertToStateSpace(sys, **kw):
647648
"""
648649

649650
from .xferfcnimportTransferFunction
651+
importitertools
650652
ifisinstance(sys,StateSpace):
651653
iflen(kw):
652654
raiseTypeError("If sys is a StateSpace, _convertToStateSpace\
@@ -679,16 +681,26 @@ def _convertToStateSpace(sys, **kw):
679681
ssout[3][:sys.outputs, :states],
680682
ssout[4],sys.dt)
681683
exceptImportError:
682-
# If slycot is not available, use signal.lti (SISO only)
683-
if (sys.inputs!=1orsys.outputs!=1):
684-
raiseTypeError("No support for MIMO without slycot")
685-
686-
# TODO: do we want to squeeze first and check dimenations?
687-
# I think this will fail if num and den aren't 1-D after
688-
# the squeeze
689-
lti_sys=lti(squeeze(sys.num),squeeze(sys.den))
690-
returnStateSpace(lti_sys.A,lti_sys.B,lti_sys.C,lti_sys.D,
691-
sys.dt)
684+
# No Slycot. Scipy tf->ss can't handle MIMO, but static MIMO is an easy special case we can check for here
685+
maxn=max(max(len(n)forninnrow)
686+
fornrowinsys.num)
687+
maxd=max(max(len(d)fordindrow)
688+
fordrowinsys.den)
689+
if1==maxnand1==maxd:
690+
D=empty((sys.outputs,sys.inputs),dtype=float)
691+
fori,jinitertools.product(range(sys.outputs),range(sys.inputs)):
692+
D[i,j]=sys.num[i][j][0]/sys.den[i][j][0]
693+
returnStateSpace([], [], [],D,sys.dt)
694+
else:
695+
if (sys.inputs!=1orsys.outputs!=1):
696+
raiseTypeError("No support for MIMO without slycot")
697+
698+
# TODO: do we want to squeeze first and check dimenations?
699+
# I think this will fail if num and den aren't 1-D after
700+
# the squeeze
701+
lti_sys=lti(squeeze(sys.num),squeeze(sys.den))
702+
returnStateSpace(lti_sys.A,lti_sys.B,lti_sys.C,lti_sys.D,
703+
sys.dt)
692704

693705
elifisinstance(sys, (int,float,complex)):
694706
if"inputs"inkw:

‎control/tests/convert_test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,28 @@ def testConvertMIMO(self):
184184
if (notslycot_check()):
185185
self.assertRaises(TypeError,control.tf2ss,tfcn)
186186

187+
deftestTf2ssStaticSiso(self):
188+
"""Regression: tf2ss for SISO static gain"""
189+
importcontrol
190+
gsiso=control.tf2ss(control.tf(23,46))
191+
self.assertEqual(0,gsiso.states)
192+
self.assertEqual(1,gsiso.inputs)
193+
self.assertEqual(1,gsiso.outputs)
194+
# in all cases ratios are exactly representable, so assert_array_equal is fine
195+
np.testing.assert_array_equal([[0.5]],gsiso.D)
196+
197+
deftestTf2ssStaticMimo(self):
198+
"""Regression: tf2ss for MIMO static gain"""
199+
importcontrol
200+
# 2x3 TFM
201+
gmimo=control.tf2ss(control.tf([[ [23], [3], [5] ], [ [-1], [0.125], [101.3] ]],
202+
[[ [46], [0.1], [80] ], [ [2], [-0.1], [1] ]]))
203+
self.assertEqual(0,gmimo.states)
204+
self.assertEqual(3,gmimo.inputs)
205+
self.assertEqual(2,gmimo.outputs)
206+
d=np.matrix([[0.5,30,0.0625], [-0.5,-1.25,101.3]])
207+
np.testing.assert_array_equal(d,gmimo.D)
208+
187209

188210
defsuite():
189211
returnunittest.TestLoader().loadTestsFromTestCase(TestConvert)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp