Using S_function in Matlab/Simulink

Hi

My goals are:
1.Run a Simulink model using the S-function
2.Online Change reference y_ref and y_ref_e;
(https://github.com/acados/acados/blob/master/examples/acados_matlab_octave/getting_started/minimal_example_ocp.m)
https://github.com/acados/acados/blob/master/examples/acados_matlab_octave/getting_started/simulink_model_closed_loop.slx
It’s compiled. But,some questions:
1.the Input of the S-function,I cannot match the inputs in minimal_example_ocp.m.
mabe this:
ocp.set(‘init_x’, x_traj_init);
ocp.set(‘init_u’, u_traj_init);
ocp.set(‘init_pi’, zeros(nx, N))

 % change values for specific shooting node using:
 %   ocp.set('field', value, optional: stage_index)
  ocp.set('constr_lbx', x0, 0)

 this  can update x0.
 but y_ref and y_ref_e?, I cannot find how to set.
  1. N = 20,nx = 4 ,nu = 1;but y_ref = zeros(100,1) y_ref_e = zeros(4,1),I cannot understand. I think y_ref = zeros(5,1)?

Thanks a lot,
gaofei

Hi,

Online Change reference y_ref and y_ref_e;

Can be done like here https://github.com/acados/acados/blob/61251bc867d33f233670ac66b5e1dd2765997642/examples/acados_matlab_octave/race_cars/main.m#L260

Please try phrasing your question more clearly.

Cheers,
Jonathan

Thank you for your reply.
The second.

N = 20,nx = 4 ,nu = 2;y_ref = zeros(120,1) ,y_ref_e = zeros(4,1).
But,y_ref = zeros(120,1)? I don’t know how to explain it.

Thanks a lot,
gaofei

The Simulink block input for y_ref contains the y_ref values for all stages (but the terminal one) concatenated, see:

Probably you have ny = 6, N = 20 in the problem you made the screenshot from.

Does this make sense?

Cheers!

@FreyJo. That’s right. N*ny, that’s how I understand it.
But why set this form?
I think we are not concerned about all stages.
Maybe,I just want to set the first stage.

Thanks
gaofei

This gives you the option to change y_ref at all stages, if you don’t want to change them for some stages, just set them to your default y_ref value…

thanks for the positive feedback!
I got it.
in addition,I had get the answers from the old topic.

All my problems have been solved.
Thanks for the amazing work you done!
:wink: :wink: :wink:

Best regards,
Gaofei