Deployment on RT-LAB/OPAL-RT

Hi :wave:

I am using ACADOS with Simulink (s-function) for an MPC problem. The ACADOs files run and work very will with Matlab, Simulink Normal run, and Simulink Accelerator run. Next step is to build and run the model on OPAL-RT target machine.

I am encountering this problem which maybe relating to the Linker when the system build in RT-LAB/OPAL-RT system.

========================================================================
-------------------- Building benchmark_mpc_1_sm_model --------------------

  rm -f benchmark_mpc_1_sm_model
  ### Linking ...
  opicpc  -Wl,-rpath='/usr/opalrt/v2024.1.2.43/common/bin' -Wl,'-rpath=/usr/opalrt/v2024.1.2.43/common/bin/x32' -Wl,-rpath='/opt/intel/composerxe/lib/ia32' -Wl,-rpath='/opt/intel/Compiler/11.1/072/lib/ia32' -Wl,-rpath='/opt/intel/Compiler/11.1/056/lib/ia32' -diag-disable remark -L. -L/usr/opalrt/v2024.1.2.43/RT-LAB/lib -L/usr/opalrt/v2024.1.2.43/common/lib -L/usr/opalrt/v2024.1.2.43/common/lib/redhawk -L/usr/opalrt/v2024.1.2.43/common/bin -L/usr/opalrt/v2024.1.2.43/common/bin/x32 -L/usr/opalrt/externals/lib    -o benchmark_mpc_1_sm_model acados_solver_sfunction_PowerSystemBESS.o benchmark_mpc_1_sm_model.o benchmark_mpc_1_sm_model_data.o benchmark_mpc_1_sm_model_offsets.o model_main.o rtGetInf.o rtGetNaN.o rt_logging.o rt_nonfinite.o rt_printf.o rt_sim.o      -lRTLABSimCore -lSimCoreLib -lSyncExchangerLib -lConnectionLib -lConnectionFactoryLib  -lOpalSfunR2023B -lOpalR2023B -lBlocksRT-2023b -ldspR2023B -lsimscapeR2023B -lSimulinkRT-2023b -lOpalRTER2023B -lOpalCore -lOpalCore -lLicenseLib -lSimulink -lSimulationUtilities -lInfrastructure  -lNetwork -lKLU -lNumeric -lFramework -lSystem -lMatio -luuid -lpthread -lRTLABSimCore -lSimCoreLib -lSyncExchangerLib -lConnectionLib -lConnectionFactoryLib -lOpalHttpLicenseRequest -lRapidJSON_Wrapper -lOpalUtils -lOpalAscii -lOpalComm -lOpalConfigFiles -lOpalCPU -lOpalEnv -lOpalFiles -lOpalList -lOpalMemLock -lOpalOSIdentification -lOpalPyTestUtils -lpthread -lm -ldl -lutil -lrt      /usr/matlab/v23.2/rtw/c/libsrc/rtwlibr_redhawk.a 
  acados_solver_sfunction_PowerSystemBESS.o: In function `mdlStart':
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x2): undefined reference to `PowerSystemBESS_acados_create_capsule'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0xa): undefined reference to `PowerSystemBESS_acados_create'
  acados_solver_sfunction_PowerSystemBESS.o: In function `mdlOutputs':
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x3a): undefined reference to `PowerSystemBESS_acados_get_nlp_config'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x45): undefined reference to `PowerSystemBESS_acados_get_nlp_dims'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x52): undefined reference to `PowerSystemBESS_acados_get_nlp_in'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x5d): undefined reference to `PowerSystemBESS_acados_get_nlp_out'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x6d): undefined reference to `PowerSystemBESS_acados_get_nlp_solver'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0xc4): undefined reference to `ocp_nlp_constraints_model_set'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x117): undefined reference to `ocp_nlp_constraints_model_set'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x146): undefined reference to `ocp_nlp_cost_model_set'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x1b9): undefined reference to `ocp_nlp_cost_model_set'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x21c): undefined reference to `ocp_nlp_cost_model_set'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x278): undefined reference to `ocp_nlp_cost_model_set'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x2d4): undefined reference to `ocp_nlp_cost_model_set'
  acados_solver_sfunction_PowerSystemBESS.o:acados_solver_sfunction_PowerSystemBESS.c:(.text+0x333): more undefined references to `ocp_nlp_cost_model_set' follow
  acados_solver_sfunction_PowerSystemBESS.o: In function `mdlOutputs':
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x659): undefined reference to `ocp_nlp_dims_get_from_attr'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x6a2): undefined reference to `ocp_nlp_constraints_model_set'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x6e6): undefined reference to `ocp_nlp_dims_get_from_attr'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x72f): undefined reference to `ocp_nlp_constraints_model_set'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x775): undefined reference to `ocp_nlp_constraints_model_set'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x7a4): undefined reference to `ocp_nlp_constraints_model_set'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x7d3): undefined reference to `ocp_nlp_cost_model_set'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x814): undefined reference to `ocp_nlp_cost_model_set'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x858): undefined reference to `ocp_nlp_cost_model_set'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x883): undefined reference to `PowerSystemBESS_acados_reset'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x8b6): undefined reference to `ocp_nlp_dims_get_from_attr'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x902): undefined reference to `ocp_nlp_out_set'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x922): undefined reference to `PowerSystemBESS_acados_solve'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x939): undefined reference to `ocp_nlp_get'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x966): undefined reference to `ocp_nlp_out_get'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x985): undefined reference to `ocp_nlp_get_all'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x9a4): undefined reference to `ocp_nlp_get_all'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x9db): undefined reference to `ocp_nlp_eval_cost'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0x9ed): undefined reference to `ocp_nlp_get'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0xa08): undefined reference to `ocp_nlp_get'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0xa1d): undefined reference to `ocp_nlp_get'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0xa2f): undefined reference to `ocp_nlp_get'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0xa41): undefined reference to `ocp_nlp_get'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0xa65): undefined reference to `ocp_nlp_out_get'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0xa9d): undefined reference to `ocp_nlp_get'
  acados_solver_sfunction_PowerSystemBESS.o: In function `mdlTerminate':
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0xacb): undefined reference to `PowerSystemBESS_acados_free'
  acados_solver_sfunction_PowerSystemBESS.c:(.text+0xad1): undefined reference to `PowerSystemBESS_acados_free_capsule'
  make: *** [benchmark_mpc_1_sm_model] Error 1
  ??? Error building benchmark_mpc_1_sm_model subsystem.

========================================================================

Anyone know how to solve this? Anyone now how to add the ACADOs lib files to the linker if this is the problem?

Thanks in advance and appreciate your help!

Hi :wave:

the error indeed looks like you are missing the acados core library as well as the solver-specific code.

Did you manage to cross-compile acados for your target system? Did you check the embedded workflow documented here, I guess you will need to follow similar steps.

Hi,

Thank you for highlighting this to me. I will check the page and try to apply the same on OPAL-RT instead of dSPACE if applicable.

Best Regards

Great, let me know how it goes! :rocket: We would be happy to include additional instructions on the docs pages regarding deployment on OPAL-RT.

Hi
I am also running a Simulink model using Acados via an S-function on an OPAL-RT target, and I am currently facing an issue where I cannot load the model onto OPAL-RT, even though I have successfully generated the C code.

I would like to ask whether you have successfully run Acados on an OPAL-RT target. Additionally, how did you use the S-function generated from Acados to run it successfully on OPAL-RT?

Hiep

Hi Hiep

Yes, I successfully deployed it on OPAL-RT, but with a lot of technical help from OPAL-RT people.

  • We needed to compile the ACADOs core libraries to a Linux version compatible with the OPAL-RT target machine operating system. Then the compiled files were moved to the target machines. Also, I needed to move the libraries from the ACADOs folder to the OPAL-RT project folder and link them as detailed below.

  • For the model in RT-Lab, I needed to link the directory of the compiled libraries folder that is on the target to the compiler under the “Variables” tab. Also, under the “File” tab, I needed to add the ACADOs project, compiled C, and other files generated by the ACADOs tool (I was using MATLAB). I needed to add them file by file based on what the OPAL-RT compiler requested, and I had to manually modify some files to include or update the directory paths to the necessary ACADOs libraries or h files I included in the project folder.

  • Regarding the S-function, it is part of the model that I developed in Simulink. You can find examples from ACADOs platform on how to use it in Simulink. Also, when generating the S-function using the tool in MATLAB, it displays a map of the S-function ports in the Command Window.

It worked at the end, and I was able to execute the Model-Predictive-Control Controller on OPAL-RT using ACADOs. If I need to do it again, I will take a different route now. I will keep my system model running in real-time on the OPAL-RT target machine, and I will run the controller I formulated in ACADOs on a more flexible platform, such as a Raspberry Pi or the computer itself, and establish real-time communication between the controller and the target. This is my opinion after my experience.

Please do not hesitate to ask if you have more questions.

Thanks!

Hi

Thank you for you support!

I have followed the suggested approach by copying the libacados.so, libblasfeo.so, libhpipm.so file from ACADOS into OPAL-RT, and I have also added all the required files that OPAL-RT needs, including the compiled C code and other files generated by the ACADOS tool (I am using MATLAB).

However, I am still unable to get my model running on OPAL-RT. I am encountering the following warning:
" Warning: file not found: /home/user/c/users/user_carsim/opal-rt/rt-labv2024.3_workspace/hiep/models/base_model/base_model_sm_carsim/base_model_1_sm_carsim".
It seems that OPAL-RT cannot find the built model.
Could you provide some advice or detailed guidance on how to resolve this issue?
I have attached some images of my model below for reference.




List item:

Log file:
OPAL RT

I look forward to hearing from you soon.
Thank you very much!