Hi
I am new to acados and would like to set up MPC problems in Matlab with constraints, reference, weights, expressions etc that change over time (time dependent, time varying, dynamic).
To explore the possibilities, I first tried to add some changes to the minimal_example_ocp with the pendulum_on_cart_model that was given at github as an example to acados.
I already saw that after setting up the solver, it should be possible to change all those things for specific time steps (“stages”) with:
ocp.set('constr_lbx', lbx_i, i)
So this would change the lower bound for x to the values in lb_x_i for stage i.
And similar one could do this for other bounds, references, expressions.
In the minimal_example_ocp code, there was already this line:
ocp.set('constr_lbx', x0, 0)
This line works fine. In general, if the stage is i=0, setting the lower or upper bound for x for only this stage works (at least it is runnable like this, I did not check if it in this case has an effect).
If using another stage, e.g.
ubx_6=[0.5; inf; inf; inf];
ocp.set('constr_ubx', ubx_6, 6);
this error message appears:
Error using ocp_set
ocp_set: error setting constr_ubx, wrong dimension, got 4, need 0
Error in acados_ocp/set (line 260)
ocp_set(obj.cost_ext_fun_type, obj.cost_ext_fun_type_e, obj.C_ocp, obj.C_ocp_ext_fun, field, value, stage);
Error in minimal_example_ocp (line 129)
ocp.set('constr_ubx', x_bound_step_6, 6);
I do not understand why this happens. Just to try, I also ran:
ocp.set('constr_ubx', [], ubx_6, 6);
to achieve the 0-dimension. Then the code is actually runnable, but I do not see the expected change in the result. To me it seems like nothing has changed by adding this constraint to stage 6.
Another thing I already tried was to change the reference y_ref:
ocp.set('cost_y_ref', [0;1;0;0], 10);
There, I got the error message:
Error using ocp_set
ocp_set: error setting cost_y_ref, wrong dimension, got 4, need 5
Error in acados_ocp/set (line 260)
ocp_set(obj.cost_ext_fun_type, obj.cost_ext_fun_type_e, obj.C_ocp, obj.C_ocp_ext_fun, field, value, stage);
Error in minimal_example_ocp (line 142)
ocp.set('cost_y_ref', [0;1;0;0], 10);
So also here, I just tried to satisfy the dimensions demanded by changing it to:
ocp.set('cost_y_ref', [0;1;0;0;0], 10);
In this case, it again was runnable and even gave the expected result. So this seems to work, I would just like to know why changing the dimensions was necessary and what the additional number exactly means.
The lines written above are the only thing I changed in the public available example.
I added them right after the line
ocp.set('constr_lbx', x0, 0) .
So my questions are:
- First, for this might already solve everything: Is there maybe a documentation I overlooked, which lists the things that can be adjusted for specific stages and how to do this for each of them?
- How do I achieve to change the lower and upper bound of x for a specific ctage i?
- Why does the error message with the dimensions appear?
- For the y_ref case, why is the additional value required and what does it mean?
- Or maybe is there other possibilities to achieve different constraints etc for different stages?
I hope my problem is understandable.
Thank you very much for your help!
Greetings
Sofie