forked from python-control/python-control
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlti_test.py
More file actions
43 lines (37 loc) · 1.38 KB
/
Copy pathlti_test.py
File metadata and controls
43 lines (37 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
import unittest
import numpy as np
from control.lti import *
from control.xferfcn import tf
from control import c2d
import numpy as np
class TestUtils(unittest.TestCase):
def test_pole(self):
sys = tf(126, [-1, 42])
np.testing.assert_equal(sys.pole(), 42)
np.testing.assert_equal(pole(sys), 42)
def test_zero(self):
sys = tf([-1, 42], [1, 10])
np.testing.assert_equal(sys.zero(), 42)
np.testing.assert_equal(zero(sys), 42)
def test_damp(self):
# Test the continuous time case.
zeta = 0.1
wn = 42
p = -wn * zeta + 1j * wn * np.sqrt(1 - zeta**2)
sys = tf(1, [1, 2 * zeta * wn, wn**2])
expected = ([wn, wn], [zeta, zeta], [p, p.conjugate()])
np.testing.assert_equal(sys.damp(), expected)
np.testing.assert_equal(damp(sys), expected)
# Also test the discrete time case.
dt = 0.001
sys_dt = c2d(sys, dt, method='matched')
p_zplane = np.exp(p*dt)
expected_dt = ([wn, wn], [zeta, zeta],
[p_zplane, p_zplane.conjugate()])
np.testing.assert_almost_equal(sys_dt.damp(), expected_dt)
np.testing.assert_almost_equal(damp(sys_dt), expected_dt)
def test_dcgain(self):
sys = tf(84, [1, 2])
np.testing.assert_equal(sys.dcgain(), 42)
np.testing.assert_equal(dcgain(sys), 42)