diff --git a/control/canonical.py b/control/canonical.py index 5eacce372..bbed5084e 100644 --- a/control/canonical.py +++ b/control/canonical.py @@ -64,7 +64,10 @@ def reachable_form(xsys): "Canonical forms for MIMO systems not yet supported") # Create a new system, starting with a copy of the old one - zsys = StateSpace(xsys) + print(xsys) + #print(*xsys) + l=[xsys.A,xsys.B,xsys.C,xsys.D,xsys.dt] + zsys = StateSpace(*l) # Generate the system matrices for the desired canonical form zsys.B = zeros(shape(xsys.B)) diff --git a/control/setup.py b/control/setup.py deleted file mode 100644 index 3ed3e3a7e..000000000 --- a/control/setup.py +++ /dev/null @@ -1,5 +0,0 @@ -def configuration(parent_package='', top_path=None): - from numpy.distutils.misc_util import Configuration - config = Configuration('control', parent_package, top_path) - config.add_subpackage('tests') - return config diff --git a/control/statesp.py b/control/statesp.py index 13e662f03..16eca6095 100644 --- a/control/statesp.py +++ b/control/statesp.py @@ -91,38 +91,21 @@ class StateSpace(LTI): """ - def __init__(self, *args): + def __init__(self,A,B,C,D,dt=None): """Construct a state space object. The default constructor is StateSpace(A, B, C, D), where A, B, C, D are matrices or equivalent objects. To call the copy constructor, call StateSpace(sys), where sys is a StateSpace object. + + Matrix sizes need to be consistent: + A must be square. + A and B must have the same number of rows. + A and C must have the same number of columns. + B and D must have the same number of columns. + C and D must have the same number of rows. """ - - if len(args) == 4: - # The user provided A, B, C, and D matrices. - (A, B, C, D) = args - dt = None; - elif len(args) == 5: - # Discrete time system - (A, B, C, D, dt) = args - elif len(args) == 1: - # Use the copy constructor. - if not isinstance(args[0], StateSpace): - raise TypeError("The one-argument constructor can only take in \ -a StateSpace object. Recived %s." % type(args[0])) - A = args[0].A - B = args[0].B - C = args[0].C - D = args[0].D - try: - dt = args[0].dt - except NameError: - dt = None; - else: - raise ValueError("Needs 1 or 4 arguments; received %i." % len(args)) - A, B, C, D = map(matrix, [A, B, C, D]) # TODO: use super here? @@ -131,6 +114,7 @@ def __init__(self, *args): self.B = B self.C = C self.D = D + self.dt=dt self.states = A.shape[1] @@ -491,7 +475,7 @@ def minreal(self, tol=0.0): except ImportError: raise TypeError("minreal requires slycot tb01pd") else: - return StateSpace(self) + return StateSpace(self.A,self.B,self.C,self.D,self.dt) # TODO: add discrete time check @@ -545,6 +529,7 @@ def append(self, other): def __getitem__(self, indices): """Array style acces""" + if len(indices) != 2: raise IOError('must provide indices of length 2 for state space') i = indices[0] diff --git a/control/tests/canonical_test.py b/control/tests/canonical_test.py index f5908a8f4..b980c7591 100644 --- a/control/tests/canonical_test.py +++ b/control/tests/canonical_test.py @@ -52,3 +52,10 @@ def test_unreachable_system(self): # Check if an exception is raised np.testing.assert_raises(ValueError, canonical_form, sys, "reachable") + +if __name__=="__main__": + t=TestCanonical() + t.test_reachable_form() + t.test_unreachable_system() + a=1 + #unittest.main() diff --git a/control/tests/discrete_test.py b/control/tests/discrete_test.py index 2d4f3f457..4be3d6ffb 100644 --- a/control/tests/discrete_test.py +++ b/control/tests/discrete_test.py @@ -68,8 +68,12 @@ def testSystemInitialization(self): def testCopyConstructor(self): for sys in (self.siso_ss1, self.siso_ss1c, self.siso_ss1d): - newsys = StateSpace(sys); + + args=[sys.A,sys.B,sys.C,sys.D,sys.dt] + newsys = StateSpace(*args); + self.assertEqual(sys.dt, newsys.dt) + for sys in (self.siso_tf1, self.siso_tf1c, self.siso_tf1d): newsys = TransferFunction(sys); self.assertEqual(sys.dt, newsys.dt)