First, please use this link to check the architecture of the processor in your target dSpace® board. The following instructions assume a PowerPC target, however, the instructions will be very similar for x86.
Follow the instructions below to simulate FORCES Pro controllers in dSPACE® Autobox and MicroAutobox models, and deploy FORCES Pro solvers on dSPACE® PowerPC embedded hardware:
- Generate a controller using either the MATLAB® or Simulink® interfaces for a PowerPC target. Read the appropriate documentation for instructions on how to do this. Make sure that printing is turned off. This is the case by default in the Simulink® interface, but in the MATLAB® interface one will have to add the following line:
One should then determine the type of target. In most cases it will be a 32-bit PowerPC target. In the Simulink® interface you can change the target platform on the 'Solver Settings' tab. In the MATLAB® interface just add the following line to your FORCES Pro script.
codeoptions.platform = 'PowerPC'; % for 32-bit targets
codeoptions.platform = 'PowerPC64'; % for 64-bit targets
- If necessary, copy the generated FORCES Pro Simulink® block into your Autobox model. You can find this block in the folder /interface inside a file with extension .mdl.
- Provided that the generated S-function MEX file '*_simulinkBlock.mex*' is on your MATLAB® path you can directly simulate the behaviour of your controller with the other components in your Autobox model on your Windows PC.
- To build your application for deployment on the dSPACE® hardware you first need to move the MEX file '*_simulinkBlock.mex*' to your /interface folder and add that folder to the MATLAB® path. Note that this MEX file is a Windows DLL that can only run on the host Windows PC. The dSPACE® toolchain only uses the MEX file to determine the interfaces to the controller - this file will not be deployed on the target PowerPC platform.
- Add the location of your PowerPC solver file, located in the folder 'obj_target', so that the dSPACE® toolchain can link it with the other blocks of your Autobox model. Add the following lines to your '*_usr.mk' make file:
# Additional user object files to be linked.
USER_OBJS = "<path_to_generated_folder>\obj_target\*.o"
If you have a source code deployment license you can leave the USER_OBJS field blank and instead give the location of the solver source file:
# Additional C source files to be compiled (file name extension .c).
USER_SRCS = "<path_to_generated_folder>\src_target\*.c"
If you have multiple FORCES Pro blocks that you need to link into the applications you can add multiple files separated by spaces.
NLP users will additionally have to give the path to external (possibly automatically generated) files, e.g.
USER_SRCS = "<path_to_generated_folder>\casadi2forces.c" "<path_to_generated_folder>\model_i.c" "<path_to_generated_folder>\model_N.c"
In certain cases you may also need to give the location of the S-function source code.
# Directories where S-function C source files are stored.
SFCN_DIR = "<path_to_generated_folder>\interface"
It may also be necessary to add the source code directory to the MATLAB path.
Alternatively, instead of altering the settings for the entire Simulink model one can instead add the list of source (or object) files to the Block Parameters S-functions Modules of the FORCES Pro block. The items in the list should be separated by spaces and must not include the file extension. They must also be in the MATLAB path. This method may help to overcome problems appearing in MATLAB versions higher than 2015a.
- The system is now able to build the application for the dSPACE® target. It is not necessary to add the paths of the header files in the '*_usr.mk' make file since these path can be resolved from the S-function.
For troubleshooting please contact email@example.com or refer to the following dSpace documentation.