Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
11 changes: 11 additions & 0 deletions control/tests/timeresp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
import numpy as np
import pytest


Comment thread
UbeenII marked this conversation as resolved.
Resolved
import control as ct
from control import StateSpace, TransferFunction, c2d, isctime, ss2tf, tf2ss
from control.exception import pandas_check
from control.timeresp import _default_time_vector, _ideal_tfinal_and_dt, \
forced_response, impulse_response, initial_response, step_info, \
step_response

import warnings
Comment thread
UbeenII marked this conversation as resolved.
Resolved


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove these extra blank lines before merging. (Normally, only up to 2 blank lines are used to separate top-level blocks in a Python file.)

class TSys:
"""Struct of test system"""
Expand Down Expand Up @@ -826,6 +829,14 @@ def test_auto_generated_time_vector_tfinal(self, tfsys, tfinal):
np.testing.assert_allclose(ideal_tfinal, tfinal, rtol=1e-4)
T = _default_time_vector(tfsys)
np.testing.assert_allclose(T[-1], tfinal, atol=0.5*ideal_dt)

def test_discrete_time_negative_one_settling(self):
#system with -1 pole
TF = TransferFunction([1,3,0],[1,3,2], dt =True)
Comment thread
UbeenII marked this conversation as resolved.
Resolved
with warnings.catch_warnings():
warnings.simplefilter("error")
impulse_response(TF)


@pytest.mark.parametrize("wn, zeta", [(10, 0), (100, 0), (100, .1)])
def test_auto_generated_time_vector_dt_cont1(self, wn, zeta):
Expand Down
3 changes: 2 additions & 1 deletion control/timeresp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2172,12 +2172,13 @@ def _ideal_tfinal_and_dt(sys, is_step=True):
m_z = np.abs(p) < sqrt_eps
p = p[~m_z]
# Negative reals- treated as oscillatory mode
m_nr = (p.real < 0) & (np.abs(p.imag) < sqrt_eps)
m_nr = (p.real < 0) & (np.abs(p.imag) < sqrt_eps) & (np.abs(p.real+1)>sqrt_eps)
Comment thread
UbeenII marked this conversation as resolved.
Resolved
p_nr, p = p[m_nr], p[~m_nr]
if p_nr.size > 0:
t_emp = np.max(log_decay_percent / np.abs((np.log(p_nr)/dt).real))
tfinal = max(tfinal, t_emp)
# discrete integrators

Comment thread
UbeenII marked this conversation as resolved.
Resolved
m_int = (p.real - 1 < sqrt_eps) & (np.abs(p.imag) < sqrt_eps)
p_int, p = p[m_int], p[~m_int]
# pure oscillatory modes
Expand Down
Loading