14.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.
14.3.1. Code Generation¶
The steps to deploy a FORCESPRO controller on a dSPACE platform are detailed below.
(Figure 14.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

Figure 14.28 Set the appropriate code generation options.¶
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 14.29).Populate the Simulink model with the system you want to control (see Figure 14.30).

Figure 14.29 Create a Simulink model.¶

Figure 14.30 Populate the Simulink model.¶
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 14.31 , Figure 14.32 and Figure 14.33).The
FORCESNLPsolver_simulinkBlock.<mex_extension>
file (created during code generation) needs to be in the same path as your model (see Figure 14.34).

Figure 14.31 Generated files.¶

Figure 14.32 Solver interface files.¶

Figure 14.33 Solver libraries.¶

Figure 14.34 The .<mex_extension>
solver file is in the same path as the model.¶
Open the
FORCESNLPsolver_lib.mdl
Simulink model file, contained in theinterface
folder of theFORCESNLPsolver
folder created during code generation (see Figure 14.35).Copy-paste the FORCESPRO Simulink block into your simulation model and connect its inputs and outputs appropriately (see Figure 14.36).

Figure 14.35 Open the generated Simulink solver model.¶

Figure 14.36 Copy-paste and connect the FORCESPRO block.¶
Access the Simulink model’s options. In the “Solver” tab, set the options (see Figure 14.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 14.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 14.39):
.\FORCESNLPsolver\include
.\FORCESNLPsolver\interface
.\FORCESNLPsolver\lib_target
In the “Code Generation/Custom Code” tab, add the source files (see Figure 14.40):
FORCESNLPsolver_simulinkBlock.c
FORCESNLPsolver_adtool2forces.c
FORCESNLPsolver_casadi.c
In the “Code Generation/Custom Code” tab, add the library file (see Figure 14.41):
libFORCESNLPsolver.a

Figure 14.37 Set the Simulink solver options.¶

Figure 14.38 Set the Simulink code generation options.¶

Figure 14.39 Add the directories included for the code generation.¶

Figure 14.40 Add the source files used for the code generation.¶

Figure 14.41 Add the libraries used for the code generation.¶
Access the FORCESPRO block’s parameters (see Figure 14.42).
Remove the “FORCESNLPsolver” prefix from the S-function module (see Figure 14.43).

Figure 14.42 Open the FORCESPRO block’s parameters.¶

Figure 14.43 Remove the leading solver name from the S-function module.¶
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 14.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 14.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 14.46).

Figure 14.44 Create project and application in ConfigurationDesk.¶

Figure 14.45 Set period of Periodic Task.¶

Figure 14.46 Build the project.¶
14.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 14.47 and Figure 14.48).

Figure 14.47 The generated files from the ConfigurationDesk building.¶

Figure 14.48 The files necessary for the simulation of the FORCESPRO controller.¶
Open dSPACE Control Desk and select create new project and name it (see Figure 14.49).
Name the experiment to execute (see Figure 14.50).
Select the platform to which you will deploy the generated executable (see Figure 14.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 14.52).

Figure 14.49 Start a new project and name it.¶

Figure 14.50 Name your experiment.¶

Figure 14.51 Select the dSPACE platform.¶

Figure 14.52 Import the variable description file.¶
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 14.53 and Figure 14.54).To see all the plots concurrently right-click on the left of the Y-axis and select
YAxes-view
>Horizontal stacked
(see Figure 14.55).

Figure 14.53 Add the inputs of U OUTPUT in a Time Plotter.¶

Figure 14.54 Add the inputs of X OUTPUT in the same Time Plotter.¶

Figure 14.55 Select to show all the signals on the same plot with their own Y-axes¶
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 14.56 and Figure 14.57).Select
Go Online
andStart Measuring
to see the results. (see Figure 14.58 and Figure 14.59).

Figure 14.56 Load the application on the dSPACE platform.¶

Figure 14.57 Select BasicExample.rta from the ConfigurationDesk project folder.¶

Figure 14.58 Buttons Go Online and Start Measuring to receive execution results.¶

Figure 14.59 Plots and results from experiment on a dSPACE platform.¶