8000 Merge pull request #1111 from roryyorke/gh1110-solve_flat_ocp · python-control/python-control@2cb0520 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2cb0520

Browse files
authored
Merge pull request #1111 from roryyorke/gh1110-solve_flat_ocp
Handle scalar `timeresp` in `solve_flat_ocp`
2 parents 92bd703 + a05b9d5 commit 2cb0520

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

control/flatsys/flatsys.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,7 @@ def solve_flat_ocp(
721721

722722
# Process final time
723723
timepts = np.atleast_1d(timepts)
724-
Tf = timepts[-1]
725-
T0 = timepts[0] if len(timepts) > 1 else T0
724+
T0 = timepts[0] if len(timepts) > 1 else 0
726725

727726
# Process keyword arguments
728727
if trajectory_constraints is None:

control/tests/flatsys_test.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,29 @@ def test_flat_solve_ocp(self, basis):
452452
np.testing.assert_almost_equal(x_const, x_nlconst)
453453
np.testing.assert_almost_equal(u_const, u_nlconst)
454454

455+
def test_solve_flat_ocp_scalar_timepts(self):
456+
# scalar timepts gives expected result
457+
f = fs.LinearFlatSystem(ct.ss(ct.tf([1],[1,1])))
458+
459+
def terminal_cost(x, u):
460+
return (x-5).dot(x-5)+u.dot(u)
461+
462+
traj1 = fs.solve_flat_ocp(f, [0, 1], x0=[23],
463+
terminal_cost=terminal_cost)
464+
465+
traj2 = fs.solve_flat_ocp(f, 1, x0=[23],
466+
terminal_cost=terminal_cost)
467+
468+
teval = np.linspace(0, 1, 101)
469+
470+
r1 = traj1.response(teval)
471+
r2 = traj2.response(teval)
472+
473+
np.testing.assert_array_equal(r1.x, r2.x)
474+
np.testing.assert_array_equal(r1.y, r2.y)
475+
np.testing.assert_array_equal(r1.u, r2.u)
476+
477+
455478
def test_bezier_basis(self):
456479
bezier = fs.BezierFamily(4)
457480
time = np.linspace(0, 1, 100)

0 commit comments

Comments
 (0)
0