Начало работы с генератором кода
Автор
/* Code generated by Engee
* Model name: aircraft_roll.engee
* Code generator: release-1.0.21
* Date: Wed May 15 14:21:24 2024
*/
#include "aircraft_roll_autopilot_roll.h"
/* External inputs */
Ext_aircraft_roll_autopilot_roll_U aircraft_roll_autopilot_roll_U;
/* External outputs */
Ext_aircraft_roll_autopilot_roll_Y aircraft_roll_autopilot_roll_Y;
/* Block states */
Ext_aircraft_roll_autopilot_roll_S aircraft_roll_autopilot_roll_S;
/* Model initialize function */
void aircraft_roll_autopilot_roll_init() {
/* InitializeConditions for UnitDelay: /CtlMode/Unit Delay */
aircraft_roll_autopilot_roll_S.UnitDelay_state = 0.0;
/* InitializeConditions for UnitDelay: /RollMode/Unit Delay */
aircraft_roll_autopilot_roll_S.UnitDelay_1_state = 0.0;
}
/* Model terminate function */
void aircraft_roll_autopilot_roll_term() {
/* (no terminate code required) */
}
/* Model step function */
void aircraft_roll_autopilot_roll_step() {
double UnitDelay;
double UnitDelay_1;
double Abs;
bool NotEngaged;
bool NotEngaged_1;
bool RelationalOperator_1;
bool RelationalOperator;
double Add_1;
double DispGain_1;
bool OR;
bool RelationalOperator_2;
double Switch_1;
double Saturation_3;
double Switch;
double Switch_2;
double Switch_1_1;
double ModeSwitch;
double Saturation;
double Add_4;
double Gain_3;
double Saturation_1;
double Add;
double Gain;
double Gain_4;
double Ts_1;
double Add_1_1;
double Saturation_2;
double Add_2;
double Switch_1_2;
double Switch_2_1;
/* Output for UnitDelay: /CtlMode/Unit Delay */
UnitDelay = aircraft_roll_autopilot_roll_S.UnitDelay_state;
/* Output for UnitDelay: /RollMode/Unit Delay */
UnitDelay_1 = aircraft_roll_autopilot_roll_S.UnitDelay_1_state;
/* Abs: /RollMode/Abs */
Abs = fabs(aircraft_roll_autopilot_roll_U.Turn_Knob);
/* Logic: /CtlMode/NotEngaged incorporates:
* Inport: /AP_Eng
*/
NotEngaged = !(aircraft_roll_autopilot_roll_U.AP_Eng);
/* Logic: /RollMode/NotEngaged incorporates:
* Inport: /AP_Eng
*/
NotEngaged_1 = !(aircraft_roll_autopilot_roll_U.AP_Eng);
/* RelationalOperator: /RollMode/Relational Operator-1 incorporates:
* Inport: /Phi
* Constant: /RollMode/LoThr-1
*/
RelationalOperator_1 = aircraft_roll_autopilot_roll_U.Phi <= -6;
/* RelationalOperator: /RollMode/Relational Operator incorporates:
* Inport: /Phi
* Constant: /RollMode/UpThr-1
*/
RelationalOperator = aircraft_roll_autopilot_roll_U.Phi >= 6;
/* Sum: /HeadingMode/Add-1 incorporates:
* Inport: /HDG_Ref
* Inport: /Psi
*/
Add_1 = aircraft_roll_autopilot_roll_U.HDG_Ref - aircraft_roll_autopilot_roll_U.Psi;
/* Gain: /HeadingMode/DispGain-1 incorporates:
* Sum: /HeadingMode/Add-1
*/
DispGain_1 = 0.015 * Add_1;
/* Logic: /RollMode/OR incorporates:
* RelationalOperator: /RollMode/Relational Operator
* RelationalOperator: /RollMode/Relational Operator-1
*/
OR = RelationalOperator || RelationalOperator_1;
/* RelationalOperator: /RollMode/Relational Operator-2 incorporates:
* Abs: /RollMode/Abs
* Constant: /RollMode/Constant-2
*/
RelationalOperator_2 = Abs < 3;
/* Switch: /CtlMode/Switch-1 incorporates:
* Constant: /CtlMode/Constant-2
* Logic: /CtlMode/NotEngaged
* UnitDelay: /CtlMode/Unit Delay
*/
if (NotEngaged > 0.0) {
Switch_1 = 0.0;
} else {
Switch_1 = UnitDelay;
}
/* End of Switch: /CtlMode/Switch-1 */
/* Product: /HeadingMode/Product incorporates:
* Gain: /HeadingMode/DispGain-1
* Inport: /TAS
*/
const double Product = DispGain_1 * aircraft_roll_autopilot_roll_U.TAS;
/* Saturate: /CtlMode/Saturation-3 incorporates:
* Switch: /CtlMode/Switch-1
*/
if (Switch_1 < -5) {
Saturation_3 = -5;
} else if (Switch_1 > 5) {
Saturation_3 = 5;
} else {
Saturation_3 = Switch_1;
}
/* Switch: /RollMode/Switch incorporates:
* Inport: /Phi
* Logic: /RollMode/OR
* Constant: /RollMode/Constant
*/
if (OR != 0.0) {
Switch = aircraft_roll_autopilot_roll_U.Phi;
} else {
Switch = 0.0;
}
/* End of Switch: /RollMode/Switch */
/* Switch: /RollMode/Switch-2 incorporates:
* UnitDelay: /RollMode/Unit Delay
* RelationalOperator: /RollMode/Relational Operator-2
* Inport: /Turn_Knob
*/
if (RelationalOperator_2 != 0.0) {
Switch_2 = UnitDelay_1;
} else {
Switch_2 = aircraft_roll_autopilot_roll_U.Turn_Knob;
}
/* End of Switch: /RollMode/Switch-2 */
/* Switch: /RollMode/Switch-1 incorporates:
* Switch: /RollMode/Switch
* Logic: /RollMode/NotEngaged
* UnitDelay: /RollMode/Unit Delay
*/
if (NotEngaged_1 > 0.0) {
Switch_1_1 = Switch;
} else {
Switch_1_1 = UnitDelay_1;
}
/* End of Switch: /RollMode/Switch-1 */
/* Switch: /ModeSwitch incorporates:
* Product: /HeadingMode/Product
* Inport: /HDG_Mode
* Switch: /RollMode/Switch-2
*/
if (aircraft_roll_autopilot_roll_U.HDG_Mode != 0.0) {
ModeSwitch = Product;
} else {
ModeSwitch = Switch_2;
}
/* End of Switch: /ModeSwitch */
/* Saturate: /CtlMode/Saturation incorporates:
* Switch: /ModeSwitch
*/
if (ModeSwitch < -30) {
Saturation = -30;
} else if (ModeSwitch > 30) {
Saturation = 30;
} else {
Saturation = ModeSwitch;
}
/* Sum: /CtlMode/Add-4 incorporates:
* Saturate: /CtlMode/Saturation
* Inport: /Phi
*/
Add_4 = Saturation - aircraft_roll_autopilot_roll_U.Phi;
/* Gain: /CtlMode/Gain-3 incorporates:
* Sum: /CtlMode/Add-4
*/
Gain_3 = 0.75 * Add_4;
/* Saturate: /CtlMode/Saturation-1 incorporates:
* Gain: /CtlMode/Gain-3
*/
if (Gain_3 < -6) {
Saturation_1 = -6;
} else if (Gain_3 > 6) {
Saturation_1 = 6;
} else {
Saturation_1 = Gain_3;
}
/* Sum: /CtlMode/Add incorporates:
* Saturate: /CtlMode/Saturation-1
* Inport: /Rate_FB
*/
Add = Saturation_1 - aircraft_roll_autopilot_roll_U.Rate_FB;
/* Gain: /CtlMode/Gain incorporates:
* Sum: /CtlMode/Add
*/
Gain = 0.5 * Add;
/* Gain: /CtlMode/Gain-4 incorporates:
* Sum: /CtlMode/Add
*/
Gain_4 = 2 * Add;
/* Gain: /CtlMode/Ts-1 incorporates:
* Gain: /CtlMode/Gain
*/
Ts_1 = 1.0/40.0 * Gain;
/* Sum: /CtlMode/Add-1 incorporates:
* Saturate: /CtlMode/Saturation-3
* Gain: /CtlMode/Gain-4
*/
Add_1_1 = Saturation_3 + Gain_4;
/* Saturate: /CtlMode/Saturation-2 incorporates:
* Sum: /CtlMode/Add-1
*/
if (Add_1_1 < -15) {
Saturation_2 = -15;
} else if (Add_1_1 > 15) {
Saturation_2 = 15;
} else {
Saturation_2 = Add_1_1;
}
/* Sum: /CtlMode/Add-2 incorporates:
* Gain: /CtlMode/Ts-1
* UnitDelay: /CtlMode/Unit Delay
*/
Add_2 = Ts_1 + UnitDelay;
/* Switch: /CtlMode/Switch incorporates:
* Constant: /CtlMode/Constant
* Logic: /CtlMode/NotEngaged
* Sum: /CtlMode/Add-2
*/
if (NotEngaged > 0.0) {
Switch_1_2 = 0.0;
} else {
Switch_1_2 = Add_2;
}
/* End of Switch: /CtlMode/Switch */
/* Switch: /Switch incorporates:
* Saturate: /CtlMode/Saturation-2
* Inport: /AP_Eng
* Constant: /Constant
*/
if (aircraft_roll_autopilot_roll_U.AP_Eng != 0.0) {
Switch_2_1 = Saturation_2;
} else {
Switch_2_1 = 0;
}
/* End of Switch: /Switch */
/* Outport: /Ail_Cmd incorporates:
* Switch: /Switch
*/
aircraft_roll_autopilot_roll_Y.Ail_Cmd = Switch_2_1;
/* Update for UnitDelay: /CtlMode/Unit Delay */
aircraft_roll_autopilot_roll_S.UnitDelay_state = Switch_1_2;
/* Update for UnitDelay: /RollMode/Unit Delay */
aircraft_roll_autopilot_roll_S.UnitDelay_1_state = Switch_1_1;
}