From 58c1c102894ab281c43bde9e52398f6a6075a35e Mon Sep 17 00:00:00 2001 From: sandmaennchen Date: Wed, 15 Jan 2025 16:33:38 +0100 Subject: [PATCH 1/3] use flat setter to update state bounds --- .../formulate_double_integrator_ocp.m | 4 ++++ .../formulate_single_integrator_ocp.m | 8 ++++++++ .../mocp_transition_example/main_multiphase_ocp.m | 10 ++++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) 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 5ee4afb58b..978974958b 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,10 @@ ocp.constraints.ubu = [u_max]; ocp.constraints.idxbu = [0]; + ocp.constraints.lbx = [-100, -10]; + ocp.constraints.ubx = [100, 10]; + ocp.constraints.idxbx = [0, 1]; + 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 ccc65fead9..b71fa5d899 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,14 @@ ocp.constraints.ubu = [u_max]; ocp.constraints.idxbu = [0]; + 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]; + ocp.constraints.x0 = settings.X0(1); end 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 4969dd2130..ec8b97a485 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,19 @@ ocp_solver = AcadosOcpSolver(ocp); +x0 = ocp.constraints{1}.x0; % 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 onx as this again overwrites lbx_0 +ocp_solver.set('constr_x0', x0); + ocp_solver.solve(); ocp_solver.print(); From 5068f05816094b7be9363fd5e0ffbfc374af78b1 Mon Sep 17 00:00:00 2001 From: sandmaennchen Date: Wed, 15 Jan 2025 16:53:49 +0100 Subject: [PATCH 2/3] add flag to fix simulink --- .../formulate_double_integrator_ocp.m | 8 +++++--- .../formulate_single_integrator_ocp.m | 14 ++++++++------ .../mocp_transition_example/get_example_settings.m | 1 + .../mocp_transition_example/main_mocp_simulink.m | 1 + 4 files changed, 15 insertions(+), 9 deletions(-) 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 978974958b..2c19f50311 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,9 +48,11 @@ ocp.constraints.ubu = [u_max]; ocp.constraints.idxbu = [0]; - ocp.constraints.lbx = [-100, -10]; - ocp.constraints.ubx = [100, 10]; - ocp.constraints.idxbx = [0, 1]; + 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; 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 b71fa5d899..20603e2bc4 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,13 +48,15 @@ ocp.constraints.ubu = [u_max]; ocp.constraints.idxbu = [0]; - ocp.constraints.lbx = [-100]; - ocp.constraints.ubx = [100]; - ocp.constraints.idxbx = [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]; + 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 fb163c029f..5c8dfdeac5 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 ee58f555a1..53844faf5e 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); From 206b56c1a38f067a2f50291b56f5dc0010aec086 Mon Sep 17 00:00:00 2001 From: sandmaennchen Date: Wed, 15 Jan 2025 17:16:36 +0100 Subject: [PATCH 3/3] cleanup --- .../mocp_transition_example/main_multiphase_ocp.m | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 ec8b97a485..ebcbfc00a1 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,9 +74,8 @@ ocp_solver = AcadosOcpSolver(ocp); -x0 = ocp.constraints{1}.x0; - % 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); @@ -84,7 +83,7 @@ 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 onx as this again overwrites lbx_0 +% 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();