Skip to content

Commit 04ed40d

Browse files
committed
Merge remote-tracking branch 'upstream/master'
solved the conflict in the margin_test routine updated the doc for margin to match order of returned values
2 parents cd30a00 + b03e294 commit 04ed40d

3 files changed

Lines changed: 19 additions & 12 deletions

File tree

control/margins.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def _polysqr(pol):
8787
# RvP, July 8, 2015, augmented to calculate all phase/gain crossings with
8888
# frd data. Correct to return smallest phase
8989
# margin, smallest gain margin and their frequencies
90-
def stability_margins(sysdata, returnall=False, epsw=1e-10):
90+
def stability_margins(sysdata, returnall=False, epsw=1e-8):
9191
"""Calculate stability margins and associated crossover frequencies.
9292
9393
Parameters
@@ -331,11 +331,12 @@ def margin(*args):
331331
Returns
332332
-------
333333
gm, pm, Wcg, Wcp : float
334-
Gain margin gm, phase margin pm (in deg), gain crossover frequency
335-
(corresponding to phase margin) and phase crossover frequency
336-
(corresponding to gain margin), in rad/sec of SISO open-loop.
337-
If more than one crossover frequency is detected, returns the lowest
338-
corresponding margin.
334+
Gain margin gm, phase margin pm (in deg), phase crossover frequency
335+
(corresponding to gain margin, where phase=-180) and gain crossover
336+
frequency (corresponding to phase margin, where gain is 0dB),
337+
in rad/sec of SISO open-loop.
338+
If more than one crossover frequency is detected for gain or phase,
339+
this returns one with the lowest corresponding margin.
339340
340341
Examples
341342
--------
@@ -352,4 +353,4 @@ def margin(*args):
352353
raise ValueError("Margin needs 1 or 3 arguments; received %i."
353354
% len(args))
354355

355-
return margin[0], margin[1], margin[4], margin[3]
356+
return margin[0], margin[1], margin[3], margin[4]

control/tests/margin_test.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def setUp(self):
4040
s = TransferFunction([1, 0], [1])
4141
self.sys4 = (8.75*(4*s**2+0.4*s+1))/((100*s+1)*(s**2+0.22*s+1)) * \
4242
1./(s**2/(10.**2)+2*0.04*s/10.+1)
43+
self.stability_margins4 = \
44+
[2.2716, 97.5941, 0.5591, 10.0053, 0.0850, 9.9918]
4345

4446
def test_stability_margins(self):
4547
omega = np.logspace(-2, 2, 2000)
@@ -57,7 +59,13 @@ def test_stability_margins(self):
5759
# final one with fixed values
5860
np.testing.assert_array_almost_equal(
5961
[gm, pm, sm, wg, wp, ws],
60-
[2.2716, 97.5941, 0.5591, 10.0053, 0.0850, 9.9918], 3)
62+
self.stability_margins4, 3)
63+
64+
def test_margin(self):
65+
gm, pm, wg, wp = margin(self.sys4)
66+
np.testing.assert_array_almost_equal(
67+
[gm, pm, wg, wp],
68+
self.stability_margins4[:2] + self.stability_margins4[3:5], 3)
6169

6270
def test_stability_margins_all(self):
6371
for sys,rgm,rwgm,rpm,rwpm in self.tsys:

control/tests/matlab_test.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def testMargin(self):
257257
gm, pm, wg, wp = margin(self.siso_ss2);
258258
gm, pm, wg, wp = margin(self.siso_ss2*self.siso_ss2*2);
259259
np.testing.assert_array_almost_equal(
260-
[gm, pm, wg, wp], [1.5451, 75.9933, 0.6559, 1.2720], decimal=3)
260+
[gm, pm, wg, wp], [1.5451, 75.9933, 1.2720, 0.6559], decimal=3)
261261

262262
def testDcgain(self):
263263
#Create different forms of a SISO system
@@ -554,8 +554,6 @@ def testSS2cont(self):
554554
-0.260952977031384 -0.274201791021713;
555555
-0.304617775734327 0.075182622718853"""), sysd.B)
556556

557-
558-
@unittest.skip("need to update margin command")
559557
def testCombi01(self):
560558
# test from a "real" case, combines tf, ss, connect and margin
561559
# this is a type 2 system, with phase starting at -180. The
@@ -610,8 +608,8 @@ def testCombi01(self):
610608
# print("%f %f %f %f" % (gm, pm, wg, wp))
611609
self.assertAlmostEqual(gm, 3.32065569155)
612610
self.assertAlmostEqual(pm, 46.9740430224)
613-
self.assertAlmostEqual(wp, 0.0616288455466)
614611
self.assertAlmostEqual(wg, 0.176469728448)
612+
self.assertAlmostEqual(wp, 0.0616288455466)
615613

616614
#! TODO: not yet implemented
617615
# def testMIMOtfdata(self):

0 commit comments

Comments
 (0)