8000 set default for gainsched_indices to xd + add unit test · python-control/python-control@51f3b6b · GitHub
[go: up one dir, main page]

Skip to content

Commit 51f3b6b

Browse files
committed
set default for gainsched_indices to xd + add unit test
1 parent 0bfe921 commit 51f3b6b

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

control/statefbk.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ def create_statefbk_iosystem(
679679
the system state x (or state estimate xhat, if an estimator is
680680
given). The indices can either be specified as integer offsets into
681681
the input vector or as strings matching the signal names of the
682-
input vector.
682+
input vector. The default is to use the desire state xd.
683683
684684
gainsched_method : str, optional
685685
The method to use for gain scheduling. Possible values are 'linear'
@@ -812,8 +812,8 @@ def create_statefbk_iosystem(
812812

813813
# Process gainscheduling variables, if present
814814
if gainsched:
815-
# Create a copy of the scheduling variable indices (default = empty)
816-
gainsched_indices = [] if gainsched_indices is None \
815+
# Create a copy of the scheduling variable indices (default = xd)
816+
gainsched_indices = range(sys.nstates) if gainsched_indices is None \
817817
else list(gainsched_indices)
818818

819819
# Make sure the scheduling variable indices are the right length

control/tests/statefbk_test.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,33 @@ def test_gainsched_unicycle(unicycle, method):
905905
np.testing.assert_allclose(
906906
resp.states[:, -1], Xd[:, -1], atol=1e-2, rtol=1e-2)
907907

908+
909+
def test_gainsched_default_indices():
910+
# Define a linear system to test
911+
sys = ct.ss([[-1, 0.1], [0, -2]], [[0], [1]], np.eye(2), 0)
912+
913+
# Define gains at origin + corners of unit cube
914+
points = [[0, 0]] + list(itertools.product([-1, 1], [-1, 1]))
915+
916+
# Define gain to be constant
917+
K, _, _ = ct.lqr(sys, np.eye(sys.nstates), np.eye(sys.ninputs))
918+
gains = [K for p in points]
919+
920+
# Define the paramters for the simulations
921+
timepts = np.linspace(0, 10, 100)
922+
X0 = np.ones(sys.nstates) * 0.9
923+
924+
# Create a controller and simulate the initial response
925+
gs_ctrl, gs_clsys = ct.create_statefbk_iosystem(sys, (gains, points))
926+
gs_resp = ct.input_output_response(gs_clsys, timepts, 0, X0)
927+
928+
# Verify that we get the same result as a constant gain
929+
ck_clsys = ct.ss(sys.A - sys.B @ K, sys.B, sys.C, 0)
930+
ck_resp = ct.input_output_response(ck_clsys, timepts, 0, X0)
931+
932+
np.testing.assert_allclose(gs_resp.states, ck_resp.states)
933+
934+
908935
def test_gainsched_errors(unicycle):
909936
# Set up gain schedule (same as previous test)
910937
speeds = [1, 5, 10]

0 commit comments

Comments
 (0)
0