NMPC in Simulink / on dSpace Error: Can't open random_source_files.h

Hi everyone :wave:

I have a nmpc in matlab simulink workign and simulating just fine. Now i want to generate C code to run it on a dSpace board (CP1104).

The problem is that code generation always fails as it can’t find or open some source file.

I tried editing nmpc_cl_stc_v3_HW_usr.mk to include all the folders of the various source files that are reported to be unable to be found or opend, but that just shifts it to another file that can’t be opened or didnt do anything.

I tried to manually add #include “acados/utils/types.h” to the sfunction c code in response to the errors but that led down a rabbit hole adding so many lines to no avail, which will all be automatically erased once i run my
C:\acados_master\examples\acados_matlab_octave\getting_started_stc\simulink_example_stc_v1.m again.

one time it can’t find print.h, then can’t find the declarationof modf from math.h, or not find some function from a hpipm file, now like in this instance types.h in the same folder as math.h.

the error message in Simulink diagnostic viewer always looks like a variation of this:

COMPILING  "nmpc_cl_stc_v3_HW.c"
(F) C0005; "C:\acados_master\acados\utils\math.h", line 41 pos 32; could not open source file "acados/utils/types.h" 
  #include "acados/utils/types.h" 

Did anyone encounter something like this?

Thanks in advance for giving my issue a read

Hi @AaronKLR, could it be that you haven’t added correctly the header paths in nmpc_cl_stc_v3_HW_usr.mk? In my experience using absolute paths in USER_INCLUDES_PATH helps resolving this type of issues. Something like

USER_INCLUDES_PATH = \ "<path_to_install_folder>\include" \ "<path_to_install_folder>\include\blasfeo\include" \ "<path_to_install_folder>\include\hpipm\include" \ "<path_to_install_folder>\include\acados_c" \

should work.

i expected adding the paths like this to the usr.mk would fix the problem too
In fact i always used absolute paths in the usr.mk and just for fancy tried the relative ones as seen in the error message once or twice after looking everywhere and not knowing what could be wrong or done about it.
so my usr.mk looks like this

# Directories where additional C and assembler source files are stored.
USER_SRCS_DIR = "C:\acados_master\acados\examples\acados_matlab_octave\getting_started_stc\c_generated_code" \

# Path names for user include files.
USER_INCLUDES_PATH = "C:\acados_master\acados\examples\acados_matlab_octave\getting_started_stc\c_generated_code" \

or really bloated as i tried to just add all the folder in the acados directory that have a c file in case it is looking for another instance of the file somewhere.

but the persistent “could not open source file” indicate something else as it should mean that it was found but not opened. But i really cant see any reason for this. in my above given example it can find the math.h but not the type.h despite both being in the "C:\acados_master\acados\utils" folder