def test_isdtime(self, objfun, arg, dt, ref, strictref): """Test isdtime and isctime functions to follow convention""" obj = objfun(*arg, dt=dt) assert isdtime(obj) == ref assert isdtime(obj, strict=True) == strictref if dt is not None: ref = not ref strictref = not strictref assert isctime(obj) == ref assert isctime(obj, strict=True) == strictref
def test_class_constants_z(self): """Make sure that the 'z' variable is defined properly""" z = TransferFunction.z G = (z + 1)/(z**2 + 2*z + 1) np.testing.assert_array_almost_equal(G.num, [[[1, 1]]]) np.testing.assert_array_almost_equal(G.den, [[[1, 2, 1]]]) assert isdtime(G, strict=True)
def test_lqr_integral_discrete(self): # Generate a discrete time system for testing sys = ct.drss(4, 4, 2, strictly_proper=True) sys.C = np.eye(4) # reset output to be full state C_int = np.eye(2, 4) # integrate outputs for first two states nintegrators = C_int.shape[0] # Generate a controller with integral action K, _, _ = ct.lqr(sys, np.eye(sys.nstates + nintegrators), np.eye(sys.ninputs), integral_action=C_int) Kp, Ki = K[:, :sys.nstates], K[:, sys.nstates:] # Create an I/O system for the controller ctrl, clsys = ct.create_statefbk_iosystem(sys, K, integral_action=C_int) # Construct the state space matrices by hand A_ctrl = np.eye(nintegrators) B_ctrl = np.block( [[-C_int, np.zeros((nintegrators, sys.ninputs)), C_int]]) C_ctrl = -K[:, sys.nstates:] D_ctrl = np.block([[Kp, np.eye(nintegrators), -Kp]]) # Check to make sure everything matches assert ct.isdtime(clsys) np.testing.assert_array_almost_equal(ctrl.A, A_ctrl) np.testing.assert_array_almost_equal(ctrl.B, B_ctrl) np.testing.assert_array_almost_equal(ctrl.C, C_ctrl) np.testing.assert_array_almost_equal(ctrl.D, D_ctrl)
def testisdtime(self, tsys): # Constant assert isdtime(1) assert not isdtime(1, strict=True) # State space assert isdtime(tsys.siso_ss1) assert not isdtime(tsys.siso_ss1, strict=True) assert not isdtime(tsys.siso_ss1c) assert not isdtime(tsys.siso_ss1c, strict=True) assert isdtime(tsys.siso_ss1d) assert isdtime(tsys.siso_ss1d, strict=True) assert isdtime(tsys.siso_ss3d, strict=True) # Transfer function assert isdtime(tsys.siso_tf1) assert not isdtime(tsys.siso_tf1, strict=True) assert not isdtime(tsys.siso_tf1c) assert not isdtime(tsys.siso_tf1c, strict=True) assert isdtime(tsys.siso_tf1d) assert isdtime(tsys.siso_tf1d, strict=True) assert isdtime(tsys.siso_tf3d, strict=True)
def testisdtime(self): # Constant self.assertEqual(isdtime(1), True) self.assertEqual(isdtime(1, strict=True), False) # State space self.assertEqual(isdtime(self.siso_ss1), True) self.assertEqual(isdtime(self.siso_ss1, strict=True), False) self.assertEqual(isdtime(self.siso_ss1c), False) self.assertEqual(isdtime(self.siso_ss1c, strict=True), False) self.assertEqual(isdtime(self.siso_ss1d), True) self.assertEqual(isdtime(self.siso_ss1d, strict=True), True) self.assertEqual(isdtime(self.siso_ss3d, strict=True), True) # Transfer function self.assertEqual(isdtime(self.siso_tf1), True) self.assertEqual(isdtime(self.siso_tf1, strict=True), False) self.assertEqual(isdtime(self.siso_tf1c), False) self.assertEqual(isdtime(self.siso_tf1c, strict=True), False) self.assertEqual(isdtime(self.siso_tf1d), True) self.assertEqual(isdtime(self.siso_tf1d, strict=True), True) self.assertEqual(isdtime(self.siso_tf3d, strict=True), True)