Getting started with the code generator¶
This model presents the implementation of the autopilot roll axis control system. The model is intended for code generation.
About the model¶
This model represents a basic roll channel autopilot with two modes of operation: roll stabilisation and heading hold. The mode switching logic is external to this model and can be implemented in other models. The roll stabilisation and heading hold modes are architecturally separated into atomic subsystems within the model.
The roll stabilisation function is a PID controller that uses roll angle and roll rate feedback to issue an aileron command. The input signal to the controller is either a roll angle setpoint (target value) or a roll angle command to hold the desired flight path. The model is as follows:
RollMode subsystem¶
This subsystem implements the basic roll set point calculation. Depending on the subsystem type, the Engee code generator will embed this calculation directly into the main model function (for a virtual subsystem) or generate a separate function with the subsystem name (for an atomic subsystem).
HeadingMode subsystem¶
This subsystem calculates the roll setpoint to maintain the desired heading.
CtlMode subsystem¶
This subsystem implements the roll angle stabilisation function in the form of a PID controller.
Model simulation¶
The model contains test pipelining around the subsystem autopilot_roll
. Run a simulation of the model to make sure it is correct.
Code generation from the model¶
This Engee model is ready for code generation. To generate code from the autopilot_roll
subsystem (which represents the algorithmic part of the model), run the following command on the command line or in the Engee interactive script:
engee.generate_code( "$(@__DIR__)/aircraft_roll.engee",
"$(@__DIR__)/autopilot_roll",
subsystem_name="autopilot_roll" )
The syntax of the engee.model.generate_code
command is described in detail in Code Generator in Engee.
The generated code is located in the directory start/examples/codegen/GettingStartedCodegen/autopilot_roll
.
Let's examine the generated code.
For details on the functions and interface of the generated code, refer to Code Generator Features.