Generate Code by Using Embedded Coder Quick Start
RollAxisAutopilot represents an autopilot control system for an
aircraft. You prepare
RollAxisAutopilot for embedded code generation by
using Embedded Coder® Quick Start, which chooses fundamental code generation settings based on your
goals and application.
Generate Code with Quick Start Tool
Open the model
RollAxisAutopilotby typing this command:
If the C Code tab is not already open, in the Apps gallery, under Code Generation, click Embedded Coder.
On the C Code tab, click Quick Start.
Advance through the steps of the Quick Start tool, stopping at the Generate Code step. Each step asks questions about the code that you want to generate. For this tutorial, use the defaults that are already selected. The tool validates your selections against the model and presents the parameter changes required to generate code.
In the Generate Code step, apply the proposed changes and generate code from
RollAxisAutopilotby clicking Next.
Click Finish, then return to the C Code tab. From this tab you can configure code generation customizations, and then check the results in the Code view next to the model.
Inspect the Generated Code
The generated code appears in two primary files:
RollAxisAutopilot.h. In your MATLAB® current folder, the
contains these primary files.
In your current folder, the code generator creates the
This folder contains the
rtwtypes.h file, which defines standard data
types that the generated code uses by default. In general, this sibling folder contains
generated files that can or must be shared between multiple models.
The code that you generate from a model includes entry-point functions, which you call from your application code. For a rate-based model, these functions include an initialization function, an execution function, and, optionally, terminate and reset functions. The functions exchange data with your application code through a data interface that you control.
Open the Code Mappings editor by clicking Code Mappings - Component Interface below the model diagram. On the Functions tab, you can see the individual entry-point functions that the code generator produces. You call these generated functions from external code or from a version of a generated main function that you modify. For the base-rate step function of a rate-based model and for step functions for export function models, you can customize the function name and arguments.
Review the list of entry-point functions that the code generator produces for the model.
Use this view to selectively specify for each function a function customization template
(code definition) and name. For this tutorial, the code generator uses default (shipped)
settings for the customization template and entry-point function names. The code generator
names the initialize function
RollAxisAutopilot_initialize and the
execution (step) function
RollAxisAutopilot_step. Both entry-point
functions have a
void-void interface (they pass
no arguments). The functions gain access to data through shared
data structures. Examples of such data include system-level input and output that the
functions exchange with application code.
To see these entry-point functions in the generated code:
On the right side of the Simulink® Editor window, in the Code view pane, locate the search bar.
In the search bar, type
RollAxisAutopilot_step. To find each instance of the step function name across the generated code files, click the search suggestion.
Use the arrows on the right to step through each instance, including the step function definition in
RollAxisAutopilot.cand the declaration in
RollAxisAutopilot.h. You can also see the number of search hits in each file from the file menu in the upper left corner.
Repeat these search steps to locate the initialize function,
RollAxisAutopilot_initializein the generated code.
Next, configure the data interface for code generation and review the generated code.