Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion control/margins.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,4 @@ def margin(*args):
raise ValueError("Margin needs 1 or 3 arguments; received %i."
% len(args))

return margin[0], margin[1], margin[4], margin[3]
return margin[0], margin[1], margin[3], margin[4]
9 changes: 8 additions & 1 deletion control/tests/margin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def setUp(self):
s = TransferFunction([1, 0], [1])
self.sys4 = (8.75*(4*s**2+0.4*s+1))/((100*s+1)*(s**2+0.22*s+1)) * \
1./(s**2/(10.**2)+2*0.04*s/10.+1)
self.stability_margins4 = [2.2716, 97.5941, 1.0454, 10.0053, 0.0850, 0.4973]

def test_stability_margins(self):
gm, pm, sm, wg, wp, ws = stability_margins(self.sys1);
Expand All @@ -28,7 +29,13 @@ def test_stability_margins(self):
gm, pm, sm, wg, wp, ws = stability_margins(self.sys4);
np.testing.assert_array_almost_equal(
[gm, pm, sm, wg, wp, ws],
[2.2716, 97.5941, 1.0454, 10.0053, 0.0850, 0.4973], 3)
self.stability_margins4, 3)

def test_margin(self):
gm, pm, wg, wp = margin(self.sys4)
np.testing.assert_array_almost_equal(
[gm, pm, wg, wp],
self.stability_margins4[:2] + self.stability_margins4[3:5], 3)

def test_phase_crossover_frequencies(self):
omega, gain = phase_crossover_frequencies(self.sys2)
Expand Down
6 changes: 2 additions & 4 deletions control/tests/matlab_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def testMargin(self):
gm, pm, wg, wp = margin(self.siso_ss2);
gm, pm, wg, wp = margin(self.siso_ss2*self.siso_ss2*2);
np.testing.assert_array_almost_equal(
[gm, pm, wg, wp], [1.5451, 75.9933, 0.6559, 1.2720], decimal=3)
[gm, pm, wg, wp], [1.5451, 75.9933, 1.2720, 0.6559], decimal=3)

def testDcgain(self):
#Create different forms of a SISO system
Expand Down Expand Up @@ -554,8 +554,6 @@ def testSS2cont(self):
-0.260952977031384 -0.274201791021713;
-0.304617775734327 0.075182622718853"""), sysd.B)


@unittest.skip("need to update margin command")
def testCombi01(self):
# test from a "real" case, combines tf, ss, connect and margin
# this is a type 2 system, with phase starting at -180. The
Expand Down Expand Up @@ -610,8 +608,8 @@ def testCombi01(self):
# print("%f %f %f %f" % (gm, pm, wg, wp))
self.assertAlmostEqual(gm, 3.32065569155)
self.assertAlmostEqual(pm, 46.9740430224)
self.assertAlmostEqual(wp, 0.0616288455466)
self.assertAlmostEqual(wg, 0.176469728448)
self.assertAlmostEqual(wp, 0.0616288455466)

#! TODO: not yet implemented
# def testMIMOtfdata(self):
Expand Down