[DS1403 (dSpace MABX3)] Calling out for help from anyone who has successfully deployed an ACADOS s-Function on DS1403 (dSpace MABX3)!

Hi :wave:

I have been working to deploy my MPC controller onto dSpace MicroAutoBox3. All went well until I finally tried to ‘Go Online’ with my model on ControlDesk.
ControlDesk crashes with error saying it failed to load the .rta file.

I am starting to wonder if deploying ACADOS s-Funtion on dSpace MircoAutoBox3 (DS1403) is possible at the first place, eventhough the documentation mentions on succeeding to do so.

So, I am calling out for any piece of wisdom out there in the community from anybody who had any success in running ACADOS s-Function on dSpace MircoAutoBox3 (DS1403)

I am open to all related discussions on this topic.

Thank you

SJ

1 Like

Hi SJ,

I successfully deplayed an ACADOS s-function onto a dSPACE MABIII.

With some minor modifications the ACADOS Embedded Workflow for dSPACE DS1401 and DS1403 works fine.

I only needed to modify the Toolchain-dSpaceDS1403.cmake file as follows:

  • Change the paths in line: 5, 6, 7, 10, 12, 14 and 17
  • In line: 26, 27, 53 and 54 the -J needs to be replaced with -I

Does the build and download process in ConfigurationDesk runs successfully?

Best regards

Jannis

I am thrilled that you have reached out to me! Thank you!

Yes, the build process in ConfigurationDesk has been successful all along. But the issue happens when I try to “Go Online” in ControlDesk. It always seem to fail while it tries to load the .rta file. Am I missing something?

Same as you I made the modifications you mentioned. Below is my toolchain.cmake file for reference. It will be helpful if you can provide your toolchain.cmake file too. It needs to be noted that i had to change the commad to

cmake -G “Unix Makefiles” -DCMAKE_TOOLCHAIN_FILE=“…/cmake/Toolchain-dSpaceDS1403.cmake” -DCMAKE_INSTALL_PREFIX=install …/

did you have to do this as well?

SET(CMAKE_SYSTEM_NAME "dSpaceDS1403")
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
set(CMAKE_SYSTEM_PROCESSOR "arm")

file(TO_CMAKE_PATH "C:/Users/USRG_SJ/Documents/acados/buildDS1403/dSPACE_RCPHIL_2023-A/" DSPACE_TOOLS)
set(DSPACE_RTLIB "${DSPACE_TOOLS}/DS1401/RTLib")
set(DSPACE_COMPILER "${DSPACE_TOOLS}/Compiler/Linux_4.14_GCC_10.3/target/arm-linux-gnueabihf")

# C Compiler
find_program(CMAKE_C_COMPILER NAMES ${DSPACE_COMPILER}/bin/arm-linux-gnueabihf-gcc.exe)
# C++ Compiler -- not used
find_program(CMAKE_CXX_COMPILER NAMES ${DSPACE_COMPILER}/bin/arm-linux-gnueabihf-gcc.exe)
# Assembler
find_program(CMAKE_ASM_COMPILER NAMES ${DSPACE_COMPILER}/bin/arm-linux-gnueabihf-as.exe)
set(CMAKE_RANLIB ":")

find_program(CMAKE_MAKE_PROGRAM NAMES "${DSPACE_TOOLS}/Exe/DSMAKE.exe")

SET(CMAKE_FIND_ROOT_PATH ${DSPACE_COMPILER})
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)


# Compiler flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I${DSPACE_RTLIB}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I${DSPACE_RTLIB}")
set(CMAKE_C_FLAGS "-D_INLINE" CACHE STRING "" FORCE)

# acados flags
set(BLASFEO_TARGET "GENERIC" CACHE STRING "BLASFEO Target architecture")
set(HPIPM_TARGET "GENERIC" CACHE STRING "HPIPM Target architecture")
set(BUILD_SHARED_LIBS OFF CACHE STRING "Build shared libraries")
set(BLASFEO_EXAMPLES OFF CACHE BOOL "Examples disabled")
set(EXT_DEP OFF CACHE BOOL "Compile external dependencies in BLASFEO")
set(ACADOS_INSTALL_DIR "install" CACHE PATH  "Installation path to ACADOS_INSTALL_DIR")


# import from platform folder
set(CMAKE_IMPORT_LIBRARY_PREFIX "")
set(CMAKE_SHARED_LIBRARY_PREFIX "")
set(CMAKE_SHARED_MODULE_PREFIX  "")
set(CMAKE_STATIC_LIBRARY_PREFIX "")

# set(CMAKE_EXECUTABLE_SUFFIX     ".exe")
# set(CMAKE_IMPORT_LIBRARY_SUFFIX ".lib")
# set(CMAKE_SHARED_LIBRARY_SUFFIX ".lib")
# set(CMAKE_SHARED_MODULE_SUFFIX  ".lib")
# set(CMAKE_STATIC_LIBRARY_SUFFIX ".lib")

# GCC-compatible file suffixes
set(CMAKE_EXECUTABLE_SUFFIX     "")      # No .exe on embedded Linux
set(CMAKE_IMPORT_LIBRARY_SUFFIX ".a")
set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
set(CMAKE_SHARED_MODULE_SUFFIX  ".so")
set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")

# set(CMAKE_C_FLAGS "\"-J${DSPACE_RTLIB}\"")

set(CMAKE_INCLUDE_FLAG_C "-I")

Oh, and also a couple of additional questions:

  1. What dSpace products are needed? Is ConfiguationDesk and ControlDesk enough? or do I need to install Real-Time Interface (RTI) as well? (I thought this product only exists for MABX2 compatibility but reading through the toolchain.cmake file made me suspicious that I might need this too) or even some other products as well?
  2. Did you copy the files in dSPACE RCPHIL 2023A into a new folder without blankspace in the name (in my case, dSPACE_RCPHIL_2023-A) as well?

Thank you so much for the help

Best regards,
SJ

Hi SJ,

this is the content of my .CMAKE file:

ET(CMAKE_SYSTEM_NAME "dSpaceDS1403")
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
SET(CMAKE_SYSTEM_PROCESSOR "ppc")

file(TO_CMAKE_PATH "C:/dSPACE_RCPHIL_2024A/" DSPACE_TOOLS) # angepasst
set(DSPACE_RTLIB "C:/dSPACE_RCPHIL_2024A/DS1401/RTLib") # angepasst
set(DSPACE_COMPILER "C:/CFD_Compiler_24.1/target/arm-linux-gnueabihf") # angepasst

# C Compiler
find_program(CMAKE_C_COMPILER NAMES C:/CFD_Compiler_24.1/target/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc.exe) # angepasst
# C++ Compiler -- not used
find_program(CMAKE_CXX_COMPILER NAMES C:/CFD_Compiler_24.1/target/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc.exe) # angepasst
# Assembler
find_program(CMAKE_ASM_COMPILER NAMES C:/CFD_Compiler_24.1/target/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-as.exe) # angepasst
set(CMAKE_RANLIB ":")

find_program(CMAKE_MAKE_PROGRAM NAMES "C:/dSPACE_RCPHIL_2024A/Exe/DSMAKE.exe") # angepasst

SET(CMAKE_FIND_ROOT_PATH ${DSPACE_COMPILER}) 
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)


# Compiler flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -H -I{DSPACE_RTLIB}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -H -I{DSPACE_RTLIB}")
set(CMAKE_C_FLAGS "-D_INLINE" CACHE STRING "" FORCE)

# acados flags
set(BLASFEO_TARGET "GENERIC" CACHE STRING "BLASFEO Target architecture")
set(HPIPM_TARGET "GENERIC" CACHE STRING "HPIPM Target architecture")
set(BUILD_SHARED_LIBS OFF CACHE STRING "Build shared libraries")
set(BLASFEO_EXAMPLES OFF CACHE BOOL "Examples disabled")
set(EXT_DEP OFF CACHE BOOL "Compile external dependencies in BLASFEO")
set(ACADOS_INSTALL_DIR "install" CACHE PATH  "Installation path to ACADOS_INSTALL_DIR")


# import from platform folder
set(CMAKE_IMPORT_LIBRARY_PREFIX "")
set(CMAKE_SHARED_LIBRARY_PREFIX "")
set(CMAKE_SHARED_MODULE_PREFIX  "")
set(CMAKE_STATIC_LIBRARY_PREFIX "")

set(CMAKE_EXECUTABLE_SUFFIX     ".exe")
set(CMAKE_IMPORT_LIBRARY_SUFFIX ".lib")
set(CMAKE_SHARED_LIBRARY_SUFFIX ".lib")
set(CMAKE_SHARED_MODULE_SUFFIX  ".lib")
set(CMAKE_STATIC_LIBRARY_SUFFIX ".lib")

# set(CMAKE_C_FLAGS "\"-I${DSPACE_RTLIB}\"")

set(CMAKE_INCLUDE_FLAG_C "-I")
set(CMAKE_INCLUDE_FLAG_CXX "-I")

# add_definitions(-D__MABX2__)
remove_definitions(-DLINUX)
remove_definitions(-DOS_WINDOWS)
remove_definitions(-D__LINUX__)

I am not sure if you problem is related toacados. Maybe try to build a model without the ACADOS s-function and try to go online in ControlDesk. ControlDesk is just a monitoring software, going online does only mean that the MABIII sends data to you PC.

To answer you questions:

  1. ConfigurationDesk and ControlDeks are enough. You don’t need any additional software
  2. Yes I did the same (see CMAKE file)

Best regards

Jannis

Thank you for the response Jannis.

It seems the only difference in the .cmake file isthe following line:

SET(CMAKE_SYSTEM_PROCESSOR "ppc")

on what grounds did you decide to set complier like this?
I know on the manual it says,
“It is possible to locate the correct compiler path from the Simulink dSPACE build output”
and I thought this meant the build output I get on ConfigurationDesk when I build in ConfigurationDesk, where I get,

Target compiler is "ARMV7-GNU" at "C:\Program Files\dSPACE RCPHIL 2023-A\Compiler\Linux_4.14_GCC_10.3\target\arm-linux-gnueabihf"

I suspect since we are both using MABX3, cmake system processor and the compiler should be same?
Am Iooking at a wrong place?

This is quite weird… I have been using dSpace MABX3 without any issues before I started using Acados in my model. Plus, about the point you made on that ControlDesk is only for monitoring, doesn’t it also serves a role of loading programs on to the MABX3?

Anyways thank you for the input

Best regards,
SJ

So happy to share that I solved the problem!!

After an extensive trial and error over the weekend, for some reason, unlike the “Embedded Workflow” instructions, I found out that, the “Include directories”, “Source files” and “Libraries” settings which is stated that it should be configured in Simulink model configuration parameters, under Code Generation / Custom Code, should actually be removed and the same setting must be configured in ConfigurationDesk under Build / Build Configuration / Default Build Configuration Set / Custom Code instead.

In short,

  1. Remove the “Include directories”, “Source files” and “Libraries” settings in Simulink.
  2. Set those settings in ConfigurationDesk under Build / Build Configuration / Default Build Configuration Set / Custom Code instead.

This may have been because of my lack of knowledge on how dSpace software works, but it seems to be something that has changed in the newer versions of MAB3. I will be glad to hear from any of you who has explanations to add on to this. I hope this helps any of you out there struggling with related issues and I want to thanks Jannis for helping me out.

Best Regards
SJ

1 Like

dSpace Software Version: 2023A
MATLAB Version: 2023A
Host PC OS: Win11

1. Acados Cross-compilation setup

  1. Edit the Toolchain-dSPACEDS1403.cmake file, which is located at 'acados_root_folder'/cmake as following. In this instruction the ‘acados_root_folder’ is C:/acados/

    # From the ConfigurationDesk build results,
    # Target compiler is "ARMV7-GNU" at "C:\Program Files\dSPACE RCPHIL 2023-A\Compiler\Linux_4.14_GCC_10.3\target\arm-linux-gnueabihf"
    
    SET(CMAKE_SYSTEM_NAME "dSpaceDS1403") # edited
    list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
    SET(CMAKE_SYSTEM_PROCESSOR "arm") # edited
    
    file(TO_CMAKE_PATH "C:/acados/buildDS1403/dSPACE_RCPHIL_2023A/" DSPACE_TOOLS) # edited
    set(DSPACE_RTLIB "${DSPACE_TOOLS}/DS1401/RTLib") # edited
    set(DSPACE_COMPILER "${DSPACE_TOOLS}/Compiler/Linux_4.14_GCC_10.3/target/arm-linux-gnueabihf") # edited
    
    # C Compiler
    find_program(CMAKE_C_COMPILER NAMES ${DSPACE_COMPILER}/bin/arm-linux-gnueabihf-gcc.exe)
    # C++ Compiler -- not used
    find_program(CMAKE_CXX_COMPILER NAMES ${DSPACE_COMPILER}/bin/arm-linux-gnueabihf-gcc.exe)
    # Assembler
    find_program(CMAKE_ASM_COMPILER NAMES ${DSPACE_COMPILER}/bin/arm-linux-gnueabihf-as.exe)
    set(CMAKE_RANLIB ":")
    
    find_program(CMAKE_MAKE_PROGRAM NAMES "${DSPACE_TOOLS}/Exe/DSMAKE.exe")
    
    SET(CMAKE_FIND_ROOT_PATH ${DSPACE_COMPILER})
    SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
    SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
    SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
    
    # Compiler flags
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I${DSPACE_RTLIB}") # edited
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I${DSPACE_RTLIB}") # edited
    set(CMAKE_C_FLAGS "-D_INLINE" CACHE STRING "" FORCE)
    
    # acados flags
    set(BLASFEO_TARGET "GENERIC" CACHE STRING "BLASFEO Target architecture")
    set(HPIPM_TARGET "GENERIC" CACHE STRING "HPIPM Target architecture")
    set(BUILD_SHARED_LIBS OFF CACHE STRING "Build shared libraries")
    set(BLASFEO_EXAMPLES OFF CACHE BOOL "Examples disabled")
    set(EXT_DEP OFF CACHE BOOL "Compile external dependencies in BLASFEO")
    set(ACADOS_INSTALL_DIR "install" CACHE PATH  "Installation path to ACADOS_INSTALL_DIR")
    
    # import from platform folder
    set(CMAKE_IMPORT_LIBRARY_PREFIX "")
    set(CMAKE_SHARED_LIBRARY_PREFIX "")
    set(CMAKE_SHARED_MODULE_PREFIX  "")
    set(CMAKE_STATIC_LIBRARY_PREFIX "")
    
    set(CMAKE_EXECUTABLE_SUFFIX     ".exe")
    set(CMAKE_IMPORT_LIBRARY_SUFFIX ".lib")
    set(CMAKE_SHARED_LIBRARY_SUFFIX ".lib")
    set(CMAKE_SHARED_MODULE_SUFFIX  ".lib")
    set(CMAKE_STATIC_LIBRARY_SUFFIX ".lib")
    
    # set(CMAKE_C_FLAGS "\"-J${DSPACE_RTLIB}\"")
    
    set(CMAKE_INCLUDE_FLAG_C "-I") # edited
    set(CMAKE_INCLUDE_FLAG_CXX "-I") # edited
    
    # add_definitions(-D__MABX2__)
    remove_definitions(-DLINUX)
    remove_definitions(-DOS_WINDOWS)
    remove_definitions(-D__LINUX__)
    
  2. In the Acados root folder, create a folder named buildDS1403\, and inside this folder create another folder named dSPACE_RCPHIL_2023A\. The key is not having any white space in its full path. Placing them in buildDS1403\ is only for file managing purposes.

  3. From C:\Program Files\dSPACE RCPHIL 2023-A\ copy the folders Complier\, Exe\, DS1401\ into the newly created 'acados_root_folder'/buildDS1403/dSPACE_RCPHIL_2023A\. If you are missing something, you might have to review your dSpace installations.

  4. Navigate to 'acados_root_folder'\buildDS1403\ and enter the following commands in order to cross-compile and build.

    PS C:\acados\buildDS1403> cmake -D CMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-dSPACEDS1403.cmake -G "Unix Makefiles" -S ../ -B ./
    PS C:\acados\buildDS1403> cmake --build ./
    PS C:\acados\buildDS1403> cmake --install ./
    
  5. After these steps you will have the following

    C:\acados\                                      <-- my acados root folder
    ├── buildDS1403\
    │   └── dSPACE_RCPHIL_2023A\                    <-- You are inside here when running cmake -S ../ -B ./
    │       └── Complier\                           <-- copied from C:\Program Files\dSPACE RCPHIL 2023-A
    │       └── DS1401\                             <-- copied from C:\Program Files\dSPACE RCPHIL 2023-A
    │       └── Exe\                                <-- copied from C:\Program Files\dSPACE RCPHIL 2023-A
    │   └── (build files will be generated here)    <-- You will find the two folders lib and include in buildDS401/install
    

2. Build the S-Function

  1. In your MATLAB working directory, where you have your Simulink model (which is yet to have the Acados s-Function in it), in this example’s case it is C:\MicroAutobox3\Simulation\, create a folder named c_generated_code\.
  2. In the MATLAB working directory, make sure you have the acados_env_variables_windows.m appropriately modified to point the Acados installation path. Run this.
  3. In the MATLAB working directory, create your Acados solver generation scripts and run them to build the s-Function. The build results will be created in the c_generated_code\ folder that we have created before.
  4. within the c_generated_code\ folder, you will the s-Function file has been generated. (The name of the generated s-Function can be found in the output message of the s-Function generation script). Add the generated s-Function in your existing Simulink model using the ‘S-Function’ block.

3. Adding paths used for Custom Code Generation

  1. Search path

    This is same as acados.org “Embedded Workflow”

    "C:\acados\buildDS1403\install\include"
    "C:\acados\buildDS1403\install\include\blasfeo\include"
    "C:\acados\buildDS1403\install\include\hpipm\include"
    
  2. Custom source files

    Recall that in acados.org “Embedded Workflow” , it tells you to source files: all *.c files in your c_generated_code folder. The following is the PowerShell command to obtain a space separated list of all the *.c files in a directory.

    PS C:\MicroAutobox3\Simulation\acados\c_generated_code> 
    (Get-ChildItem -Recurse -Filter *.c | ForEach-Object { $_.FullName -replace '/', '\' }) -join ' '
    

    However, some of the *.c files must be excluded.

    Files to exclude

    C:\MicroAutobox3\Simulation\c_generated_code\acados_mex_create_path_tracking.c 
    C:\MicroAutobox3\Simulation\c_generated_code\acados_mex_free_path_tracking.c 
    C:\MicroAutobox3\Simulation\c_generated_code\acados_mex_set_path_tracking.c 
    C:\MicroAutobox3\Simulation\c_generated_code\acados_mex_solve_path_tracking.c
    
    C:\MicroAutobox3\Simulation\c_generated_code\acados_sim_solver_sfunction_path_tracking.c
    C:\MicroAutobox3\Simulation\c_generated_code\acados_solver_sfunction_path_tracking.c
    
    C:\MicroAutobox3\Simulation\c_generated_code\main_path_tracking.c
    C:\MicroAutobox3\Simulation\c_generated_code\main_sim_path_tracking.c
    C:\MicroAutobox3\Simulation\c_generated_code\CMakeFiles\4.0.1\CompilerIdC\CMakeCCompilerId.c
    

    Which leaves us with,

    files to include

    C:\MicroAutobox3\Simulation\c_generated_code\acados_sim_solver_path_tracking.c
    C:\MicroAutobox3\Simulation\c_generated_code\acados_solver_path_tracking.c
    
    C:\MicroAutobox3\Simulation\c_generated_code\path_tracking_cost\*.c
    C:\MicroAutobox3\Simulation\c_generated_code\path_tracking_model\*.c
    

    or simply, you can use the following PowerShell command to obtain the relevant *.c files in the directory.

    PS C:\MicroAutobox3\Simulation\acados\c_generated_code> 
    (Get-ChildItem -Recurse -Filter *.c | Where-Object { $_.FullName -notmatch "mex|sfunction|main|CMakeCCompilerId" } | ForEach-Object { $_.FullName -replace '/', '\' }) -join ' '
    
  3. Custom libraries

    This is same as acados.org “Embedded Workflow”, except instead of .lib they are .a

    "C:\acados\buildDS1403\install\lib\libacados.a"
    "C:\acados\buildDS1403\install\lib\libblasfeo.a"
    "C:\acados\buildDS1403\install\lib\libhpipm.a"
    

4. Build the project

  1. Now go ahead and build the project using the Build button in ConfigurationDesk.
  2. We are good to go.
1 Like