Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Handle scalar timeresp in solve_flat_ocp #1111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions control/flatsys/flatsys.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,8 +721,7 @@ def solve_flat_ocp(

# Process final time
timepts = np.atleast_1d(timepts)
Tf = timepts[-1]
T0 = timepts[0] if len(timepts) > 1 else T0
T0 = timepts[0] if len(timepts) > 1 else 0

# Process keyword arguments
if trajectory_constraints is None:
Expand Down
23 changes: 23 additions & 0 deletions control/tests/flatsys_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,29 @@ def test_flat_solve_ocp(self, basis):
np.testing.assert_almost_equal(x_const, x_nlconst)
np.testing.assert_almost_equal(u_const, u_nlconst)

def test_solve_flat_ocp_scalar_timepts(self):
# scalar timepts gives expected result
f = fs.LinearFlatSystem(ct.ss(ct.tf([1],[1,1])))

def terminal_cost(x, u):
return (x-5).dot(x-5)+u.dot(u)

traj1 = fs.solve_flat_ocp(f, [0, 1], x0=[23],
terminal_cost=terminal_cost)

traj2 = fs.solve_flat_ocp(f, 1, x0=[23],
terminal_cost=terminal_cost)

teval = np.linspace(0, 1, 101)

r1 = traj1.response(teval)
r2 = traj2.response(teval)

np.testing.assert_array_equal(r1.x, r2.x)
np.testing.assert_array_equal(r1.y, r2.y)
np.testing.assert_array_equal(r1.u, r2.u)


def test_bezier_basis(self):
bezier = fs.BezierFamily(4)
time = np.linspace(0, 1, 100)
Expand Down
Loading