Skip to content

Commit

Permalink
MATLAB: flat setter example (#1420)
Browse files Browse the repository at this point in the history
Extend MOCP transition example with bounds on `x` and showcase usage of
flat format setters.
  • Loading branch information
sandmaennchen authored Jan 15, 2025
1 parent d0edd56 commit 5aeb773
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
ocp.constraints.ubu = [u_max];
ocp.constraints.idxbu = [0];

if settings.WITH_X_BOUNDS
ocp.constraints.lbx = [-100, -10];
ocp.constraints.ubx = [100, 10];
ocp.constraints.idxbx = [0, 1];
end

ocp.constraints.x0 = settings.X0;

end
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@
ocp.constraints.ubu = [u_max];
ocp.constraints.idxbu = [0];

if settings.WITH_X_BOUNDS
ocp.constraints.lbx = [-100];
ocp.constraints.ubx = [100];
ocp.constraints.idxbx = [0];

ocp.constraints.lbx_e = [-100];
ocp.constraints.ubx_e = [100];
ocp.constraints.idxbx_e = [0];
end

ocp.constraints.x0 = settings.X0(1);
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@
settings.L2_COST_V = 1e-1;
settings.L2_COST_P = 1e0;
settings.L2_COST_A = 1e-3;
settings.WITH_X_BOUNDS = true;
end
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@


settings = get_example_settings();
settings.WITH_X_BOUNDS = false;

N_list = [10, 1, 15];
n_phases = length(N_list);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,18 @@

ocp_solver = AcadosOcpSolver(ocp);


% initialize x trajectory using flattened format
x0 = ocp.constraints{1}.x0;
x_init = [repmat(x0, 1, N_list(1)+N_list(2)) repmat(x0(1), 1, N_list(3)+1)];

ocp_solver.set('x', x_init);

% update state bounds using flattened format
lbx = [repmat([-10, -5], 1, N_list(1)) repmat([-10], 1, N_list(3)+1)];
ocp_solver.set('constr_lbx', lbx);

% need to set initial state after updating the bounds on x as this again overwrites lbx_0
ocp_solver.set('constr_x0', x0);

ocp_solver.solve();
ocp_solver.print();

Expand Down

0 comments on commit 5aeb773

Please sign in to comment.