Embedded Application of acados without dynamic memory allocation

Hi everyone,

I am currently using the acados MATLAB interface to formulate my optimal control problem. Then, I use the ocp.generate_c_code function to generate the corresponding solver in C-code.
Solving my OCPs in a closed-loop manner in Simulink works well with the S-function provided by acados.
Now, I want to use the generated C-code to implement my control on an embedded system (TI TMS320F280049C). However, this leads to the following issues for me:

The Microcontroller I want to use contains two seperately working cores. One of them is desired to conduct mathematical operations very efficiently. Therefore, it would be really beneficial if I could use this core to perform my control. However, this core is not capable of handling dynamic memory allocation. The main CPU on the other hand is able to do so. This leads to my question: Is it possible for me to outsoure the computational part of the generated C-code such that I can run this part of the code on the mathematically efficient core?

Would it otherwise be possible to convert all of the dynamical memory allocations into static ones? Do you have any experience dealing with cores that are not capable of handling dynamic memory and what would you suggest?

Let me know if there is any further information you need to help me out and thanks for your help.

Best regards

Hi Leon,

Welcome to the forum!

This is in general possible, but will require some work.
I want to refer to Section 4 of the latest acados publication would.

I think the generated file acados_solver_<model_name>.c is a good place to start.
You would need to get rid of the mallocs / callocs in there and the ones in the acados C interface, i.e. the file ocp_nlp_interface.c, and provide the memory differently.

Maybe you come up with a way to do this a bit more general, i.e. add a templated function that computes all the memory here acados/acados_solver.in.c at master · acados/acados · GitHub
It would be cool to be more flexible in this sense, and a PR would be welcome.

Also this might be helpful Developer Guide — acados documentation