This model shows an implementation of a roll axis autopilot control system, that is designed for code generation.
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('rtwdemo_roll');
RollAngleReference
The basic roll angle reference calculation is implemented as the subsystem RollAngleReference
. Embedded Coder® inlines this calculation directly into the main function for rtwdemo_roll
.
open_system('rtwdemo_roll/RollAngleReference');
HeadingMode
The subsystem HeadingMode
computes the roll command to track the desired heading.
close_system('rtwdemo_roll/RollAngleReference'); open_system('rtwdemo_heading');
BasicRollMode
The subsystem BasicRollMode
computes the roll attitude control function (PID).
close_system('rtwdemo_heading'); open_system('rtwdemo_attitude');
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 rtwconfiguredemo('rtwdemo_roll','GRT')
In your system temporary folder, create a temporary folder for the build process.
currentDir = pwd; [~,cgDir] = rtwdemodir();
Generate code.
rtwbuild('rtwdemo_roll');
### Starting build procedure for: rtwdemo_roll ### Successful completion of build procedure for: rtwdemo_roll Build Summary Top model targets built: Model Action Rebuild Reason ============================================================================================= rtwdemo_roll Code generated and compiled Code generation information file does not exist. 1 of 1 models built (0 models already up to date) Build duration: 0h 0m 10.946s
You can view the entire generated code in a detailed HTML report, with bi-directional traceability between model and code.
web(fullfile(cgDir,'rtwdemo_roll_ert_rtw','html','rtwdemo_roll_codegen_rpt.html'))
Close models and return to previous working folder.
close_system('rtwdemo_roll',0) close_system('rtwdemo_attitude',0) close_system('rtwdemo_heading',0) cd(currentDir); rtwdemoclean;
For more information on generating code with Embedded Coder, see the Tutorials in the Get Started with Embedded Coder documentation.