8000 allow default linearized system name to be customized · python-control/python-control@14fc96e · GitHub
[go: up one dir, main page]

Skip to content

Commit 14fc96e

Browse files
committed
allow default linearized system name to be customized
1 parent 4f04f48 commit 14fc96e

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

control/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ def use_legacy_defaults(version):
222222
# changed iosys naming conventions
223223
set_defaults('iosys', state_name_delim='.',
224224
duplicate_system_name_prefix='copy of ',
225-
duplicate_system_name_suffix='')
225+
duplicate_system_name_suffix='',
226+
linearized_system_name_prefix='',
227+
linearized_system_name_suffix='_linearized')
226228

227229
return (major, minor, patch)

control/iosys.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@
4949
_iosys_defaults = {
5050
'iosys.state_name_delim': '_',
5151
'iosys.duplicate_system_name_prefix': '',
52-
'iosys.duplicate_system_name_suffix': '$copy'
52+
'iosys.duplicate_system_name_suffix': '$copy',
53+
'iosys.linearized_system_name_prefix': '',
54+
'iosys.linearized_system_name_suffix': '$linearized'
5355
}
5456

5557

@@ -570,7 +572,10 @@ def linearize(self, x0, u0, t=0, params={}, eps=1e-6,
570572
# Set the names the system, inputs, outputs, and states
571573
if copy:
572574
if name is None:
573-
linsys.name = self.name + "_linearized"
575+
linsys.name = \
576+
config.defaults['iosys.linearized_system_name_prefix'] + \
577+
self.name + \
578+
config.defaults['iosys.linearized_system_name_suffix']
574579
linsys.ninputs, linsys.input_index = self.ninputs, \
575580
self.input_index.copy()
576581
linsys.noutputs, linsys.output_index = \
@@ -1781,9 +1786,13 @@ def linearize(sys, xeq, ueq=[], t=0, params={}, **kw):
17811786
the system name is set to the input system name with the string
17821787
'_linearized' appended.
17831788
name : string, optional
1784-
Set the name of the linearized system. If not specified and if `copy`
1785-
is `False`, a generic name <sys[id]> is generated with a unique
1786-
integer id.
1789+
Set the name of the linearized system. If not specified and
1790+
if `copy` is `False`, a generic name <sys[id]> is generated
1791+
with a unique integer id. If `copy` is `True`, the new system
1792+
name is determined by adding the prefix and suffix strings in
1793+
config.defaults['iosys.linearized_system_name_prefix'] and
1794+
config.defaults['iosys.linearized_system_name_suffix'], with the
1795+
default being to add the suffix '$linearized'.
17871796
17881797
Returns
17891798
-------
@@ -1967,6 +1976,13 @@ def interconnect(syslist, connections=[], inplist=[], outlist=[],
19671976
19681977
Notes
19691978
-----
1979+
If a system is duplicated in the list of systems to be connected,
1980+
a warning is generated a copy of the system is created with the
1981+
name of the new system determined by adding the prefix and suffix
1982+
strings in config.defaults['iosys.linearized_system_name_prefix']
1983+
and config.defaults['iosys.linearized_system_name_suffix'], with the
1984+
default being to add the suffix '$copy'$ to the system name.
1985+
19701986
It is possible to replace lists in most of arguments with tuples instead,
19711987
but strictly speaking the only use of tuples should be in the
19721988
specification of an input- or output-signal via the tuple notation
@@ -1977,7 +1993,7 @@ def interconnect(syslist, connections=[], inplist=[], outlist=[],
19771993
In addition to its use for general nonlinear I/O systems, the
19781994
:func:`~control.interconnect` function allows linear systems to be
19791995
interconnected using named signals (compared with the
1980-
:func:`~control.connect` function, which uses signal indicies) and to be
1996+
:func:`~control.connect` function, which uses signal indices) and to be
19811997
treated as both a :class:`~control.StateSpace` system as well as an
19821998
:class:`~control.InputOutputSystem`.
19831999

control/tests/iosys_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,13 @@ def test_linearize_named_signals(self, kincar):
218218
assert linearized.find_state('theta') == 2
219219

220220
# If we copy signal names w/out a system name, append '_linearized'
221+
ct.use_legacy_defaults('0.8.4')
221222
linearized = kincar.linearize([0, 0, 0], [0, 0], copy=True)
222223
assert linearized.name == kincar.name + '_linearized'
224+
ct.use_legacy_defaults('0.9.0')
225+
linearized = kincar.linearize([0, 0, 0], [0, 0], copy=True)
226+
assert linearized.name == kincar.name + '$linearized'
227+
ct.reset_defaults()
223228

224229
# If copy is False, signal names should not be copied
225230
lin_nocopy = kincar.linearize(0, 0, copy=False)

0 commit comments

Comments
 (0)
0