Setting y_ref for each time step

Hi :wave:

I am trying to implement a reference trajectory y-ref for a linear cost function.

i have defined the following

ocp = acados_ocp(ocp_model,ocp_opts);

for i = 0:N-1
    current_r_ref = [r_ref(:, i+1);0;0]; % Get the reference for the current timestep
    ocp.set('cost_y_ref',i,current_r_ref); % Set the parameter 'p' for timestep 'i-1' (acADOS uses zero indexing)
end

where current_r_ref has the size of ny x 1. But I get the following error.

Error using acados_mex_set_obsRT
ocp_set: field cost_y_ref not supported for cost type 4 at stage -40

Error in obsRT_mex_solver/set (line 89)
                acados_mex_set_obsRT(obj.cost_ext_fun_type, obj.cost_ext_fun_type_e, obj.C_ocp, field, value, stage);

Error in acados_ocp/set (line 243)
            obj.t_ocp.set(field, value, varargin{:});

Error in RT_obs_acados_R1 (line 175)
    ocp.set('cost_y_ref',i,current_r_ref); % Set the parameter 'p' for timestep 'i-1' (acADOS uses zero indexing)
 

Any help appreciated.

Thanks,

Hi,

the Matlab function to do this can be used as:

ocp.set('cost_y_ref', yref, k); % last argument is the stage

This is taken from an example.
So you have the wrong order of arguments.
Cheers!

That worked thanks! Would you happen to know which example?