diff --git a/examples/acados_matlab_octave/mocp_transition_example/formulate_double_integrator_ocp.m b/examples/acados_matlab_octave/mocp_transition_example/formulate_double_integrator_ocp.m index 5ee4afb58..2c19f5031 100644 --- a/examples/acados_matlab_octave/mocp_transition_example/formulate_double_integrator_ocp.m +++ b/examples/acados_matlab_octave/mocp_transition_example/formulate_double_integrator_ocp.m @@ -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 diff --git a/examples/acados_matlab_octave/mocp_transition_example/formulate_single_integrator_ocp.m b/examples/acados_matlab_octave/mocp_transition_example/formulate_single_integrator_ocp.m index ccc65fead..20603e2bc 100644 --- a/examples/acados_matlab_octave/mocp_transition_example/formulate_single_integrator_ocp.m +++ b/examples/acados_matlab_octave/mocp_transition_example/formulate_single_integrator_ocp.m @@ -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 diff --git a/examples/acados_matlab_octave/mocp_transition_example/get_example_settings.m b/examples/acados_matlab_octave/mocp_transition_example/get_example_settings.m index fb163c029..5c8dfdeac 100644 --- a/examples/acados_matlab_octave/mocp_transition_example/get_example_settings.m +++ b/examples/acados_matlab_octave/mocp_transition_example/get_example_settings.m @@ -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 diff --git a/examples/acados_matlab_octave/mocp_transition_example/main_mocp_simulink.m b/examples/acados_matlab_octave/mocp_transition_example/main_mocp_simulink.m index ee58f555a..53844faf5 100644 --- a/examples/acados_matlab_octave/mocp_transition_example/main_mocp_simulink.m +++ b/examples/acados_matlab_octave/mocp_transition_example/main_mocp_simulink.m @@ -29,6 +29,7 @@ settings = get_example_settings(); +settings.WITH_X_BOUNDS = false; N_list = [10, 1, 15]; n_phases = length(N_list); diff --git a/examples/acados_matlab_octave/mocp_transition_example/main_multiphase_ocp.m b/examples/acados_matlab_octave/mocp_transition_example/main_multiphase_ocp.m index 4969dd213..ebcbfc00a 100644 --- a/examples/acados_matlab_octave/mocp_transition_example/main_multiphase_ocp.m +++ b/examples/acados_matlab_octave/mocp_transition_example/main_multiphase_ocp.m @@ -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();