Generate (Embedded) Code from a simulink model that includes an ACADOS sfunction

Hi everyone,

first of all: ACADOS is an awesome tool, I have already been using its predecessor ACADO extensively, it is amazing to see how things have progressed.

Now my specific problem: I am using the ACADOS MATLAB interface to generate c-code, including the s-function c-code. Next I compile the s-function and run it as part of a pretty large simulink model (let’s call it “control.slx”) which implements all the algorithms required to control an even larger plant model (let’s call it “plant.slx”). Obviously, I connect “plant.slx” and “control.slx” to simulate the closed loop, which works fine.

Ideally, I could now generate self-contained c-code from the model “control.slx” that I can deploy to embedded platforms. In fact, I did that in the past already, but only with s-functions that I generated using the legacy code tool shipped with MATLAB. As the legacy code tool allows generation of the *.tlc file along with the s-function’s c-code, these s-functions could be inlined and the autogenrated s-function c-code did not appear anywhere in the code to be deployed (neither did “simtruc.h” and other Simulink related code). The ACADOS-generated s-functino however comes without that *.tlc file …

Interestingly, I remember ACADO made use of the legacy code tool, so deployment was pretty much straight forward. In ACADOS, this seems no longer the case. After all, I am missing the *.tlc file that mirrors the s-function c-code. I know it is a pain to write *.tlc files, even Mathworks employees avoid it :smiley:. I am now assessing my options to achieve code-generation with the ACADOS s-function inlined.

Options and Questions:

  1. Use legacy code tool to generate an s-function myself, including the *.tlc file that belongs to it. Are there specific reasons you do not use the legacy code tool but manually implement the s-function for code generation?
  2. Write the *.tlc file myself for the specific s-function I would like to embed.
  3. Write a code generator that writes the *.tlc file equivalent of the automatically generated s-function c-code, depending on the “simulink_opts”.

Any opinions and suggestions that might help?

Best,
Philipp

1 Like

Hi all, FYI: I ended up replicating the autogenerated s-function code in plain C (initialize, step, and terminate functions) and wrapped that code with an s-function using the legacy code tool. The S-Function is now inlined in the generated code, also rapid accelerator mode works (might have worked with the autogenrated s-function as well). Only downside for now is that the plain c implementation has to be coded manually … slows down the iteration cycle a bit.