Changing parameters at runtime in Matlab

Hi,

I use the Matlab interface and have some questions

  1. I want to change some parameters between the calls of “ocp.solve()”. This works fine with e.g. “ocp.set(‘constr_lbu’, lbu)”, but when I try “ocp.set(‘constr_lbx’, 123)” (the same happens with ‘constr_ubx’) I get the following error:

Error using ocp_set
ocp_set: error setting constr_lbx, wrong dimension, got 1, need 4

I have 4 states and 1 inequality constraint, so setting ‘constr_lbx’ to scalar values should be fine (the scalar constraint I set during code generation works). Strangely enough, if I try “ocp.set(‘constr_lbx’, [1; 1; 1; 1])” the error changes to

Error using ocp_set
ocp_set: error setting constr_lbx, wrong dimension, got 4, need 1

  1. My second issue is that calling “ocp.set(‘cost_zu’, zu)” at runtime crashes Matlab. I get the following error on the terminal:

error: ocp_nlp_dims_get_from_attr: field ns not available

I set the fields “dim_ns” and “cost_zu” during code generation without any errors. Do you have an idea what the problem is?

BR
Martin

Hi Martin,

first of all, welcome to the forum! :wave:

The setter can be called in two ways, for all fields, where I use ‘p’ as an example:

    ocp.set('p', p_val );

This will try to set the parameters p to p_val for all stages of the ocp.

    ocp.set('p', p_val, stage);

This will try to set the parameters p to p_val just for the stage with index stage (0 based indexing) of the ocp.
I tried to document this in the example here:

  1. Probably you have an initial condition for x0, which is implemented through lbx, ubx at stage 0 internally. If you want to set the value for the other stages, do something like:
for i:1:N % or N-1
ocp.set(‘constr_lbx’, value, i)
end
  1. I can confirm there was a bug when updating slack penalties from Matlab.
    I just pushed a fix to the master, see:
    Quick fixes by FreyJo · Pull Request #580 · acados/acados · GitHub
    Note, that you will have to recompile both acados and its Matlab interface.

Cheers,
Jonathan

Hi Jonathan,

thanks for your help, now everything works.

BR
Martin