Skip to content

Commit 94fe55e

Browse files
committed
impoed unit tests
1 parent a8a536b commit 94fe55e

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

control/margins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ def stability_margins(sysdata, returnall=False, epsw=0.0, method='best'):
300300
determined by the frequency of maximum sensitivity (given by the
301301
magnitude of 1/(1+L)).
302302
"""
303+
# TODO: FRD method for cont-time systems doesn't work
303304
try:
304305
if isinstance(sysdata, frdata.FRD):
305306
sys = frdata.FRD(sysdata, smooth=True)
@@ -408,7 +409,6 @@ def _dstab(w):
408409
w_180 = np.array(
409410
[sp.optimize.brentq(_arg, sys.omega[i], sys.omega[i+1])
410411
for i in widx])
411-
# TODO: replace by evalfr(sys, 1J*w) or sys(1J*w), (needs gh-449)
412412
w180_resp = sys(1j * w_180)
413413

414414
# Find all crossings, note that this depends on omega having

control/tests/margin_test.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,24 @@ def test_stability_margins_discrete(cnum, cden, dt, ref, rtol):
356356
out = stability_margins(tf, method='poly')
357357
assert_allclose(out, ref, rtol=rtol)
358358

359+
359360
def test_stability_margins_methods():
360-
sys = TransferFunction(1, (1, 2))
361+
# the following system gives slightly inaccurate result for DT systems
362+
# because of numerical issues
363+
omegan = 1
364+
zeta = 0.5
365+
resonance = TransferFunction(omegan**2, [1, 2*zeta*omegan, omegan**2])
366+
omegan2 = 100
367+
resonance2 = TransferFunction(omegan2**2, [1, 2*zeta*omegan2, omegan2**2])
368+
sys = 5 * resonance * resonance2
369+
sysd = sys.sample(0.001, 'zoh')
361370
"""Test stability_margins() function with different methods"""
362-
out = stability_margins(sys, method='best')
363-
out = stability_margins(sys, method='frd')
364-
out = stability_margins(sys, method='poly')
365-
371+
out = stability_margins(sysd, method='best')
372+
assert_allclose(
373+
(18.876634845228644, 11.244969911924102, 0.40684128014454546,
374+
9.763585543509473, 4.351735617240803, 2.559873290031937),
375+
stability_margins(sysd, method='poly'))
376+
assert_allclose(
377+
(18.876634740386308, 26.356358386241055, 0.40684127995261044,
378+
9.763585494645046, 2.3293357226374805, 2.55985695034263),
379+
stability_margins(sysd, method='frd'))

0 commit comments

Comments
 (0)