Getting started with the code generator
This model presents the implementation of an autopilot control system along the roll axis. The model is intended for code generation.
About the model
This model represents the basic roll channel autopilot with two modes of operation: roll stabilization and flight course retention. The logic of switching modes is external to this model and can be implemented in other models. The roll stabilization and flight course retention modes are architecturally separated into atomic subsystems within the model.
The roll stabilization function is a PID controller that uses feedback on the angle and speed of the roll to issue commands to the aileron. The input signal for the controller is either the roll angle setting (preset value) or the roll angle command to maintain the desired flight course. The model looks like this:
The RollMode subsystem
This subsystem implements the basic calculation of the roll angle setting. Depending on the subsystem type, the Engee code generator will embed this calculation directly into the main function of the model (for the virtual subsystem) or generate a separate function with the subsystem name (for the atomic subsystem).
The HeadingMode subsystem
In this subsystem, the roll setting is calculated to maintain the desired flight course.
The CtlMode subsystem
This subsystem implements the roll angle stabilization function in the form of a PID controller.
Simulation of the model
The model contains a test harness around the subsystem autopilot_roll. Run a simulation of the model to make sure it is correct.
Generating code from a model
This Engee model is ready for code generation. To generate the code from the subsystem autopilot_roll (which represents the algorithmic part of the model), run the following command on the command line or in an interactive script Engee:
engee.generate_code( "$(@__DIR__)/aircraft_roll.engee",
"$(@__DIR__)/autopilot_roll",
subsystem_name="autopilot_roll" )
Command syntax engee.model.generate_code it is described in detail in the section Code generator in Engee.
The generated code is located in the directory start/examples/codegen/GettingStartedCodegen/autopilot_roll.
Consider the generated code.
For more information about the functions and interface of the generated code, see Code Generator Features.