Get Started with Embedded Coder
This model shows an implementation of a roll axis autopilot control system, that is designed for code generation.
About the Model
This model represents a basic roll axis autopilot with two operating modes: roll attitude hold and heading hold. The mode logic for these modes is external to this model. The model architecture represents the heading hold mode and basic roll attitude function as atomic subsystems.
The roll attitude control function is a PID controller that uses roll attitude and roll rate feedback to produce an aileron command. The input to the controller is either a basic roll angle reference or a roll command to track the desired heading. The model is as follows:
open_system('RollAxisAutopilot');
Subsystem RollAngleReference
The basic roll angle reference calculation is implemented as the subsystem RollAngleReference
. Embedded Coder® inlines this calculation directly into the main function for RollAxisAutopilot
.
open_system('RollAxisAutopilot/RollAngleReference');
Subsystem HeadingMode
The subsystem HeadingMode
computes the roll command to track the desired heading.
close_system('RollAxisAutopilot/RollAngleReference'); open_system('RollAxisAutopilot/HeadingMode');
Subsystem BasicRollMode
The subsystem BasicRollMode
computes the roll attitude control function (PID).
close_system('RollAxisAutopilot/HeadingMode'); open_system('RollAxisAutopilot/BasicRollMode');
Generate Code for the Model
The model is preconfigured to generate code using Embedded Coder. To generate code using Simulink® Coder™ only, reconfigure the model or at the command prompt type cs = getActiveConfigSet('RollAxisAutopilot'); switchTarget(cs,'grt.tlc',[]);
Generate code.
slbuild('RollAxisAutopilot');
### Starting build procedure for: RollAxisAutopilot ### Successful completion of build procedure for: RollAxisAutopilot Build Summary Top model targets: Model Build Reason Status Build Duration ==================================================================================================================== RollAxisAutopilot Information cache folder or artifacts were missing. Code generated and compiled. 0h 0m 26.381s 1 of 1 models built (0 models already up to date) Build duration: 0h 0m 31.564s
You can view the entire generated code in a detailed HTML report, with bi-directional traceability between model and code.
currentDir = pwd; web(fullfile(currentDir,'RollAxisAutopilot_ert_rtw','html','index.html'))
Embedded Coder Get Started Tutorials
For more information on generating code with Embedded Coder, see Generate C Code from Simulink Models in the Get Started with Embedded Coder documentation.