33# margin_test.py - test suit for stability margin commands
44# RMM, 15 Jul 2011
55
6+ from __future__ import print_function
67import unittest
78import numpy as np
89from control .xferfcn import TransferFunction
@@ -23,14 +24,18 @@ def setUp(self):
2324 1. / (s ** 2 / (10. ** 2 )+ 2 * 0.04 * s / 10. + 1 )
2425
2526 def test_stability_margins (self ):
26- gm , pm , sm , wg , wp , ws = stability_margins (self .sys1 );
27- gm , pm , sm , wg , wp , ws = stability_margins (self .sys2 );
28- gm , pm , sm , wg , wp , ws = stability_margins (self .sys3 );
29- gm , pm , sm , wg , wp , ws = stability_margins (self .sys4 );
27+ omega = np .logspace (- 2 , 2 , 200 )
28+ for sys in (self .sys1 , self .sys2 , self .sys3 , self .sys4 ):
29+ out = stability_margins (sys )
30+ gm , pm , sm , wg , wp , ws = out
31+ outf = stability_margins (FRD (sys , omega ))
32+ print (sys , out , outf )
33+ np .testing .assert_array_almost_equal (out , outf , 3 )
34+ # final one with fixed values
3035 np .testing .assert_array_almost_equal (
3136 [gm , pm , sm , wg , wp , ws ],
32- [2.2716 , 97.5941 , 0.9565 , 10.0053 , 0.0850 , 0.4973 ], 3 )
33-
37+ [2.2716 , 97.5941 , 0.9633 , 10.0053 , 0.0850 , 0.4064 ], 3 )
38+
3439 def test_phase_crossover_frequencies (self ):
3540 omega , gain = phase_crossover_frequencies (self .sys2 )
3641 np .testing .assert_array_almost_equal (omega , [1.73205 , 0. ])
@@ -95,7 +100,6 @@ def test_frd(self):
95100 C = K * (1 + 1.9 * s )
96101 TFopen = fresp * C * G
97102 gm , pm , sm , wg , wp , ws = stability_margins (TFopen )
98- print gm
99103 np .testing .assert_array_almost_equal (
100104 [pm ], [44.55 ], 2 )
101105
@@ -105,7 +109,7 @@ def test_nocross(self):
105109 h1 = 1 / (1 + s )
106110 h2 = 3 * (10 + s )/ (2 + s )
107111 h3 = 0.01 * (10 - s )/ (2 + s )/ (1 + s )
108- gm , pm , sm , wg , wp , ws = stability_margins (h1 )
112+ gm , pm , wm , wg , wp , ws = stability_margins (h1 )
109113 self .assertEqual (gm , None )
110114 self .assertEqual (wg , None )
111115 gm , pm , wm , wg , wp , ws = stability_margins (h2 )
@@ -117,7 +121,6 @@ def test_nocross(self):
117121 out2b = stability_margins (FRD (h2 , omega ))
118122 out3b = stability_margins (FRD (h3 , omega ))
119123
120-
121124
122125def test_suite ():
123126 return unittest .TestLoader ().loadTestsFromTestCase (TestMargin )
0 commit comments