Skip to content

Commit 20177f2

Browse files
committed
add warning if output might not be state in create_statefbk_iosystem
1 parent 1a32831 commit 20177f2

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

control/statefbk.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ def create_statefbk_iosystem(
718718
List of strings that name the individual signals of the transformed
719719
system. If not given, the inputs and outputs are the same as the
720720
original system.
721-
721+
722722
name : string, optional
723723
System name. If unspecified, a generic name <sys[id]> is generated
724724
with a unique integer id.
@@ -750,6 +750,12 @@ def create_statefbk_iosystem(
750750
# TODO: check to make sure output map is the identity
751751
raise ControlArgument("System output must be the full state")
752752
else:
753+
# Issue a warning if we can't verify state output
754+
if (isinstance(sys, NonlinearIOSystem) and sys.outfcn is not None) or \
755+
(isinstance(sys, StateSpace) and
756+
not (np.all(sys.C == np.eye(sys.nstates)) and np.all(sys.D == 0))):
757+
warnings.warn("cannot verify system output is system state")
758+
753759
# Use the system directly instead of an estimator
754760
estimator = sys
755761

control/tests/statefbk_test.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,12 @@ def test_statefbk_errors(self):
754754
sys = ct.rss(4, 4, 2, strictly_proper=True)
755755
K, _, _ = ct.lqr(sys, np.eye(sys.nstates), np.eye(sys.ninputs))
756756

757+
with pytest.warns(UserWarning, match="cannot verify system output"):
758+
ctrl, clsys = ct.create_statefbk_iosystem(sys, K)
759+
760+
# reset the system output
761+
sys.C = np.eye(sys.nstates)
762+
757763
with pytest.raises(ControlArgument, match="must be I/O system"):
758764
sys_tf = ct.tf([1], [1, 1])
759765
ctrl, clsys = ct.create_statefbk_iosystem(sys_tf, K)
@@ -806,11 +812,8 @@ def unicycle():
806812
def unicycle_update(t, x, u, params):
807813
return np.array([np.cos(x[2]) * u[0], np.sin(x[2]) * u[0], u[1]])
808814

809-
def unicycle_output(t, x, u, params):
810-
return x
811-
812815
return ct.NonlinearIOSystem(
813-
unicycle_update, unicycle_output,
816+
unicycle_update, None,
814817
inputs = ['v', 'phi'],
815818
outputs = ['x', 'y', 'theta'],
816819
states = ['x_', 'y_', 'theta_'])

0 commit comments

Comments
 (0)