Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: apu fuel consumption #8145

Merged
merged 3 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
1. [MCDU] Add basic annunciator support - @tracernz (Mike)
1. [MCDU] Add basic MCDU MENU functionality - @tracernz (Mike)
1. [MCDU] Split subsystem scratchpads - @tracernz (Mike)
1. [APU] APU can now consume fuel - @tracernz (Mike)

## 0.10.0

Expand Down
26 changes: 16 additions & 10 deletions fbw-a32nx/src/wasm/fadec_a320/src/EngineControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ class EngineControl {
outFlow = 0;
} else {
outFlow = max(0, (correctedFuelFlow * LBS_TO_KGS * ratios->delta2(mach, ambientPressure) * sqrt(ratios->theta2(mach, ambientTemp))) -
paramImbalance);
paramImbalance);
}

if (engine == 1) {
Expand Down Expand Up @@ -658,11 +658,10 @@ class EngineControl {
}
}

/// <summary>
/// FBW Fuel Consumption and Tankering
/// @brief FBW Fuel Consumption and Tankering
/// Updates Fuel Consumption with realistic values
/// </summary>
void updateFuel(double deltaTime) {
/// @param deltaTimeSeconds Frame delta time in seconds
void updateFuel(double deltaTimeSeconds) {
double m = 0;
double b = 0;
double fuelBurn1 = 0;
Expand Down Expand Up @@ -692,6 +691,7 @@ class EngineControl {
double engine1FF = simVars->getEngine1FF(); // KG/H
double engine2FF = simVars->getEngine2FF(); // KG/H

/// weight of one gallon of fuel in pounds
double fuelWeightGallon = simVars->getFuelWeightGallon();
double fuelUsedLeft = simVars->getFuelUsedLeft(); // Kg
double fuelUsedRight = simVars->getFuelUsedRight(); // Kg
Expand All @@ -706,7 +706,9 @@ class EngineControl {
double leftAuxQuantity = simVars->getFuelTankQuantity(4) * fuelWeightGallon; // LBS
double rightAuxQuantity = simVars->getFuelTankQuantity(5) * fuelWeightGallon; // LBS
double centerQuantity = simVars->getFuelTankQuantity(1) * fuelWeightGallon; // LBS
double fuelLeft = 0; // LBS
/// Left inner tank fuel quantity in pounds
double fuelLeft = 0;
/// Right inner tank fuel quantity in pounds
double fuelRight = 0;
double fuelLeftAux = 0;
double fuelRightAux = 0;
Expand All @@ -717,7 +719,7 @@ class EngineControl {
double xfrAuxRight = 0;
double fuelTotalActual = leftQuantity + rightQuantity + leftAuxQuantity + rightAuxQuantity + centerQuantity; // LBS
double fuelTotalPre = fuelLeftPre + fuelRightPre + fuelAuxLeftPre + fuelAuxRightPre + fuelCenterPre; // LBS
double deltaFuelRate = abs(fuelTotalActual - fuelTotalPre) / (fuelWeightGallon * deltaTime); // LBS/ sec
double deltaFuelRate = abs(fuelTotalActual - fuelTotalPre) / (fuelWeightGallon * deltaTimeSeconds); // LBS/ sec

double engine1State = simVars->getEngine1State();
double engine2State = simVars->getEngine2State();
Expand All @@ -733,7 +735,8 @@ class EngineControl {
isReady = simVars->getIsReady();
devState = simVars->getDeveloperState();

deltaTime = deltaTime / 3600;
/// Delta time for this update in hours
double deltaTime = deltaTimeSeconds / 3600;

// Pump State Logic for Left Wing
if (pumpStateLeft == 0 && (timerLeft.elapsed() == 0 || timerLeft.elapsed() >= 1000)) {
Expand Down Expand Up @@ -902,10 +905,13 @@ class EngineControl {
else if (xfrValveCenterRightOpen)
xfrCenterToRight = fuelCenterPre - centerQuantity;

/// apu fuel consumption for this frame in pounds
double apuFuelConsumption = simVars->getLineFlow(18) * fuelWeightGallon * deltaTime;

//--------------------------------------------
// Final Fuel levels for left and right inner tanks
fuelLeft = (fuelLeftPre - (fuelBurn1 * KGS_TO_LBS)) + xfrAuxLeft + xfrCenterToLeft; // LBS
fuelRight = (fuelRightPre - (fuelBurn2 * KGS_TO_LBS)) + xfrAuxRight + xfrCenterToRight; // LBS
fuelLeft = (fuelLeftPre - (fuelBurn1 * KGS_TO_LBS)) + xfrAuxLeft + xfrCenterToLeft - apuFuelConsumption; // LBS
fuelRight = (fuelRightPre - (fuelBurn2 * KGS_TO_LBS)) + xfrAuxRight + xfrCenterToRight; // LBS

//--------------------------------------------
// Setting new pre-cycle conditions
Expand Down
9 changes: 6 additions & 3 deletions fbw-a32nx/src/wasm/fadec_a320/src/SimVars.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class SimVars {
Engine1VibN1 = register_named_variable("A32NX_ENGINE_VIB_N1:1");
Engine2VibN1 = register_named_variable("A32NX_ENGINE_VIB_N1:2");
Engine1VibN2 = register_named_variable("A32NX_ENGINE_VIB_N2:1");
Engine2VibN2 = register_named_variable("A32NX_ENGINE_VIB_N2:2");
Engine2VibN2 = register_named_variable("A32NX_ENGINE_VIB_N2:2");
Engine1FF = register_named_variable("A32NX_ENGINE_FF:1");
Engine2FF = register_named_variable("A32NX_ENGINE_FF:2");
Engine1PreFF = register_named_variable("A32NX_ENGINE_PRE_FF:1");
Expand Down Expand Up @@ -324,7 +324,7 @@ class SimVars {
FLOAT64 getEngine1VibN1() { return get_named_variable_value(Engine1VibN1); }
FLOAT64 getEngine2VibN1() { return get_named_variable_value(Engine2VibN1); }
FLOAT64 getEngine1VibN2() { return get_named_variable_value(Engine1VibN2); }
FLOAT64 getEngine2VibN2() { return get_named_variable_value(Engine2VibN2); }
FLOAT64 getEngine2VibN2() { return get_named_variable_value(Engine2VibN2); }
FLOAT64 getEngine1PreFF() { return get_named_variable_value(Engine1PreFF); }
FLOAT64 getEngine2PreFF() { return get_named_variable_value(Engine2PreFF); }
FLOAT64 getEngineImbalance() { return get_named_variable_value(EngineImbalance); }
Expand Down Expand Up @@ -378,6 +378,9 @@ class SimVars {
FLOAT64 getNAI(int index) { return aircraft_varget(NacelleAntiIce, m_Units->Bool, index); }
FLOAT64 getPump(int index) { return aircraft_varget(FuelPump, m_Units->Number, index); }
FLOAT64 getValve(int index) { return aircraft_varget(FuelValve, m_Units->Number, index); }
/// @brief Gets a fuel line flow rate in gallons/hour
/// @param index Index of the fuel line
/// @return Fuel line flow rate in gallons/hour
FLOAT64 getLineFlow(int index) { return aircraft_varget(FuelLineFlow, m_Units->Gph, index); }
FLOAT64 getJunctionSetting(int index) { return aircraft_varget(FuelJunctionSetting, m_Units->Number, index); }
};
};
Loading