Skip to content

Commit 24eeb75

Browse files
sawyerbfullerbnavigator
authored andcommitted
re-incorporated lti.timebaseEqual, with a pendingDeprecationWarning
1 parent 5f46b5b commit 24eeb75

2 files changed

Lines changed: 59 additions & 5 deletions

File tree

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"restructuredtext.confPath": "${workspaceFolder}/doc"
3+
}

control/lti.py

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414

1515
import numpy as np
1616
from numpy import absolute, real
17+
from warnings import warn
1718

18-
__all__ = ['issiso', 'timebase', 'common_timebase', 'isdtime', 'isctime',
19-
'pole', 'zero', 'damp', 'evalfr', 'freqresp', 'dcgain']
19+
__all__ = ['issiso', 'timebase', 'common_timebase', 'timebaseEqual',
20+
'isdtime', 'isctime', 'pole', 'zero', 'damp', 'evalfr',
21+
'freqresp', 'dcgain']
2022

2123
class LTI:
2224
"""LTI is a parent class to linear time-invariant (LTI) system objects.
@@ -158,12 +160,35 @@ def timebase(sys, strict=True):
158160
return sys.dt
159161

160162
def common_timebase(dt1, dt2):
161-
"""Find the common timebase when interconnecting systems."""
162-
# cases:
163+
"""
164+
Find the common timebase when interconnecting systems
165+
166+
Parameters
167+
----------
168+
dt1, dt2: number or system with a 'dt' attribute (e.g. TransferFunction
169+
or StateSpace system)
170+
171+
Returns
172+
-------
173+
dt: number
174+
The common timebase of dt1 and dt2, as specified in
175+
:ref:`conventions-ref`.
176+
177+
Raises
178+
------
179+
ValueError
180+
when no compatible time base can be found
181+
"""
182+
# explanation:
163183
# if either dt is None, they are compatible with anything
164184
# if either dt is True (discrete with unspecified time base),
165185
# use the timebase of the other, if it is also discrete
166-
# otherwise they must be equal (holds for both cont and discrete systems)
186+
# otherwise both dts must be equal
187+
if hasattr(dt1, 'dt'):
188+
dt1 = dt1.dt
189+
if hasattr(dt2, 'dt'):
190+
dt2 = dt2.dt
191+
167192
if dt1 is None:
168193
return dt2
169194
elif dt2 is None:
@@ -183,6 +208,32 @@ def common_timebase(dt1, dt2):
183208
else:
184209
raise ValueError("Systems have incompatible timebases")
185210

211+
# Check to see if two timebases are equal
212+
def timebaseEqual(sys1, sys2):
213+
"""
214+
Check to see if two systems have the same timebase
215+
216+
timebaseEqual(sys1, sys2)
217+
218+
returns True if the timebases for the two systems are compatible. By
219+
default, systems with timebase 'None' are compatible with either
220+
discrete or continuous timebase systems. If two systems have a discrete
221+
timebase (dt > 0) then their timebases must be equal.
222+
"""
223+
warn("timebaseEqual will be deprecated in a future release of "
224+
"python-control; use :func:`common_timebase` instead",
225+
PendingDeprecationWarning)
226+
227+
if (type(sys1.dt) == bool or type(sys2.dt) == bool):
228+
# Make sure both are unspecified discrete timebases
229+
return type(sys1.dt) == type(sys2.dt) and sys1.dt == sys2.dt
230+
elif (sys1.dt is None or sys2.dt is None):
231+
# One or the other is unspecified => the other can be anything
232+
return True
233+
else:
234+
return sys1.dt == sys2.dt
235+
236+
186237
# Check to see if a system is a discrete time system
187238
def isdtime(sys, strict=False):
188239
"""

0 commit comments

Comments
 (0)