I am currently working on a project where I need to implement a nonlinear model predictive control (NMPC) using acados in Simulink.
I have set up the model and solver in acados…, but I am struggling with integrating it smoothly into Simulink.
Specifically, I am not sure about the best way to pass the required inputs and retrieve the outputs within the Simulink environment.
Has anyone here successfully connected acados with Simulink: ?? I would appreciate any advice or examples, especially on how to manage the interface between the two platforms.
take a look athe the script simulink_example_advanced in the getting_started folder. I think everything that you need for integration acados in simulink is explained there.
Here a brief description of the overall workflow:
Create an OCP solver like in the minimal_example till line 115.
Set the simulink options by fist getting the simulink options and then setting the input and output ports of the generated s-function, like in the script simulink_example_advanced line 5 to 24.
Navigate into the c_generated_code folder and call make_sfun for creating an s-function of the ocp solver and make_sfun_sim for creating an s-function of the process model of your NMPC (simulink_example_advanced line 35 to 38).
Create a simulink model and import the generated s-function into the model.
Once we have created the S-function, how do we determine what are the inputs and outputs to S-function. It would be great if you could share any documentations.
take a look at the minimal_example_ocp. In line 44 the simulink opts is loaded. You can manipulate it by setting the individual inputs and outputs to 0 or 1 and thereby determine what the inputs and outputs of the s-function are.