Deploying an Executable to the Desktop
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.
In the "Running MATLAB Functions and Simulink Models on a Desktop" documentation, the workflow of running MATLAB and Simulink directly on the desktop was described.
This documentation module shows how to convert MATLAB and Simulink code into executables using a function that has been provided by this Getting Started Guide, buildExecutable. How to deploy this executable to a robotic system is also described.
Overview of Deployment
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|
This module will go over the second line in this table, Desktop Deployment of an Executable using buildExecutable"
Why deploy an executable to the Desktop
An executable generated out of MATLAB and Simulink:
- Fast Execution - executes faster than running MATLAB Functions and Simulink Models directly
- Execution outside of MATLAB - can be run outside of MATLAB from the DOS Command Prompt or Terminal, thereby removing the processing overhead associated with keeping MATLAB open and enabling multiple executables to be run simultaneously
- Deployment to computer which does not have MATLAB installed - can be deployed to any computer which does not have MATLAB installed, as long as it has the same OS as the environment in which it was built.
Steps to Build an Executable
1. Setup the Compiler
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:
2. Build the Executable
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
Use the buildExecutable command to generate an executable out of the MATLAB Function or Simulink Model:
Basic MATLAB Example
Basic Simulink Example
Video Acquisition and Viewing using an Executable
Learn how to acquire and view video when generating an executable
Scheduling using an Executable
Learn how to schedule tasks when generating an executable
Communicating using an Executable
Learn how to communicate using UDP when generating an executable
Functions using an Executable
Learn how to use functions with system objects when generating an executable.
Buoy Detection using an Executable
Pull these basic concepts together to implement a basic task in the RoboBoat Competition, buoy detection.
Acquire acoustic data from a DAQ
Switch a Robotic System between Autonomous and Manual Mode using an RC Remote Control
Deploying an Executable using codegen, slbuild and packNGo
The buildExecutable function uses codegen, slbuild and packNGo to create a deployable package of code for a desktop computer.
If you would prefer not to use the buildExecutable to create your executable and/or would like to learn more about the underlying functions which are used, see the documentation for Deploying and Executable using codegen, slbuild and packNGo.