Skip to content

Commit

Permalink
MATLAB: check values in idxbx[_0,_e] and idxbu (acados#1390)
Browse files Browse the repository at this point in the history
This PR adds a check for the indices related to simple bounds.

---------

Co-authored-by: Jonathan Frey <[email protected]>
  • Loading branch information
josipkh and FreyJo authored Dec 2, 2024
1 parent dfcc627 commit 09ffc3a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion examples/acados_matlab_octave/linear_mpc/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@
ocp_solver.solve();

% check the solver output
if ocp_solver.get('status') ~= 0
status = ocp_solver.get('status');
if status ~= 0
warning(['acados ocp solver failed with status ',num2str(status)]);
end

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

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


Expand Down
12 changes: 12 additions & 0 deletions interfaces/acados_matlab_octave/AcadosOcp.m
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ function make_consistent(self, is_mocp_phase)
if nbx_0 ~= length(constraints.ubx_0) || nbx_0 ~= length(constraints.idxbx_0)
error('inconsistent dimension nbx_0, regarding idxbx_0, lbx_0, ubx_0.');
end
if min(constraints.idxbx_0) < 0 || max(constraints.idxbx_0) > (dims.nx-1)
error(['idxbx_0 should contain (zero-based) indices between 0 and ', num2str(dims.nx-1)])
end
elseif ~isempty(constraints.idxbx_0) || ~isempty(constraints.lbx_0) || ~isempty(constraints.ubx_0)
error('setting bounds on x: need idxbx_0, lbx_0, ubx_0, at least one missing.');
else
Expand All @@ -281,6 +284,9 @@ function make_consistent(self, is_mocp_phase)
if nbx ~= length(constraints.ubx) || nbx ~= length(constraints.idxbx)
error('inconsistent dimension nbx, regarding idxbx, lbx, ubx.');
end
if min(constraints.idxbx) < 0 || max(constraints.idxbx) > (dims.nx-1)
error(['idxbx should contain (zero-based) indices between 0 and ', num2str(dims.nx-1)])
end
elseif ~isempty(constraints.idxbx) || ~isempty(constraints.lbx) || ~isempty(constraints.ubx)
error('setting bounds on x: need idxbx, lbx, ubx, at least one missing.');
else
Expand All @@ -293,6 +299,9 @@ function make_consistent(self, is_mocp_phase)
if nbu ~= length(constraints.ubu) || nbu ~= length(constraints.idxbu)
error('inconsistent dimension nbu, regarding idxbu, lbu, ubu.');
end
if min(constraints.idxbu) < 0 || max(constraints.idxbu) > (dims.nu-1)
error(['idxbu should contain (zero-based) indices between 0 and ', num2str(dims.nu-1)])
end
elseif ~isempty(constraints.idxbu) || ~isempty(constraints.lbu) || ~isempty(constraints.ubu)
error('setting bounds on u: need idxbu, lbu, ubu, at least one missing.');
else
Expand Down Expand Up @@ -348,6 +357,9 @@ function make_consistent(self, is_mocp_phase)
if nbx_e ~= length(constraints.ubx_e) || nbx_e ~= length(constraints.idxbx_e)
error('inconsistent dimension nbx_e, regarding Jbx_e, lbx_e, ubx_e.');
end
if min(constraints.idxbx_e) < 0 || max(constraints.idxbx_e) > (dims.nx-1)
error(['idxbx_e should contain (zero-based) indices between 0 and ', num2str(dims.nx-1)])
end
elseif ~isempty(constraints.idxbx_e) || ~isempty(constraints.lbx_e) || ~isempty(constraints.ubx_e)
error('setting bounds on x: need Jbx_e, lbx_e, ubx_e, at least one missing.');
else
Expand Down

0 comments on commit 09ffc3a

Please sign in to comment.