Several Robotics System Toolbox™ functions are enabled to generate C/C++ code. Code generation from MATLAB code requires the MATLAB® Coder™ product. To generate code from robotics functions, follow these steps:
Write your function or application that uses Robotics System Toolbox functions that are enabled for code generation. For code generation, some of these functions have requirements that you must follow. See Code Generation Support.
%#codegen directive to your MATLAB code.
Follow the workflow for code generation from MATLAB code using either the MATLAB Coder app or the command-line interface.
Using the app, the basic workflow is:
Set up a project. Specify your top-level functions and define input types.
The app screens your code for code generation readiness. It reports issues such as a function that is not supported for code generation.
Check for run-time issues.
The app generates and runs a MEX version of your function. This step detects issues that can be hard to detect in the generated C/C++ code.
Configure the code generation settings for your application.
Generate C/C++ code.
Verify the generated C/C++ code. If you have an Embedded Coder® license, you can use software-in-the-loop execution (SIL) or processor-in-the-loop (PIL) execution.
For a tutorial, see Generate C Code by Using the MATLAB Coder App (MATLAB Coder).
Using the command-line interface, the basic workflow is:
To detect issues and verify the behavior of the generated code, generate a MEX version of your function.
coder.config to create a code configuration object
for a library or executable.
Modify the code configuration object properties as required for your application.
Generate code using the
Verify the generated code. If you have an Embedded Coder license, you can use software-in-the-loop execution (SIL) or processor-in-the-loop (PIL) execution.
For a tutorial, see Generate C Code at the Command Line (MATLAB Coder).
To view a full list of code generation support, see Functions Supporting Code Generation. You can also view the Extended Capabilities section on any reference page.