Skip to content

Commit d6916c6

Browse files
author
Mark
committed
Expand unit tests, add info to doc string for parameters and returns, rename is_passive to ispassive for naming convention consistency. Autoformat to pep8.
1 parent 27487a9 commit d6916c6

2 files changed

Lines changed: 50 additions & 14 deletions

File tree

control/passivity.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,27 @@
1010
except ImportError as e:
1111
cvx = None
1212

13-
lmi_epsilon = 1e-12
1413

15-
def is_passive(sys):
14+
def ispassive(sys):
1615
'''
17-
Indicates if a linear time invariant system is passive
16+
Indicates if a linear time invariant (LTI) system is passive
1817
1918
Constructs a linear matrix inequality and a feasibility optimization
2019
such that if a solution exists, the system is passive.
2120
2221
The source for the algorithm is:
2322
McCourt, Michael J., and Panos J. Antsaklis.
2423
"Demonstrating passivity and dissipativity using computational methods." ISIS 8 (2013).
24+
25+
Parameters
26+
----------
27+
sys: A continuous LTI system
28+
System to be checked.
29+
30+
Returns
31+
-------
32+
bool:
33+
The input system passive.
2534
'''
2635
if cvx is None:
2736
raise ModuleNotFoundError("cvxopt required for passivity module")
@@ -31,9 +40,9 @@ def is_passive(sys):
3140
C = sys.C
3241
D = sys.D
3342

34-
#account for strictly proper systems
35-
[n,m] = D.shape
36-
D = D + np.nextafter(0,1)*np.eye(n,m)
43+
# account for strictly proper systems
44+
[n, m] = D.shape
45+
D = D + np.nextafter(0, 1)*np.eye(n, m)
3746

3847
def make_LMI_matrix(P):
3948
V = np.vstack((

control/tests/passivity_test.py

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,57 @@
77
from control import ss, passivity
88
from control.tests.conftest import cvxoptonly
99

10+
1011
@cvxoptonly
11-
def test_is_passive():
12+
def test_ispassive():
1213
A = numpy.array([[0, 1], [-2, -2]])
1314
B = numpy.array([[0], [1]])
1415
C = numpy.array([[-1, 2]])
1516
D = numpy.array([[1.5]])
1617
sys = ss(A, B, C, D)
1718

1819
# happy path is passive
19-
assert(passivity.is_passive(sys))
20+
assert(passivity.ispassive(sys))
2021

2122
# happy path not passive
2223
D = -D
2324
sys = ss(A, B, C, D)
2425

25-
assert(not passivity.is_passive(sys))
26+
assert(not passivity.ispassive(sys))
27+
28+
29+
@cvxoptonly
30+
def test_ispassive_edge_cases():
31+
A = numpy.array([[0, 1], [-2, -2]])
32+
B = numpy.array([[0], [1]])
33+
C = numpy.array([[-1, 2]])
34+
D = numpy.array([[1.5]])
2635

27-
#edge cases of D=0 boundary condition
28-
B *= 0
29-
C *= 0
3036
D *= 0
37+
38+
# strictly proper
3139
sys = ss(A, B, C, D)
32-
assert(passivity.is_passive(sys))
40+
assert(passivity.ispassive(sys))
3341

42+
# ill conditioned
3443
A = A*1e12
3544
sys = ss(A, B, C, D)
36-
assert(passivity.is_passive(sys))
45+
assert(passivity.ispassive(sys))
46+
47+
# different combinations of zero A,B,C,D are 0
48+
B *= 0
49+
C *= 0
50+
assert(passivity.ispassive(sys))
51+
52+
A *= 0
53+
B = numpy.array([[0], [1]])
54+
C = numpy.array([[-1, 2]])
55+
D = numpy.array([[1.5]])
56+
assert(passivity.ispassive(sys))
57+
58+
B *= 0
59+
C *= 0
60+
assert(passivity.ispassive(sys))
61+
62+
A *= 0
63+
assert(passivity.ispassive(sys))

0 commit comments

Comments
 (0)