13.4. Speedgoat¶
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.4.1. High-level interface¶
13.4.1.1. Instructions¶
The steps to deploy and simulate a FORCESPRO controller on a Speedgoat platform are detailed below.
(Figure 13.60) 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.
(Figure 13.61) Create a new Simulink model using the blank model template.
(Figure 13.62) Populate the Simulink model with the system you want to control.
(Figure 13.63) Make sure the
FORCESNLPsolver_simulinkBlock.mexw64
file (created during code generation) is on the MATLAB path.(Figure 13.64) Open the
FORCESNLPsolver_lib.mdl
Simulink model file, contained in theinterface
folder of theFORCESNLPsolver
folder created during code generation.(Figure 13.65) Copy-paste the FORCESPRO Simulink block into your simulation model and connect its inputs and outputs appropriately.
(Figure 13.66) Access the Simulink model’s options.
(Figure 13.67) 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.
(Figure 13.68) 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
(Figure 13.69) In the “Code Generation/Custom Code” tab, include the directories:
BasicExample
BasicExample\FORCESNLPsolver\interface
BasicExample\FORCESNLPsolver\lib_target
(Figure 13.70) In the “Code Generation/Custom Code” tab, add the source files:
FORCESNLPsolver_simulinkBlock.c
FORCESNLPsolver_adtool2forces.c
FORCESNLPsolver_casadi.c
(Figure 13.71) In the “Code Generation/Custom Code” tab, add the library file:
FORCESNLPsolver.lib
(Figure 13.72) Access the FORCESPRO block’s parameters.
(Figure 13.73) Remove “FORCESNLPsolver” and “FORCESNLPsolver_simulinkBlock” from the S-function module.
(Figure 13.74) Compile the code of the Simulink model. This will also automatically load the model to the connected Speedgoat platform.
Deployment is complete and simulations can now be run on the Speedgoat platform.
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
.
13.4.1.2. Figures¶
13.4.2. Y2F interface¶
13.4.2.1. Instructions¶
The steps to deploy and simulate a FORCESPRO controller on a Speedgoat platform are detailed below.
(Figure 13.75) 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.
(Figure 13.76) Create a new Simulink model using the blank model template.
(Figure 13.77) Populate the Simulink model with the system you want to control.
(Figure 13.78) Make sure the
simplempc_solver_simulinkBlock.mexw64
file (created during code generation) is on the MATLAB path.(Figure 13.79) 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.(Figure 13.80) Access the Simulink model’s options.
(Figure 13.81) 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.
(Figure 13.82) 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
(Figure 13.83) In the “Code Generation/Custom Code” tab, include the directories:
Y2F\simplempc_solver\interface
Y2F\simplempc_solver\lib_target
(Figure 13.84) In the “Code Generation/Custom Code” tab, add the source files:
simplempc_solver_simulinkBlock.c
simplempc_solver.c
(Figure 13.85) In the “Code Generation/Custom Code” tab, add the library files:
internal_simplempc_solver_1.lib
(Figure 13.86) Compile the code of the Simulink model. This will also automatically load the model to the connected Speedgoat platform.
Deployment is complete and simulations can now be run on the Speedgoat platform.
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
.