8.3. Speedgoat

8.3.1. High-level interface

The steps to deploy and simulate a FORCES Pro controller on a Speedgoat platform are detailed below.

  1. (Figure 8.28) Set the code generation options:
codeoptions.platform = 'Speedgoat-x86'; % 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.29) Create a new Simulink model using the blank model template.
  2. (Figure 8.30) Populate the Simulink model with the system you want to control.
  3. (Figure 8.31) Make sure the FORCESNLPsolver_simulinkBlock.mexw64 file (created during code generation) is on the Matlab path.
  4. (Figure 8.32) Open the FORCESNLPsolver_lib.mdl Simulink model file, contained in the interface folder of the FORCESNLPsolver folder created during code generation.
  5. (Figure 8.33) Copy-paste the FORCES Pro Simulink block into your simulation model and connect its inputs and outputs appropriately.
  6. (Figure 8.34) Access the Simulink model’s options.
  7. (Figure 8.35) 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.
  1. (Figure 8.36) In the “Code Generation” tab, set the options:
  • System target file: slrt.tlc
  • Language: C
  • Generate makefile: On
  • Template makefile: slrt_default_tmf
  • Make command: make_rtw
  1. (Figure 8.37) In the “Code Generation/Custom Code” tab, include the directories:
  • BasicExample
  • BasicExample\FORCESNLPsolver\interface
  • BasicExample\FORCESNLPsolver\lib_target
  1. (Figure 8.38) 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.39) In the “Code Generation/Custom Code” tab, add the library files:
  • FORCESNLPsolver.lib
  1. (Figure 8.40) Access the FORCES Pro block’s parameters.

  2. (Figure 8.41) Remove “FORCESNLPsolver” and “FORCESNLPsolver_simulinkBlock” from the S-function module.

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

  4. Run the simulation on the Speedgoat platform.

    You can download the Matlab code of this simulation to try it out for yourself by clicking here.

../../_images/speedgoat_high_level_1.png

Figure 8.28 Set the appropriate code generation options.

../../_images/speedgoat_high_level_2.png

Figure 8.29 Create a Simulink model.

../../_images/speedgoat_high_level_3.png

Figure 8.30 Populate the Simulink model.

../../_images/speedgoat_high_level_4.png

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

../../_images/speedgoat_high_level_5.png

Figure 8.32 Open the generated Simulink solver model.

../../_images/speedgoat_high_level_6.png

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

../../_images/speedgoat_high_level_7.png

Figure 8.34 Open the Simulink model options.

../../_images/speedgoat_high_level_8.png

Figure 8.35 Set the Simulink solver options.

../../_images/speedgoat_high_level_9.png

Figure 8.36 Set the Simulink code generation options.

../../_images/speedgoat_high_level_10.png

Figure 8.37 Add the directories included for the code generation.

../../_images/speedgoat_high_level_11.png

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

../../_images/speedgoat_high_level_12.png

Figure 8.39 Add the libraries used for the code generation.

../../_images/speedgoat_high_level_13.png

Figure 8.40 Open the FORCES Pro block’s parameters.

../../_images/speedgoat_high_level_14.png

Figure 8.41 Remove the default data from the S-function module.

../../_images/speedgoat_high_level_15.png

Figure 8.42 Compile the code of the Simulink model.

8.3.2. Y2F interface

The steps to deploy and simulate a FORCES Pro controller on a Speedgoat platform are detailed below.

  1. (Figure 8.43) Set the code generation options:
codeoptions.platform = 'Speedgoat-x86'; % 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.44) Create a new Simulink model using the blank model template.
  2. (Figure 8.45) Populate the Simulink model with the system you want to control.
  3. (Figure 8.46) Make sure the simplempc_solver_simulinkBlock.mexw64 file (created during code generation) is on the Matlab path.
  4. (Figure 8.47) 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.48) Access the Simulink model’s options.
  6. (Figure 8.49) 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.50) In the “Code Generation/RTI general build options” tab, set the options:
  • System target file: slrt.tlc
  • Language: C
  • Generate makefile: On
  • Template makefile: slrt_default_tmf
  • Make command: make_rtw
  1. (Figure 8.51) In the “Code Generation/Custom Code” tab, include the directories:
  • Y2F\simplempc_solver\interface
  • Y2F\simplempc_solver\lib_target
  1. (Figure 8.52) In the “Code Generation/Custom Code” tab, add the source files:
  • simplempc_solver_simulinkBlock.c
  • simplempc_solver.c
  1. (Figure 8.53) In the “Code Generation/Custom Code” tab, add the library files:
  • internal_simplempc_solver_1.lib
  1. (Figure 8.54) Compile the code of the Simulink model. This will also automatically load the model to the connected Speedgoat platform.

  2. Run the simulation on the Speedgoat platform.

    You can download the Matlab code of this simulation to try it out for yourself by clicking here.

../../_images/speedgoat_y2f_1.png

Figure 8.43 Set the appropriate code generation options.

../../_images/speedgoat_y2f_2.png

Figure 8.44 Create a Simulink model.

../../_images/speedgoat_y2f_3.png

Figure 8.45 Populate the Simulink model.

../../_images/speedgoat_y2f_4.png

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

../../_images/speedgoat_y2f_5.png

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

../../_images/speedgoat_y2f_6.png

Figure 8.48 Open the Simulink model options.

../../_images/speedgoat_y2f_7.png

Figure 8.49 Set the Simulink solver options.

../../_images/speedgoat_y2f_8.png

Figure 8.50 Set the Simulink code generation options.

../../_images/speedgoat_y2f_9.png

Figure 8.51 Add the directories included for the code generation.

../../_images/speedgoat_y2f_10.png

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

../../_images/speedgoat_y2f_11.png

Figure 8.53 Add the libraries used for the code generation.

../../_images/speedgoat_y2f_12.png

Figure 8.54 Compile the code of the Simulink model.