10.2. dSPACE MicroAutoBox II

10.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 10.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 10.2) Create a new Simulink model using the RTI1401 template provided by dSPACE.

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

  3. (Figure 10.4) Make sure the FORCESNLPsolver_simulinkBlock.mexw64 file (created during code generation) is on the Matlab path.

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

  5. (Figure 10.6) Copy-paste the FORCES Pro Simulink block into your simulation model and connect its inputs and outputs appropriately.

  6. (Figure 10.7) Access the Simulink model’s options.

  7. (Figure 10.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 10.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 10.10) In the “Code Generation/Custom Code” tab, include the directories:

  • BasicExample

  • BasicExample\FORCESNLPsolver\interface

  • BasicExample\FORCESNLPsolver\lib_target

  1. (Figure 10.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 10.12) In the “Code Generation/Custom Code” tab, add the library files:

  • FORCESNLPsolver.lib

  1. (Figure 10.13) Access the FORCES Pro block’s parameters.

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

  3. (Figure 10.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 10.1 Set the appropriate code generation options.

../../_images/dspace_high_level_2.png

Figure 10.2 Create a Simulink model.

../../_images/dspace_high_level_3.png

Figure 10.3 Populate the Simulink model.

../../_images/dspace_high_level_4.png

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

../../_images/dspace_high_level_5.png

Figure 10.5 Open the generated Simulink solver model.

../../_images/dspace_high_level_6.png

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

../../_images/dspace_high_level_7.png

Figure 10.7 Open the Simulink model options.

../../_images/dspace_high_level_8.png

Figure 10.8 Set the Simulink solver options.

../../_images/dspace_high_level_9.png

Figure 10.9 Set the Simulink code generation options.

../../_images/dspace_high_level_10.png

Figure 10.10 Add the directories included for the code generation.

../../_images/dspace_high_level_11.png

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

../../_images/dspace_high_level_12.png

Figure 10.12 Add the libraries used for the code generation.

../../_images/dspace_high_level_13.png

Figure 10.13 Open the FORCES Pro block’s parameters.

../../_images/dspace_high_level_14.png

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

../../_images/dspace_high_level_15.png

Figure 10.15 Compile the code of the Simulink model.

10.2.2. Y2F interface

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

  1. (Figure 10.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 10.17) Create a new Simulink model using the RTI1401 template provided by dSPACE.

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

  3. (Figure 10.19) Make sure the simplempc_solver_simulinkBlock.mexw64 file (created during code generation) is on the Matlab path.

  4. (Figure 10.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 10.21) Access the Simulink model’s options.

  6. (Figure 10.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 10.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 10.24) In the “Code Generation/Custom Code” tab, include the directories:

  • Y2F

  • Y2F\simplempc_solver\interface

  • Y2F\simplempc_solver\lib_target

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

  • simplempc_solver_simulinkBlock.c

  • simplempc_solver.c

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

  • internal_simplempc_solver_1.lib

  1. (Figure 10.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 10.16 Set the appropriate code generation options.

../../_images/dspace_y2f_2.png

Figure 10.17 Create a Simulink model.

../../_images/dspace_y2f_3.png

Figure 10.18 Populate the Simulink model.

../../_images/dspace_y2f_4.png

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

../../_images/dspace_y2f_5.png

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

../../_images/dspace_y2f_6.png

Figure 10.21 Open the Simulink model options.

../../_images/dspace_y2f_7.png

Figure 10.22 Set the Simulink solver options.

../../_images/dspace_y2f_8.png

Figure 10.23 Set the Simulink code generation options.

../../_images/dspace_y2f_9.png

Figure 10.24 Add the directories included for the code generation.

../../_images/dspace_y2f_10.png

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

../../_images/dspace_y2f_11.png

Figure 10.26 Add the libraries used for the code generation.

../../_images/dspace_y2f_12.png

Figure 10.27 Compile the code of the Simulink model.