Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Rebased #431: Default dt is 0#490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
bnavigator merged 14 commits intopython-control:masterfrombnavigator:rebase-pr431
Dec 31, 2020
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
14 commits
Select commitHold shift + click to select a range
578cfa6
Revert "make tests work with pre #431 source code state" from #438
bnavigatorDec 30, 2020
86401d6
set default dt to be 0 instead of None.
sawyerbfullerJul 17, 2020
1ed9ee2
changes so that a default dt=0 passes unit tests. fixed code everywhe…
sawyerbfullerJul 17, 2020
5f46b5b
small bugfix to xferfcn._evalfr to correctly give it dt value
sawyerbfullerJul 18, 2020
24eeb75
re-incorporated lti.timebaseEqual, with a pendingDeprecationWarning
sawyerbfullerJul 20, 2020
0223b82
changes to enable package-wide default, 'control.default_dt')
sawyerbfullerJul 20, 2020
1ca9dec
fixes to docstrings and conventions.rst to match convention of dt=0 a…
sawyerbfullerJul 20, 2020
3b2ab18
remove extraneous file
sawyerbfullerJul 21, 2020
351e0f7
new method is_static_gain() for state space and transfer function sys…
sawyerbfullerJul 22, 2020
e3a0070
added keyword arguments to xferfcn.tf and statesp.ss to set dt
sawyerbfullerJul 22, 2020
404b23c
update tests for dt=0, fix the constructor checks for missing dt
bnavigatorDec 31, 2020
8b82850
remove duplicate is_static_gain
bnavigatorDec 31, 2020
b9dc8df
Merge branch 'master' into rebase-pr431
murrayrmDec 31, 2020
75f3aef
add test for dt in arg and kwarg
bnavigatorDec 31, 2020
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
10 changes: 8 additions & 2 deletionscontrol/config.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,7 +15,7 @@

# Package level default values
_control_defaults = {
# No package level defaults (yet)
'control.default_dt':0
}
defaults = dict(_control_defaults)

Expand DownExpand Up@@ -59,6 +59,9 @@ def reset_defaults():
from .statesp import _statesp_defaults
defaults.update(_statesp_defaults)

from .iosys import _iosys_defaults
defaults.update(_iosys_defaults)


def _get_param(module, param, argval=None, defval=None, pop=False):
"""Return the default value for a configuration option.
Expand DownExpand Up@@ -208,8 +211,11 @@ def use_legacy_defaults(version):
# Go backwards through releases and reset defaults
#

# Version 0.9.0: switched to 'array' as default for state space objects
# Version 0.9.0:
if major == 0 and minor < 9:
# switched to 'array' as default for state space objects
set_defaults('statesp', use_numpy_matrix=True)
# switched to 0 (=continuous) as default timestep
set_defaults('control', default_dt=None)

return (major, minor, patch)
64 changes: 33 additions & 31 deletionscontrol/dtime.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -53,21 +53,19 @@

# Sample a continuous time system
def sample_system(sysc, Ts, method='zoh', alpha=None, prewarp_frequency=None):
"""Convert a continuous time system to discrete time

Creates a discrete time system from a continuous time system by
sampling. Multiple methods of conversion are supported.
"""
Convert a continuous time system to discrete time by sampling

Parameters
----------
sysc :linsys
sysc :LTI (StateSpace or TransferFunction)
Continuous time system to be converted
Ts : real
Ts : real > 0
Sampling period
method : string
Method to use for conversion: 'matched', 'tustin', 'zoh' (default)
Method to use for conversion, e.g. 'bilinear', 'zoh' (default)

prewarp_frequency :float within [0, infinity)
prewarp_frequency :real within [0, infinity)
The frequency [rad/s] at which to match with the input continuous-
time system's magnitude and phase

Expand All@@ -78,13 +76,13 @@ def sample_system(sysc, Ts, method='zoh', alpha=None, prewarp_frequency=None):

Notes
-----
See`TransferFunction.sample`and `StateSpace.sample` for
See:meth:`StateSpace.sample`or :meth:`TransferFunction.sample`` for
further details.

Examples
--------
>>> sysc = TransferFunction([1], [1, 2, 1])
>>> sysd = sample_system(sysc, 1, method='matched')
>>> sysd = sample_system(sysc, 1, method='bilinear')
"""

# Make sure we have a continuous time system
Expand All@@ -95,35 +93,39 @@ def sample_system(sysc, Ts, method='zoh', alpha=None, prewarp_frequency=None):


def c2d(sysc, Ts, method='zoh', prewarp_frequency=None):
'''
Return adiscrete-time system
"""
Convert acontinuoustime system to discrete time by sampling

Parameters
----------
sysc: LTI (StateSpace or TransferFunction), continuous
System to be converted
sysc : LTI (StateSpace or TransferFunction)
Continuous time system to be converted
Ts : real > 0
Sampling period
method : string
Method to use for conversion, e.g. 'bilinear', 'zoh' (default)

Ts: number
Sample time for the conversion
prewarp_frequency : real within [0, infinity)
The frequency [rad/s] at which to match with the input continuous-
time system's magnitude and phase

method: string, optional
Method to be applied,
'zoh' Zero-order hold on the inputs (default)
'foh' First-order hold, currently not implemented
'impulse' Impulse-invariant discretization, currently not implemented
'tustin' Bilinear (Tustin) approximation, only SISO
'matched' Matched pole-zero method, only SISO
Returns
-------
sysd : linsys
Discrete time system, with sampling rate Ts

Notes
-----
See :meth:`StateSpace.sample` or :meth:`TransferFunction.sample`` for
further details.

prewarp_frequency : float within [0, infinity)
The frequency [rad/s] at which to match with the input continuous-
time system's magnitude and phase
Examples
--------
>>> sysc = TransferFunction([1], [1, 2, 1])
>>> sysd = sample_system(sysc, 1, method='bilinear')
"""

'''
# Call the sample_system() function to do the work
sysd = sample_system(sysc, Ts, method, prewarp_frequency)

# TODO: is this check needed? If sysc is StateSpace, sysd is too?
if isinstance(sysc, StateSpace) and not isinstance(sysd, StateSpace):
return _convertToStateSpace(sysd) # pragma: no cover

return sysd
84 changes: 45 additions & 39 deletionscontrol/iosys.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,12 +38,15 @@

from .statesp import StateSpace, tf2ss
from .timeresp import _check_convert_array
from .lti import isctime, isdtime, _find_timebase
from .lti import isctime, isdtime, common_timebase
from . import config

__all__ = ['InputOutputSystem', 'LinearIOSystem', 'NonlinearIOSystem',
'InterconnectedSystem', 'input_output_response', 'find_eqpt',
'linearize', 'ss2io', 'tf2io']

# Define module default parameter values
_iosys_defaults = {}

class InputOutputSystem(object):
"""A class for representing input/output systems.
Expand All@@ -69,9 +72,11 @@ class for a set of subclasses that are used to implement specific
states : int, list of str, or None
Description of the system states. Same format as `inputs`.
dt : None, True or float, optional
System timebase. None (default) indicates continuous time, True
indicates discrete time with undefined sampling time, positive number
is discrete time with specified sampling time.
System timebase. 0 (default) indicates continuous
time, True indicates discrete time with unspecified sampling
time, positive number is discrete time with specified
sampling time, None indicates unspecified timebase (either
continuous or discrete time).
params : dict, optional
Parameter values for the systems. Passed to the evaluation functions
for the system as default values, overriding internal defaults.
Expand All@@ -87,9 +92,11 @@ class for a set of subclasses that are used to implement specific
Dictionary of signal names for the inputs, outputs and states and the
index of the corresponding array
dt : None, True or float
System timebase. None (default) indicates continuous time, True
indicates discrete time with undefined sampling time, positive number
is discrete time with specified sampling time.
System timebase. 0 (default) indicates continuous
time, True indicates discrete time with unspecified sampling
time, positive number is discrete time with specified
sampling time, None indicates unspecified timebase (either
continuous or discrete time).
params : dict, optional
Parameter values for the systems. Passed to the evaluation functions
for the system as default values, overriding internal defaults.
Expand DownExpand Up@@ -118,7 +125,7 @@ def name_or_default(self, name=None):
return name

def __init__(self, inputs=None, outputs=None, states=None, params={},
dt=None,name=None):
name=None,**kwargs):
"""Create an input/output system.

The InputOutputSystem contructor is used to create an input/output
Expand All@@ -143,10 +150,11 @@ def __init__(self, inputs=None, outputs=None, states=None, params={},
states : int, list of str, or None
Description of the system states. Same format as `inputs`.
dt : None, True or float, optional
System timebase. None (default) indicates continuous
time, True indicates discrete time withundefined sampling
System timebase.0 (default) indicates continuous
time, True indicates discrete time withunspecified sampling
time, positive number is discrete time with specified
sampling time.
sampling time, None indicates unspecified timebase (either
continuous or discrete time).
params : dict, optional
Parameter values for the systems. Passed to the evaluation
functions for the system as default values, overriding internal
Expand All@@ -162,9 +170,13 @@ def __init__(self, inputs=None, outputs=None, states=None, params={},

"""
# Store the input arguments
self.params = params.copy() # default parameters
self.dt = dt # timebase
self.name = self.name_or_default(name) # system name

# default parameters
self.params = params.copy()
# timebase
self.dt = kwargs.get('dt', config.defaults['control.default_dt'])
# system name
self.name = self.name_or_default(name)

# Parse and store the number of inputs, outputs, and states
self.set_inputs(inputs)
Expand DownExpand Up@@ -210,9 +222,7 @@ def __mul__(sys2, sys1):
"inputs and outputs")

# Make sure timebase are compatible
dt = _find_timebase(sys1, sys2)
if dt is False:
raise ValueError("System timebases are not compabile")
dt = common_timebase(sys1.dt, sys2.dt)

inplist = [(0,i) for i in range(sys1.ninputs)]
outlist = [(1,i) for i in range(sys2.noutputs)]
Expand DownExpand Up@@ -464,12 +474,11 @@ def feedback(self, other=1, sign=-1, params={}):
"inputs and outputs")

# Make sure timebases are compatible
dt = _find_timebase(self, other)
if dt is False:
raise ValueError("System timebases are not compabile")
dt = common_timebase(self.dt, other.dt)

inplist = [(0,i) for i in range(self.ninputs)]
outlist = [(0,i) for i in range(self.noutputs)]

# Return the series interconnection between the systems
newsys = InterconnectedSystem((self, other), inplist=inplist, outlist=outlist,
params=params, dt=dt)
Expand DownExpand Up@@ -580,10 +589,11 @@ def __init__(self, linsys, inputs=None, outputs=None, states=None,
states : int, list of str, or None, optional
Description of the system states. Same format as `inputs`.
dt : None, True or float, optional
System timebase. None (default) indicates continuous
time, True indicates discrete time withundefined sampling
System timebase.0 (default) indicates continuous
time, True indicates discrete time withunspecified sampling
time, positive number is discrete time with specified
sampling time.
sampling time, None indicates unspecified timebase (either
continuous or discrete time).
params : dict, optional
Parameter values for the systems. Passed to the evaluation
functions for the system as default values, overriding internal
Expand DownExpand Up@@ -650,7 +660,8 @@ class NonlinearIOSystem(InputOutputSystem):

"""
def __init__(self, updfcn, outfcn=None, inputs=None, outputs=None,
states=None, params={}, dt=None, name=None):
states=None, params={},
name=None, **kwargs):
"""Create a nonlinear I/O system given update and output functions.

Creates an `InputOutputSystem` for a nonlinear system by specifying a
Expand DownExpand Up@@ -702,10 +713,10 @@ def __init__(self, updfcn, outfcn=None, inputs=None, outputs=None,
operating in continuous or discrete time. It can have the
following values:

* dt =None No timebase specified
* dt= 0 Continuous time system
* dt> 0 Discretetimesystemwith samplingtime dt
* dt =True Discrete time with unspecified sampling time
* dt =0: continuous time system (default)
* dt> 0: discrete time system with sampling period 'dt'
* dt= True: discretetime withunspecifiedsamplingperiod
* dt =None: no timebase specified

name : string, optional
System name (used for specifying signals). If unspecified, a generic
Expand All@@ -722,6 +733,7 @@ def __init__(self, updfcn, outfcn=None, inputs=None, outputs=None,
self.outfcn = outfcn

# Initialize the rest of the structure
dt = kwargs.get('dt', config.defaults['control.default_dt'])
super(NonlinearIOSystem, self).__init__(
inputs=inputs, outputs=outputs, states=states,
params=params, dt=dt, name=name
Expand DownExpand Up@@ -871,10 +883,10 @@ def __init__(self, syslist, connections=[], inplist=[], outlist=[],
operating in continuous or discrete time. It can have the
following values:

* dt =None No timebase specified
* dt= 0 Continuous time system
* dt> 0 Discretetimesystemwith samplingtime dt
* dt =True Discrete time with unspecified sampling time
* dt =0: continuous time system (default)
* dt> 0: discrete time system with sampling period 'dt'
* dt= True: discretetime withunspecifiedsamplingperiod
* dt =None: no timebase specified

name : string, optional
System name (used for specifying signals). If unspecified, a generic
Expand All@@ -888,20 +900,14 @@ def __init__(self, syslist, connections=[], inplist=[], outlist=[],
# Check to make sure all systems are consistent
self.syslist = syslist
self.syslist_index = {}
dt = None
nstates = 0; self.state_offset = []
ninputs = 0; self.input_offset = []
noutputs = 0; self.output_offset = []
sysobj_name_dct = {}
sysname_count_dct = {}
for sysidx, sys in enumerate(syslist):
# Make sure time bases are consistent
# TODO: Use lti._find_timebase() instead?
if dt is None and sys.dt is not None:
# Timebase was not specified; set to match this system
dt = sys.dt
elif dt != sys.dt:
raise TypeError("System timebases are not compatible")
dt = common_timebase(dt, sys.dt)

# Make sure number of inputs, outputs, states is given
if sys.ninputs is None or sys.noutputs is None or \
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp