13.3. dSPACE deployment through ConfigurationDesk¶
This process applies to the following dSPACE platforms
dSPACE MicroAutoBox III
dSPACE SCALEXIO
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.3.1. Code Generation¶
The steps to deploy a FORCESPRO controller on a dSPACE platform are detailed below.
(Figure 13.28) Set the code generation options:
When generating code for HW target platforms, codeoptions.platform
needs to be set.
dSPACE MicroAutoBox III:
'dSPACE-MABXIII'
dSPACE SCALEXIO:
'dSPACE-SCALEXIO'
codeoptions.platform = '<platform_name>'; % to generate code for the dSPACE platform
codeoptions.printlevel = 0; % printing should be disabled on target HW
codeoptions.cleanup = 0; % to keep necessary files for target compile
Create a new Simulink model (henceforth referred to as
dSPACE.slx
) using thedSPACE Run-Time Target
template provided by dSPACE and save it in theBasicExample
folder (see Figure 13.29).Populate the Simulink model with the system you want to control (see Figure 13.30).
Run the BasicExample.m script to perform code generation for your solver (henceforth referred to as
FORCESNLPsolver
, placed in the folder “BasicExample”). This will create the necessary files for your building (see Figure 13.31 , Figure 13.32 and Figure 13.33).The
FORCESNLPsolver_simulinkBlock.<mex_extension>
file (created during code generation) needs to be in the same path as your model (see Figure 13.34).
Open the
FORCESNLPsolver_lib.mdl
Simulink model file, contained in theinterface
folder of theFORCESNLPsolver
folder created during code generation (see Figure 13.35).Copy-paste the FORCESPRO Simulink block into your simulation model and connect its inputs and outputs appropriately (see Figure 13.36).
Access the Simulink model’s options. In the “Solver” tab, set the options (see Figure 13.37):
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.
In the “Code Generation” tab, set the options (see Figure 13.38):
System target file:
dsrt.tlc
Language:
C
/C++
Generate makefile: Checked
Template makefile:
dsrt_default_tmf
Make command:
make_dsrt
In the “Code Generation/Custom Code” tab, include the directories (see Figure 13.39):
.\FORCESNLPsolver\include
.\FORCESNLPsolver\interface
.\FORCESNLPsolver\lib_target
In the “Code Generation/Custom Code” tab, add the source files (see Figure 13.40):
FORCESNLPsolver_simulinkBlock.c
FORCESNLPsolver_adtool2forces.c
FORCESNLPsolver_casadi.c
In the “Code Generation/Custom Code” tab, add the library file (see Figure 13.41):
libFORCESNLPsolver.a
Access the FORCESPRO block’s parameters (see Figure 13.42).
Remove the “FORCESNLPsolver” prefix from the S-function module (see Figure 13.43).
Create a new Project and Application in ConfigurationDesk. Select directory of project, name of project and application, the model
dSPACE.slx
as the application process and connected dSPACE platform to deploy to (see Figure 13.44).Go to the tasks tab and make sure the period of the Periodic Task matches the fixed step size selected in the Simulink model options (see Figure 13.45).
Go to the build tab and start the building process. After building is complete the application will be loaded automatically in the dSPACE platform (see Figure 13.46).
13.3.2. Solver Execution¶
The steps to simulate a FORCESPRO controller on a dSPACE platform are detailed below.
After code generation with FORCESPRO and building with the ConfigurationDesk, the ConfigurationDesk project will have generated files to use to run your model on the dSPACE platform (see Figure 13.47 and Figure 13.48).
Open dSPACE Control Desk and select create new project and name it (see Figure 13.49).
Name the experiment to execute (see Figure 13.50).
Select the platform to which you will deploy the generated executable (see Figure 13.51).
Import the variable description file
BasicExample.sdf
in order to have access to the model variables and see the results of the execution (see Figure 13.52).
On the project layout select the tab
Variables
and on theBasicExample.sdf
category expandModel Root
.Select
U OUTPUT
andX OUTPUT
and Drag & Drop all the input variables together to the Layout. In the opened menu selectTime Plotter
(see Figure 13.53 and Figure 13.54).To see all the plots concurrently right-click on the left of the Y-axis and select
YAxes-view
>Horizontal stacked
(see Figure 13.55).
Application should have already been loaded from the building of ConfigurationDesk. Otherwise, select the
Platforms/Devices
tab. Right-Click on your platform and selectReal-Time Application
>Load
. Choose the executable fileBasicExample.rta
(see Figure 13.56 and Figure 13.57).Select
Go Online
andStart Measuring
to see the results. (see Figure 13.58 and Figure 13.59).