Code Generation from MATLAB Code

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.

  • Add the %#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:

  1. 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.

  2. 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.

  3. Configure the code generation settings for your application.

  4. Generate C/C++ code.

  5. 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.

  • Use 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 codegen command.

  • 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).

Related Topics