8000 fix timebase bug in InterconnectedSystem (issue #754) · steadymingha/python-control@f17c919 · GitHub
[go: up one dir, main page]

Skip to content

Commit f17c919

Browse files
committed
fix timebase bug in InterconnectedSystem (issue python-control#754)
1 parent a73a03d commit f17c919

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

control/iosys.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -871,9 +871,12 @@ def __init__(self, syslist, connections=[], inplist=[], outlist=[],
871871
if not isinstance(outlist, (list, tuple)):
872872
outlist = [outlist]
873873

874-
# Process keyword arguments
874+
# Check if dt argument was given; if not, pull from systems
875+
dt = kwargs.pop('dt', None)
876+
877+
# Process keyword arguments (except dt)
875878
defaults = {'inputs': len(inplist), 'outputs': len(outlist)}
876-
name, inputs, outputs, states, dt = _process_namedio_keywords(
879+
name, inputs, outputs, states, _ = _process_namedio_keywords(
877880
kwargs, defaults, end=True)
878881

879882
# Initialize the system list and index

control/tests/timebase_test.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import pytest
2+
import inspect
3+
import numpy as np
4+
import control as ct
5+
6+
@pytest.mark.parametrize(
7+
"dt1, dt2, dt3", [
8+
(0, 0, 0),
9+
(0, 0.1, ValueError),
10+
(0, None, 0),
11+
(0.1, 0, ValueError),
12+
(0.1, 0.1, 0.1),
13+
(0.1, None, 0.1),
14+
(None, 0, 0),
15+
(None, 0.1, 0.1),
16+
(None, None, None),
17+
(0.2, None, 0.2),
18+
(0.2, 0.1, ValueError),
19+
])
20+
@pytest.mark.parametrize("op", [ct.series, ct.parallel, ct.feedback])
21+
@pytest.mark.parametrize("type", [ct.StateSpace, ct.ss, ct.tf])
22+
def test_composition(dt1, dt2, dt3, op, type):
23+
# Define the system
24+
A, B, C, D = [[1, 1], [0, 1]], [[0], [1]], [[1, 0]], 0
25+
sys1 = ct.StateSpace(A, B, C, D, dt1)
26+
sys2 = ct.StateSpace(A, B, C, D, dt2)
27+
28+
# Convert to the desired form
29+
sys1 = type(sys1)
30+
sys2 = type(sys2)
31+
32+
if inspect.isclass(dt3) and issubclass(dt3, Exception):
33+
with pytest.raises(dt3, match="incompatible timebases"):
34+
sys3 = op(sys1, sys2)
35+
else:
36+
sys3 = op(sys1, sys2)
37+
assert sys3.dt == dt3

0 commit comments

Comments
 (0)
0