Skip to content

Commit bc5079b

Browse files
committed
reverted mistaken margin argument rearrangement and clarified definitions in docstring of margin
1 parent ca8e670 commit bc5079b

3 files changed

Lines changed: 28 additions & 26 deletions

File tree

control/margins.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,12 @@ def margin(*args):
522522
Gain margin
523523
pm : float
524524
Phase margin (in degrees)
525-
wgc : float or array_like
526-
Gain crossover frequency (where gain crosses 1)
527-
wpc : float or array_like
528-
Phase crossover frequency (where phase crosses -180 degrees)
525+
wcg : float or array_like
526+
Crossover frequency associated with gain margin (phase crossover
527+
frequency), where phase crosses below -180 degrees.
528+
wcp : float or array_like
529+
Crossover frequency associated with phase margin (gain crossover
530+
frequency), where gain crosses below 1.
529531
530532
Margins are calculated for a SISO open-loop system.
531533
@@ -536,7 +538,7 @@ def margin(*args):
536538
Examples
537539
--------
538540
>>> sys = tf(1, [1, 2, 1, 0])
539-
>>> gm, pm, wg, wp = margin(sys)
541+
>>> gm, pm, wcg, wcp = margin(sys)
540542
541543
"""
542544
if len(args) == 1:
@@ -548,4 +550,4 @@ def margin(*args):
548550
raise ValueError("Margin needs 1 or 3 arguments; received %i."
549551
% len(args))
550552

551-
return margin[0], margin[1], margin[4], margin[3]
553+
return margin[0], margin[1], margin[3], margin[4]

control/tests/margin_test.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ def test_margin_sys(tsys):
102102
sys, refout, refoutall = tsys
103103
"""Test margin() function with system input"""
104104
out = margin(sys)
105-
assert_allclose(out, np.array(refout)[[0, 1, 4, 3]], atol=1.5e-3)
105+
assert_allclose(out, np.array(refout)[[0, 1, 3, 4]], atol=1.5e-3)
106106

107107
def test_margin_3input(tsys):
108108
sys, refout, refoutall = tsys
109109
"""Test margin() function with mag, phase, omega input"""
110110
omega = np.logspace(-2, 2, 2000)
111111
mag, phase, omega_ = sys.frequency_response(omega)
112112
out = margin((mag, phase*180/np.pi, omega_))
113-
assert_allclose(out, np.array(refout)[[0, 1, 4, 3]], atol=1.5e-3)
113+
assert_allclose(out, np.array(refout)[[0, 1, 3, 4]], atol=1.5e-3)
114114

115115

116116
@pytest.mark.parametrize(
@@ -276,23 +276,23 @@ def tsys_zmore(request, tsys_zmoresystems):
276276
@pytest.mark.parametrize(
277277
'tsys_zmore',
278278
[dict(sysname='typem1', K=2.0, atol=1.5e-3,
279-
result=(float('Inf'), -120.0007, 0.5774, float('NaN'))),
279+
result=(float('Inf'), -120.0007, float('NaN'), 0.5774)),
280280
dict(sysname='type0', K=0.8, atol=1.5e-3,
281-
result=(10.0014, float('inf'), float('nan'), 1.7322)),
281+
result=(10.0014, float('inf'), 1.7322, float('nan'))),
282282
dict(sysname='type0', K=2.0, atol=1e-2,
283-
result=(4.000, 67.6058, 0.7663, 1.7322)),
283+
result=(4.000, 67.6058, 1.7322, 0.7663)),
284284
dict(sysname='type1', K=1.0, atol=1e-4,
285-
result=(float('Inf'), 144.9032, 0.3162, float('NaN'))),
285+
result=(float('Inf'), 144.9032, float('NaN'), 0.3162)),
286286
dict(sysname='type2', K=1.0, atol=1e-4,
287-
result=(float('Inf'), 44.4594, 0.7907, float('NaN'))),
287+
result=(float('Inf'), 44.4594, float('NaN'), 0.7907)),
288288
dict(sysname='type3', K=1.0, atol=1.5e-3,
289-
result=(0.0626, 37.1748, 0.7951, 0.1119)),
289+
result=(0.0626, 37.1748, 0.1119, 0.7951)),
290290
dict(sysname='example21', K=1.0, atol=1e-2,
291291
result=(0.0100, -14.5640, 0, 0.0022)),
292292
dict(sysname='example21', K=1000.0, atol=1e-2,
293-
result=(0.1793, 22.5215, 0.0630, 0.0243)),
293+
result=(0.1793, 22.5215, 0.0243, 0.0630)),
294294
dict(sysname='example21', K=5000.0, atol=1.5e-3,
295-
result=(4.5596, 21.2101, 0.1868, 0.4385)),
295+
result=(4.5596, 21.2101, 0.4385, 0.1868)),
296296
],
297297
indirect=True)
298298
def test_zmore_margin(tsys_zmore):

control/tests/matlab_test.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,13 @@ def testLsim_mimo(self, mimo):
355355
def testMargin(self, siso):
356356
"""Test margin()"""
357357
#! TODO: check results to make sure they are OK
358-
gm, pm, wg, wp = margin(siso.tf1)
359-
gm, pm, wg, wp = margin(siso.tf2)
360-
gm, pm, wg, wp = margin(siso.ss1)
361-
gm, pm, wg, wp = margin(siso.ss2)
362-
gm, pm, wg, wp = margin(siso.ss2 * siso.ss2 * 2)
358+
gm, pm, wcg, wcp = margin(siso.tf1)
359+
gm, pm, wcg, wcp = margin(siso.tf2)
360+
gm, pm, wcg, wcp = margin(siso.ss1)
361+
gm, pm, wcg, wcp = margin(siso.ss2)
362+
gm, pm, wcg, wcp = margin(siso.ss2 * siso.ss2 * 2)
363363
np.testing.assert_array_almost_equal(
364-
[gm, pm, wg, wp], [1.5451, 75.9933, 0.6559, 1.2720], decimal=3)
364+
[gm, pm, wcg, wcp], [1.5451, 75.9933, 1.2720, 0.6559], decimal=3)
365365

366366
def testDcgain(self, siso):
367367
"""Test dcgain() for SISO system"""
@@ -781,12 +781,12 @@ def testCombi01(self):
781781
# total open loop
782782
Hol = Hc*Hno*Hp
783783

784-
gm, pm, wg, wp = margin(Hol)
785-
# print("%f %f %f %f" % (gm, pm, wg, wp))
784+
gm, pm, wcg, wcp = margin(Hol)
785+
# print("%f %f %f %f" % (gm, pm, wcg, wcp))
786786
np.testing.assert_allclose(gm, 3.32065569155)
787787
np.testing.assert_allclose(pm, 46.9740430224)
788-
np.testing.assert_allclose(wg, 0.0616288455466)
789-
np.testing.assert_allclose(wp, 0.176469728448)
788+
np.testing.assert_allclose(wcg, 0.176469728448)
789+
np.testing.assert_allclose(wcp, 0.0616288455466)
790790

791791
def test_tf_string_args(self):
792792
"""Make sure s and z are defined properly"""

0 commit comments

Comments
 (0)