FORCESPRO 6.3
  • Chapter
      • 1. Introduction
      • 2. License Variants
      • 3. Installation
      • 4. Backward Compatibility
      • 5. Y2F Interface
      • 6. MathWorks Linear MPC Plugin
      • 7. MathWorks Nonlinear MPC Plugin
      • 8. Low-level interface
      • 9. High-level Interface
      • 10. Simulating your custom controller in Simulink®
      • 11. Examples
      • 12. Parametric problems
      • 13. Code Deployment
      • 14. Multicore parallelization
      • 15. Licensing
      • 16. Autotuner
      • 17. Solver Options
      • 18. Exitflags
      • 19. Modelling Utilities
      • 20. Dumping Problem Formulation and Data
      • 21. Webcompilers
      • 22. Frequently asked questions

13.2. dSPACE deployment through Simulink Coder¶

  • Platform Specific Configurations

    • Platform name codeoption

    • Simulink Model HW Target Configuration

  • High-level interface

  • Y2F interface

    • Instructions

This process applies to the following dSPACE platforms

  • dSPACE MicroAutoBox II

  • dSPACE AutoBox

  • dSPACE MicroLabBox

Important

When deploying to a target hardware platform, the library included in the lib_target directory of the generated solver should be used instead of the library in the lib directory.

13.2.1. Platform Specific Configurations¶

13.2.1.1. Platform name codeoption¶

When generating code for HW target platforms, codeoptions.platform needs to be set.

  • dSPACE MicroAutoBox II: 'dSPACE-MABII'

  • dSPACE AutoBox: 'dSPACE-AutoBox'

  • dSPACE MicroLabBox: 'dSPACE-MicroLabBox'

13.2.1.2. Simulink Model HW Target Configuration¶

When creating a Simulink Model for HW target platforms, certain hardware options need to be set.

  • Simulink Model Template:

    • dSPACE MicroAutoBox II: RTI1401

    • dSPACE AutoBox: RTI1007

    • dSPACE MicroLabBox: RTI1202

  • System target file:

    • dSPACE MicroAutoBox II: rti1401.tlc

    • dSPACE AutoBox: rti1007.tlc

    • dSPACE MicroLabBox: rti1202.tlc

  • Template makefile:

    • dSPACE MicroAutoBox II: rti1401.tmf

    • dSPACE AutoBox: rti1007.tmf

    • dSPACE MicroLabBox: rti1202.tmf

13.2.2. High-level interface¶

The steps to deploy and simulate a FORCESPRO controller on a dSPACE platform are detailed below.

  1. (Figure 13.1) Set the code generation options (for <platform_name> see Platform name codeoption):

codeoptions.platform = '<platform_name>'; % to specify the platform
codeoptions.printlevel = 0; % on some platforms printing is not supported
codeoptions.cleanup = 0; % to keep necessary files for target compile

and then generate the code for your solver (henceforth referred to as “FORCESNLPsolver”, placed in the folder “BasicExample”) using the high-level interface.

../../_images/ds_coder_high_level_1.png

Figure 13.1 Set the appropriate code generation options.¶

  1. (Figure 13.2) Create a new Simulink model using the Simulink model template provided by dSPACE (for <simulink_model_template> see Simulink Model HW Target Configuration).

  2. (Figure 13.3) Populate the Simulink model with the system you want to control.

../../_images/ds_coder_high_level_2.png

Figure 13.2 Create a Simulink model.¶

../../_images/ds_coder_high_level_3.png

Figure 13.3 Populate the Simulink model.¶

  1. (Figure 13.4) Make sure the FORCESNLPsolver_simulinkBlock.mexw64 file (created during code generation) is on the MATLAB path.

../../_images/ds_coder_high_level_4.png

Figure 13.4 Add the folder containing the .mexw64 solver file to the MATLAB path.¶

  1. (Figure 13.5) Open the FORCESNLPsolver_lib.mdl Simulink model file, contained in the interface folder of the FORCESNLPsolver folder created during code generation.

  2. (Figure 13.6) Copy-paste the FORCESPRO Simulink block into your simulation model and connect its inputs and outputs appropriately.

../../_images/ds_coder_high_level_5.png

Figure 13.5 Open the generated Simulink solver model.¶

../../_images/ds_coder_high_level_6.png

Figure 13.6 Copy-paste and connect the FORCESPRO block.¶

  1. (Figure 13.7) Access the Simulink model’s options.

  2. (Figure 13.8) In the “Solver” tab, set the options:

  • Simulation start/stop time: Depending on the simulation wanted.

  • Solver type: Discrete or fixed-step.

  • Fixed-step size: Needs to be higher than the execution time of the solver.

../../_images/ds_coder_high_level_7.png

Figure 13.7 Open the Simulink model options.¶

../../_images/ds_coder_high_level_8.png

Figure 13.8 Set the Simulink solver options.¶

  1. (Figure 13.9) In the “Code Generation” tab, set the options (for <tlc_file> and <makefile_template> see Simulink Model HW Target Configuration):

  • System target file: <tlc_file>

  • Language: C

  • Generate makefile: On

  • Template makefile: <makefile_template>

  • Make command: make_rti

  1. (Figure 13.10) In the “Code Generation/Custom Code” tab, include the directories:

  • BasicExample

  • BasicExample\FORCESNLPsolver\interface

  • BasicExample\FORCESNLPsolver\lib_target

  1. (Figure 13.11) In the “Code Generation/Custom Code” tab, add the source files:

  • FORCESNLPsolver_simulinkBlock.c

  • FORCESNLPsolver_adtool2forces.c

  • FORCESNLPsolver_casadi.c

  1. (Figure 13.12) In the “Code Generation/Custom Code” tab, add the library file:

  • FORCESNLPsolver.lib

../../_images/ds_coder_high_level_9.png

Figure 13.9 Set the Simulink code generation options.¶

../../_images/ds_coder_high_level_10.png

Figure 13.10 Add the directories included for the code generation.¶

../../_images/ds_coder_high_level_11.png

Figure 13.11 Add the source files used for the code generation.¶

../../_images/ds_coder_high_level_12.png

Figure 13.12 Add the libraries used for the code generation.¶

  1. (Figure 13.13) Access the FORCESPRO block’s parameters.

  2. (Figure 13.14) Remove the “FORCESNLPsolver” prefix from the S-function module.

  3. (Figure 13.15) Compile the code of the Simulink model. This will also automatically load the model to the connected dSPACE platform.

../../_images/ds_coder_high_level_13.png

Figure 13.13 Open the FORCESPRO block’s parameters.¶

../../_images/ds_coder_high_level_14.png

Figure 13.14 Remove the leading solver name from the S-function module.¶

  1. Deployment is complete and simulations can now be run on the dSPACE platform.

../../_images/ds_coder_high_level_15.png

Figure 13.15 Compile the code of the Simulink model.¶

13.2.3. Y2F interface¶

13.2.3.1. Instructions¶

The steps to deploy and simulate a FORCESPRO controller on a dSPACE platform are detailed below.

  1. (Figure 13.16) Set the code generation options (for <platform_name> see Platform name codeoption):

codeoptions.platform = '<platform_name>'; % to specify the platform
codeoptions.printlevel = 0; % on some platforms printing is not supported

and then generate the code for your solver (henceforth referred to as “simplempc_solver”, placed in the folder “Y2F”) using the Y2F interface.

../../_images/ds_coder_y2f_1.png

Figure 13.16 Set the appropriate code generation options.¶

  1. (Figure 13.17) Create a new Simulink model using the Simulink model template provided by dSPACE (for <simulink_model_template> see Simulink Model HW Target Configuration).

  2. (Figure 13.18) Populate the Simulink model with the system you want to control.

../../_images/ds_coder_y2f_2.png

Figure 13.17 Create a Simulink model.¶

../../_images/ds_coder_y2f_3.png

Figure 13.18 Populate the Simulink model.¶

  1. (Figure 13.19) Make sure the simplempc_solver_simulinkBlock.mexw64 file (created during code generation) is on the MATLAB path.

../../_images/ds_coder_y2f_4.png

Figure 13.19 Add the folder containing the .mexw64 solver file to the MATLAB path.¶

  1. (Figure 13.20) Copy-paste the FORCESPRO Simulink block, contained in the created y2f_simulink_lib.slx Simulink model file, into your simulation model and connect its inputs and outputs appropriately.

../../_images/ds_coder_y2f_5.png

Figure 13.20 Copy-paste and connect the FORCESPRO block.¶

  1. (Figure 13.21) Access the Simulink model’s options.

  2. (Figure 13.22) In the “Solver” tab, set the options:

  • Simulation start/stop time: Depending on the simulation wanted.

  • Solver type: Discrete or fixed-step.

  • Fixed-step size: Needs to be higher than the execution time of the solver.

../../_images/ds_coder_y2f_6.png

Figure 13.21 Open the Simulink model options.¶

../../_images/ds_coder_y2f_7.png

Figure 13.22 Set the Simulink solver options.¶

  1. (Figure 13.23) In the “Code Generation/RTI general build options” tab, set the options (for <tlc_file> and <makefile_template> see Simulink Model HW Target Configuration):

    • System target file: <tlc_file>

    • Language: C

    • Generate makefile: On

    • Template makefile: <makefile_template>

    • Make command: make_rti

  2. (Figure 13.24) In the “Code Generation/Custom Code” tab, include the directories:

  • Y2F

  • Y2F\simplempc_solver\interface

  • Y2F\simplempc_solver\lib_target

  1. (Figure 13.25) In the “Code Generation/Custom Code” tab, add the source files:

  • simplempc_solver_simulinkBlock.c

  • simplempc_solver.c

  1. (Figure 13.26) In the “Code Generation/Custom Code” tab, add the library files:

  • internal_simplempc_solver_1.lib

../../_images/ds_coder_y2f_8.png

Figure 13.23 Set the Simulink code generation options.¶

../../_images/ds_coder_y2f_9.png

Figure 13.24 Add the directories included for the code generation.¶

../../_images/ds_coder_y2f_10.png

Figure 13.25 Add the source files used for the code generation.¶

../../_images/ds_coder_y2f_11.png

Figure 13.26 Add the libraries used for the code generation.¶

  1. (Figure 13.27) Compile the code of the Simulink model. This will also automatically load the model to the connected dSPACE platform.

  2. Deployment is complete and simulations can now be run on the dSPACE platform.

../../_images/ds_coder_y2f_12.png

Figure 13.27 Compile the code of the Simulink model.¶

Back to top

© Copyright 2023, embotech AG.
Created using Sphinx 5.2.0.