8.2. dSPACE MicroAutoBox II

8.2.1. High-level interface

The steps to deploy and simulate a FORCES Pro controller on a dSPACE MicroAutoBox II are detailed below.

  1. (Figure 8.1) Set the code generation options:
codeoptions.platform = 'dSPACE-MABII'; % 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.

  1. (Figure 8.2) Create a new Simulink model using the RTI1401 template provided by dSPACE.
  2. (Figure 8.3) Populate the Simulink model with the system you want to control.
  3. (Figure 8.4) Make sure the FORCESNLPsolver_simulinkBlock.mexw64 file (created during code generation) is on the Matlab path.
  4. (Figure 8.5) Open the FORCESNLPsolver_lib.mdl Simulink model file, contained in the interface folder of the FORCESNLPsolver folder created during code generation.
  5. (Figure 8.6) Copy-paste the FORCES Pro Simulink block into your simulation model and connect its inputs and outputs appropriately.
  6. (Figure 8.7) Access the Simulink model’s options.
  7. (Figure 8.8) In the “Solver” tab, set the options:
  • Simulation start/stop time: Depending on the simulation wanted.
  • Solver type: Discrete or fixed-step (variable-step solvers are not supported by the MicroAutoBox).
  • Fixed-step size: Needs to be higher than the execution time of the solver.
  1. (Figure 8.9) In the “Code Generation” tab, set the options:
  • System target file: rti1401.tlc
  • Language: C
  • Generate makefile: On
  • Template makefile: rti1401.tmf
  • Make command: make_rti
  1. (Figure 8.10) In the “Code Generation/Custom Code” tab, include the directories:
  • BasicExample
  • BasicExample\FORCESNLPsolver\interface
  • BasicExample\FORCESNLPsolver\lib_target
  1. (Figure 8.11) In the “Code Generation/Custom Code” tab, add the source files:
  • FORCESNLPsolver_simulinkBlock.c
  • FORCESNLPsolver_casadi2forces.c
  • FORCESNLPsolver_model_1.c
  • FORCESNLPsolver_model_11.c
  1. (Figure 8.12) In the “Code Generation/Custom Code” tab, add the library files:
  • FORCESNLPsolver.lib
  1. (Figure 8.13) Access the FORCES Pro block’s parameters.
  2. (Figure 8.14) Remove the “FORCESNLPsolver” prefix from the S-function module.
  3. (Figure 8.15) Compile the code of the Simulink model. This will also automatically load the model to the connected MicroAutoBox.
../../_images/dspace_high_level_1.png

Figure 8.1 Set the appropriate code generation options.

../../_images/dspace_high_level_2.png

Figure 8.2 Create a Simulink model.

../../_images/dspace_high_level_3.png

Figure 8.3 Populate the Simulink model.

../../_images/dspace_high_level_4.png

Figure 8.4 Add the folder containing the .mexw64 solver file to the Matlab path.

../../_images/dspace_high_level_5.png

Figure 8.5 Open the generated Simulink solver model.

../../_images/dspace_high_level_6.png

Figure 8.6 Copy-paste and connect the FORCES Pro block.

../../_images/dspace_high_level_7.png

Figure 8.7 Open the Simulink model options.

../../_images/dspace_high_level_8.png

Figure 8.8 Set the Simulink solver options.

../../_images/dspace_high_level_9.png

Figure 8.9 Set the Simulink code generation options.

../../_images/dspace_high_level_10.png

Figure 8.10 Add the directories included for the code generation.

../../_images/dspace_high_level_11.png

Figure 8.11 Add the source files used for the code generation.

../../_images/dspace_high_level_12.png

Figure 8.12 Add the libraries used for the code generation.

../../_images/dspace_high_level_13.png

Figure 8.13 Open the FORCES Pro block’s parameters.

../../_images/dspace_high_level_14.png

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

../../_images/dspace_high_level_15.png

Figure 8.15 Compile the code of the Simulink model.

8.2.2. Y2F interface

The steps to deploy and simulate a FORCES Pro controller on a dSPACE MicroAutoBox II are detailed below.

  1. (Figure 8.16) Set the code generation options:
codeoptions.platform = 'dSPACE-MABII'; % 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.

  1. (Figure 8.17) Create a new Simulink model using the RTI1401 template provided by dSPACE.
  2. (Figure 8.18) Populate the Simulink model with the system you want to control.
  3. (Figure 8.19) Make sure the simplempc_solver_simulinkBlock.mexw64 file (created during code generation) is on the Matlab path.
  4. (Figure 8.20) Copy-paste the FORCES Pro Simulink block, contained in the created y2f_simulink_lib.slx Simulink model file, into your simulation model and connect its inputs and outputs appropriately.
  5. (Figure 8.21) Access the Simulink model’s options.
  6. (Figure 8.22) In the “Solver” tab, set the options:
  • Simulation start/stop time: Depending on the simulation wanted.
  • Solver type: Discrete or fixed-step (variable-step solvers are not supported by the MicroAutoBox).
  • Fixed-step size: Needs to be higher than the execution time of the solver.
  1. (Figure 8.23) In the “Code Generation/RTI general build options” tab, set the options:
  • System target file: rti1401.tlc
  • Language: C
  • Generate makefile: On
  • Template makefile: rti1401.tmf
  • Make command: make_rti
  1. (Figure 8.24) In the “Code Generation/Custom Code” tab, include the directories:
  • Y2F
  • Y2F\simplempc_solver\interface
  • Y2F\simplempc_solver\lib_target
  1. (Figure 8.25) In the “Code Generation/Custom Code” tab, add the source files:
  • simplempc_solver_simulinkBlock.c
  • simplempc_solver.c
  1. (Figure 8.26) In the “Code Generation/Custom Code” tab, add the library files:
  • internal_simplempc_solver_1.lib
  1. (Figure 8.27) Compile the code of the Simulink model. This will also automatically load the model to the connected MicroAutoBox.
../../_images/dspace_y2f_1.png

Figure 8.16 Set the appropriate code generation options.

../../_images/dspace_y2f_2.png

Figure 8.17 Create a Simulink model.

../../_images/dspace_y2f_3.png

Figure 8.18 Populate the Simulink model.

../../_images/dspace_y2f_4.png

Figure 8.19 Add the folder containing the .mexw64 solver file to the Matlab path.

../../_images/dspace_y2f_5.png

Figure 8.20 Copy-paste and connect the FORCES Pro block.

../../_images/dspace_y2f_6.png

Figure 8.21 Open the Simulink model options.

../../_images/dspace_y2f_7.png

Figure 8.22 Set the Simulink solver options.

../../_images/dspace_y2f_8.png

Figure 8.23 Set the Simulink code generation options.

../../_images/dspace_y2f_9.png

Figure 8.24 Add the directories included for the code generation.

../../_images/dspace_y2f_10.png

Figure 8.25 Add the source files used for the code generation.

../../_images/dspace_y2f_11.png

Figure 8.26 Add the libraries used for the code generation.

../../_images/dspace_y2f_12.png

Figure 8.27 Compile the code of the Simulink model.