Getting Started with Executable Deployment
This documentation shows the workflow of generating an executable out of MATLAB and Simulink code to be placed on the desktop. This executable could be used to control your robotic platform.
There are several different ways of deploying MATLAB and Simulink Code. This table summarizes the various deployment methods that are available for MATLAB and Simulink code to a desktop.
Table of Deployment Methods
|Run in MATLAB or Simulink||Run code in MATLAB||Run code in Simulink|
|Desktop Deployment of Executable||buildExecutable(codename) which uses codegen and packNGo||buildExecutable(codename) which uses slbuild and packNGo|
|Desktop Algorithm Export||Generate C/C++ code only, use external IDE to build||Generate C/C++ code only, use external IDE to build|
Why deploy an executable to the Desktop
- Fast Execution - MATLAB and Simulink generated code executes faster and is easy to deploy than base MATLAB and Simulink code.
- Execution from Terminal - Generating an executable allows the user to run the executable from the DOS Command Prompt or Terminal, enabling many executables to be run simultaneously
- Deployment to computer which does not have MATLAB installed - When executables are created out of the generated code, they can be deployed to any computer with the same OS as the environment in which it was built.
This documentation shows how to convert MATLAB functions and Simulink models into executables using a function that has been provided by this toolbox, buildExecutable. How to deploy this executable to a robotic system is also described.
As with most code generation related workflows in MATLAB and Simulink, a compiler is necessary.
MATLAB and Simulink Coder automatically locates and uses a supported installed compiler. For the current list of supported compilers, see Supported and Compatible Compilers on the MathWorks® Web site.
You can use mex -setup to change the default compiler. See Changing Default Compiler.
To determine if your compiler is set up correctly, use the following example in the documentation:
Step 1: Check for codegen support
The codegen directive in MATLABi.e. %#codegen, checks the function to make sure that everything is supported for code generation. Add the %#codegen directive (or pragma) to your function after the function signature to indicate that you intend to generate code for the MATLAB® algorithm.
function bw = thresholdImage(img,thresholds) %#codegen bw = logical(... % red threshold
Adding this directive instructs the MATLAB code analyzer to help you diagnose and fix violations that would result in errors during code generation. If there are functions that are not supported for code generation, this directive will allow the MATLAB code analyzer to tell you.
Alternatively, you could use the following documentation to determine pre-emptively if a function is supported for code generation.
Step 2: Use buildExecutable
Basic MATLAB Example
Basic Simulink Example