Skip to content

Commit

Permalink
Migration A380X done - debugging & testing
Browse files Browse the repository at this point in the history
  • Loading branch information
frankkopp committed Mar 19, 2024
1 parent 15f7370 commit b5eb550
Show file tree
Hide file tree
Showing 14 changed files with 1,061 additions and 1,414 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ add_definitions(
# EXAMPLES | NO_EXAMPLES
-DNO_EXAMPLES
#PROFILING | NO_PROFILING - for logging of profiling information of pre-, post-, update() calls
-DPROFILING
-DNO_PROFILING
)

# add the common components
Expand Down
3 changes: 1 addition & 2 deletions fbw-a32nx/src/wasm/fadec_a320/src/EngineControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,6 @@ class EngineControl {
double ambientTemp,
double ambientPressure,
double mach,
double simN1highest,
double packs,
double nai,
double wai) {
Expand Down Expand Up @@ -1303,7 +1302,7 @@ class EngineControl {

updateFuel(deltaTime);

updateThrustLimits(simulationTime, pressAltitude, ambientTemp, ambientPressure, mach, simN1highest, packs, nai, wai);
updateThrustLimits(simulationTime, pressAltitude, ambientTemp, ambientPressure, mach, packs, nai, wai);
// timer.elapsed();
}

Expand Down
55 changes: 27 additions & 28 deletions fbw-a32nx/src/wasm/fadec_a32nx/src/Fadec/EngineControlA32NX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ void EngineControl_A32NX::update(sGaugeDrawData* pData) {
}

const double mach = simData.simVarsDataPtr->data().airSpeedMach;
const double pressAltitude = simData.simVarsDataPtr->data().pressureAltitude;
const double ambientTemp = simData.simVarsDataPtr->data().ambientTemperature;
const double pressureAltitude = simData.simVarsDataPtr->data().pressureAltitude;
const double ambientTemperature = simData.simVarsDataPtr->data().ambientTemperature;
const double ambientPressure = simData.simVarsDataPtr->data().ambientPressure;
const double imbalance = simData.engineImbalance->get();
const double idleN2 = simData.engineIdleN2->get();
Expand All @@ -51,7 +51,7 @@ void EngineControl_A32NX::update(sGaugeDrawData* pData) {
const int nai = (simData.simVarsDataPtr->data().engineAntiIce[L] > 0.5 || simData.simVarsDataPtr->data().engineAntiIce[R] > 0.5) ? 1 : 0;
const int wai = simData.wingAntiIce->getAsInt64();

generateIdleParameters(pressAltitude, mach, ambientTemp, ambientPressure);
generateIdleParameters(pressureAltitude, mach, ambientTemperature, ambientPressure);

bool engineStarter;
double engineIgniter;
Expand Down Expand Up @@ -103,25 +103,25 @@ void EngineControl_A32NX::update(sGaugeDrawData* pData) {
engineMasterTurnedOff, //
simN2, //
idleN2, //
ambientTemp); //
ambientTemperature); //

double cFbwFF;
double correctedFuelFlow;
switch (engineState) {
case STARTING:
case RESTARTING:
if (engineStarter) {
engineStartProcedure(engine, engineState, imbalance, pData->dt, engineTimer, simN2, pressAltitude, ambientTemp);
engineStartProcedure(engine, engineState, imbalance, pData->dt, engineTimer, simN2, pressureAltitude, ambientTemperature);
break;
}
case SHUTTING:
engineShutdownProcedure(engine, ambientTemp, simN1, pData->dt, engineTimer);
cFbwFF = updateFF(engine, imbalance, simCN1, mach, pressAltitude, ambientTemp, ambientPressure);
engineShutdownProcedure(engine, ambientTemperature, simN1, pData->dt, engineTimer);
correctedFuelFlow = updateFF(engine, imbalance, simCN1, mach, pressureAltitude, ambientTemperature, ambientPressure);
break;
default:
updatePrimaryParameters(engine, imbalance, simN1, simN2);
cFbwFF = updateFF(engine, imbalance, simCN1, mach, pressAltitude, ambientTemp, ambientPressure);
updateEGT(engine, imbalance, pData->dt, msfsHandlerPtr->getSimOnGround(), engineState, simCN1, cFbwFF, mach, pressAltitude,
ambientTemp);
correctedFuelFlow = updateFF(engine, imbalance, simCN1, mach, pressureAltitude, ambientTemperature, ambientPressure);
updateEGT(engine, imbalance, pData->dt, msfsHandlerPtr->getSimOnGround(), engineState, simCN1, correctedFuelFlow, mach,
pressureAltitude, ambientTemperature);
// updateOil(engine, imbalance, thrust, simN2, deltaN2, deltaTime, ambientTemp);
}

Expand All @@ -132,7 +132,8 @@ void EngineControl_A32NX::update(sGaugeDrawData* pData) {
}

updateFuel(pData->dt);
updateThrustLimits(msfsHandlerPtr->getSimulationTime(), pressAltitude, ambientTemp, ambientPressure, mach, simN1highest, packs, nai, wai);
updateThrustLimits(msfsHandlerPtr->getSimulationTime(), pressureAltitude, ambientTemperature, ambientPressure, mach, simN1highest, packs,
nai, wai);

#ifdef PROFILING
profilerUpdate.stop();
Expand Down Expand Up @@ -192,7 +193,7 @@ void EngineControl_A32NX::initializeEngineControlData() {
oilTemperaturePre[L] = simData.simVarsDataPtr->data().ambientTemperature;
oilTemperaturePre[R] = simData.simVarsDataPtr->data().ambientTemperature;
}
simData.oilTempLeftDataPtr->data().oilTempLeft = oilTemperaturePre[L];
simData.oilTempLeftDataPtr->data().oilTempE1 = oilTemperaturePre[L];
simData.oilTempRightDataPtr->data().oilTempRight = oilTemperaturePre[R];
simData.oilTempLeftDataPtr->writeDataToSim();
simData.oilTempRightDataPtr->writeDataToSim();
Expand All @@ -206,14 +207,14 @@ void EngineControl_A32NX::initializeEngineControlData() {
simData.engineTimer[R]->set(0);

// Initialize Fuel Tanks
const double fuelWeightGallon = simData.simVarsDataPtr->data().fuelWeightPerGallon; // weight of gallon of jet A in lbs

const double centerQuantity = simData.simVarsDataPtr->data().fuelTankQuantityCenter; // gal
const double leftQuantity = simData.simVarsDataPtr->data().fuelTankQuantityLeft; // gal
const double rightQuantity = simData.simVarsDataPtr->data().fuelTankQuantityRight; // gal
const double leftAuxQuantity = simData.simVarsDataPtr->data().fuelTankQuantityLeftAux; // gal
const double rightAuxQuantity = simData.simVarsDataPtr->data().fuelTankQuantityRightAux; // gal

const double fuelWeightGallon = simData.simVarsDataPtr->data().fuelWeightPerGallon; // weight of gallon of jet A in lbs

// only loads saved fuel quantity on C/D spawn
if (simData.startState->updateFromSim(timeStamp, tickCounter) == 2) {
simData.fuelCenterPre->set(fuelConfiguration.getFuelCenter() * fuelWeightGallon); // in LBS
Expand All @@ -228,6 +229,7 @@ void EngineControl_A32NX::initializeEngineControlData() {
simData.fuelAuxLeftPre->set(leftAuxQuantity * fuelWeightGallon); // in LBS
simData.fuelAuxRightPre->set(rightAuxQuantity * fuelWeightGallon); // in LBS
}

// Initialize Pump State
simData.fuelPumpState[L]->set(0);
simData.fuelPumpState[R]->set(0);
Expand Down Expand Up @@ -297,10 +299,7 @@ double EngineControl_A32NX::imbalanceExtractor(double imbalanceCode, int paramet
return static_cast<int>(imbalanceCode) % 100;
}

void EngineControl_A32NX::generateIdleParameters(double pressAltitude, //
double mach, //
double ambientTemp, //
double ambientPressure) { //
void EngineControl_A32NX::generateIdleParameters(double pressAltitude, double mach, double ambientTemp, double ambientPressure) {
const double idleCN1 = Tables1502_A32NX::iCN1(pressAltitude, mach, ambientTemp);
const double idleN1 = idleCN1 * sqrt(EngineRatios::theta2(0, ambientTemp));
const double idleN2 = Tables1502_A32NX::iCN2(pressAltitude, mach) * sqrt(EngineRatios::theta(ambientTemp));
Expand Down Expand Up @@ -470,7 +469,7 @@ void EngineControl_A32NX::engineStartProcedure(int engine,

switch (engine) {
case 1:
simData.oilTempLeftDataPtr->data().oilTempLeft = oilTemperature;
simData.oilTempLeftDataPtr->data().oilTempE1 = oilTemperature;
simData.oilTempLeftDataPtr->writeDataToSim();
break;
case 2:
Expand Down Expand Up @@ -539,7 +538,7 @@ double EngineControl_A32NX::updateFF(int engine,
profilerUpdateFF.start();
#endif

double correctedFuelFlow = Polynomial_A32NX::correctedFuelFlow(simCN1, mach, pressAltitude); // in lbs/hr.
const double correctedFuelFlow = Polynomial_A32NX::correctedFuelFlow(simCN1, mach, pressAltitude); // in lbs/hr.

// Check which engine is imbalanced and set the imbalance parameter
const double engineImbalanced = imbalanceExtractor(imbalance, 1);
Expand Down Expand Up @@ -782,9 +781,9 @@ void EngineControl_A32NX::updateFuel(double deltaTimeSeconds) {
fuelLeftAux = (fuelAuxLeftPre / fuelWeightGallon); // USG
fuelRightAux = (fuelAuxRightPre / fuelWeightGallon); // USG

simData.fuelLRDataPtr->data().fuelLeftMain = fuelLeft;
simData.fuelLRDataPtr->data().fuelRightMain = fuelRight;
simData.fuelLRDataPtr->writeDataToSim();
simData.fuelFeedTankDataPtr->data().fuelLeftMain = fuelLeft;
simData.fuelFeedTankDataPtr->data().fuelRightMain = fuelRight;
simData.fuelFeedTankDataPtr->writeDataToSim();

simData.fuelCandAuxDataPtr->data().fuelCenter = fuelCenter;
simData.fuelCandAuxDataPtr->data().fuelLeftAux = fuelLeftAux;
Expand Down Expand Up @@ -931,6 +930,7 @@ void EngineControl_A32NX::updateFuel(double deltaTimeSeconds) {
simData.enginePreFF[R]->set(engine2FF);
simData.engineFuelUsed[L]->set(fuelUsedLeft);
simData.engineFuelUsed[R]->set(fuelUsedRight);

simData.fuelAuxLeftPre->set(leftAuxQuantity);
simData.fuelAuxRightPre->set(rightAuxQuantity);
simData.fuelCenterPre->set(centerQuantity);
Expand All @@ -941,9 +941,9 @@ void EngineControl_A32NX::updateFuel(double deltaTimeSeconds) {
fuelLeft = (fuelLeft / fuelWeightGallon); // USG
fuelRight = (fuelRight / fuelWeightGallon); // USG

simData.fuelLRDataPtr->data().fuelLeftMain = fuelLeft;
simData.fuelLRDataPtr->data().fuelRightMain = fuelRight;
simData.fuelLRDataPtr->writeDataToSim();
simData.fuelFeedTankDataPtr->data().fuelLeftMain = fuelLeft;
simData.fuelFeedTankDataPtr->data().fuelRightMain = fuelRight;
simData.fuelFeedTankDataPtr->writeDataToSim();
}

//--------------------------------------------
Expand Down Expand Up @@ -1033,7 +1033,6 @@ void EngineControl_A32NX::updateThrustLimits(double simulationTime,
}

double deltaThrust = 0;

if (isTransitionActive) {
double timeDifference = (std::max)(0.0, (simulationTime - transitionStartTime) - transitionWaitTime);
if (timeDifference > 0 && clb > flex) {
Expand Down
31 changes: 16 additions & 15 deletions fbw-a32nx/src/wasm/fadec_a32nx/src/Fadec/FadecSimData_A32NX.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class FadecSimData_A32NX {
*/
DataDefinitionVariablePtr<AtcIdData> atcIdDataPtr;

struct FuelLRData {
struct FuelFeedTankData {
FLOAT64 fuelLeftMain;
FLOAT64 fuelRightMain;
};
Expand All @@ -57,9 +57,9 @@ class FadecSimData_A32NX {
* @var FLOAT64 fuelLeftMain The fuel quantity of the left main tank in gallons.
* @var FLOAT64 fuelRightMain The fuel quantity of the right main tank in gallons.
*/
DataDefinitionVariablePtr<FuelLRData> fuelLRDataPtr;
DataDefinitionVariablePtr<FuelFeedTankData> fuelFeedTankDataPtr;

struct FuelCandAuxData {
struct FuelTankData {
FLOAT64 fuelCenter;
FLOAT64 fuelLeftAux;
FLOAT64 fuelRightAux;
Expand All @@ -78,10 +78,10 @@ class FadecSimData_A32NX {
* @var FLOAT64 fuelLeftAux The fuel quantity of the left aux tank in gallons.
* @var FLOAT64 fuelRightAux The fuel quantity of the right aux tank in gallons.
*/
DataDefinitionVariablePtr<FuelCandAuxData> fuelCandAuxDataPtr;
DataDefinitionVariablePtr<FuelTankData> fuelCandAuxDataPtr;

struct OliTempLeftData {
FLOAT64 oilTempLeft;
struct OliTempE1Data {
FLOAT64 oilTempE1;
};
DataDefinitionVector oilTempLeftDataDef = {
{"GENERAL ENG OIL TEMPERATURE", 1, UNITS.Celsius} //
Expand All @@ -92,7 +92,7 @@ class FadecSimData_A32NX {
* @UpdateFrequncey: manual write only
* @var FLOAT64 oilTempLeft The oil temperature of the left engine in Celsius.
*/
DataDefinitionVariablePtr<OliTempLeftData> oilTempLeftDataPtr;
DataDefinitionVariablePtr<OliTempE1Data> oilTempLeftDataPtr;

struct OliTempRightData {
FLOAT64 oilTempRight;
Expand All @@ -108,7 +108,7 @@ class FadecSimData_A32NX {
*/
DataDefinitionVariablePtr<OliTempRightData> oilTempRightDataPtr;

struct OilPsiLeftData {
struct OilPsiData {
FLOAT64 oilPsiLeft;
};
DataDefinitionVector oilPsiLeftDataDef = {
Expand All @@ -120,7 +120,7 @@ class FadecSimData_A32NX {
* @UpdateFrequncey: manual write only
* @var FLOAT64 oilPsiLeft The oil pressure of the left engine in Psi.
*/
DataDefinitionVariablePtr<OilPsiLeftData> oilPsiLeftDataPtr;
DataDefinitionVariablePtr<OilPsiData> oilPsiDataPtr;

struct OilPsiRightData {
FLOAT64 oilPsiRight;
Expand Down Expand Up @@ -282,14 +282,15 @@ class FadecSimData_A32NX {

void initDataDefinitions(DataManager* dm) {
atcIdDataPtr = dm->make_datadefinition_var<AtcIdData>("ATC ID DATA", atcIdDataDef, NO_AUTO_UPDATE);
fuelLRDataPtr = dm->make_datadefinition_var<FuelLRData>("FUEL LR DATA", fuelLRDataDef, NO_AUTO_UPDATE);
fuelCandAuxDataPtr = dm->make_datadefinition_var<FuelCandAuxData>("FUEL CAND AUX DATA", fuelCandAuxDataDef, NO_AUTO_UPDATE);
oilTempLeftDataPtr = dm->make_datadefinition_var<OliTempLeftData>("OIL TEMP LEFT DATA", oilTempLeftDataDef, NO_AUTO_UPDATE);
fuelFeedTankDataPtr = dm->make_datadefinition_var<FuelFeedTankData>("FUEL LR DATA", fuelLRDataDef, NO_AUTO_UPDATE);
fuelCandAuxDataPtr = dm->make_datadefinition_var<FuelTankData>("FUEL CAND AUX DATA", fuelCandAuxDataDef, NO_AUTO_UPDATE);
oilTempLeftDataPtr = dm->make_datadefinition_var<OliTempE1Data>("OIL TEMP LEFT DATA", oilTempLeftDataDef, NO_AUTO_UPDATE);
oilTempRightDataPtr = dm->make_datadefinition_var<OliTempRightData>("OIL TEMP RIGHT DATA", oilTempRightDataDef, NO_AUTO_UPDATE);
oilPsiLeftDataPtr = dm->make_datadefinition_var<OilPsiLeftData>("OIL PSI LEFT DATA", oilPsiLeftDataDef, NO_AUTO_UPDATE);
oilPsiDataPtr = dm->make_datadefinition_var<OilPsiData>("OIL PSI LEFT DATA", oilPsiLeftDataDef, NO_AUTO_UPDATE);
oilPsiRightDataPtr = dm->make_datadefinition_var<OilPsiRightData>("OIL PSI RIGHT DATA", oilPsiRightDataDef, NO_AUTO_UPDATE);

simVarsDataPtr = dm->make_datadefinition_var<SimVarsData>("SIMVARS DATA", simVarsDataDef, AUTO_READ);
simVarsDataPtr = dm->make_datadefinition_var<SimVarsData>("SIMVARS DATA", simVarsDataDef);
simVarsDataPtr->requestPeriodicDataFromSim(SIMCONNECT_PERIOD_VISUAL_FRAME);
}

void initEvents(DataManager* dm) {
Expand Down Expand Up @@ -368,7 +369,7 @@ class FadecSimData_A32NX {
apuRpmPercent = dm->make_named_var("A32NX_APU_N_RAW", UNITS.Number, AUTO_READ);
engineStarterPressurized[L] = dm->make_named_var("A32NX_PNEU_ENG_1_STARTER_PRESSURIZED", UNITS.Number, AUTO_READ);
engineStarterPressurized[R] = dm->make_named_var("A32NX_PNEU_ENG_2_STARTER_PRESSURIZED", UNITS.Number, AUTO_READ);
packsState[L] = dm->make_named_var("A32NX_COND_PACK_FLOW_VALVE_1_IS_OPEN:1", UNITS.Number, AUTO_READ);
packsState[L] = dm->make_named_var("A32NX_COND_PACK_FLOW_VALVE_1_IS_OPEN", UNITS.Number, AUTO_READ);
packsState[R] = dm->make_named_var("A32NX_COND_PACK_FLOW_VALVE_2_IS_OPEN", UNITS.Number, AUTO_READ);
refuelRate = dm->make_named_var("A32NX_EFB_REFUEL_RATE_SETTING", UNITS.Number, AUTO_READ);
refuelStartedByUser = dm->make_named_var("A32NX_REFUEL_STARTED_BY_USR", UNITS.Number, AUTO_READ);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Position, EngineNumber, FadecActive } from '@instruments/common/types';
import React from 'react';

const IgnitionBorder: React.FC<Position & EngineNumber & FadecActive> = ({ x, y, engine, active }) => {
const [engineState] = useSimVar(`L:A32NX_ENGINE_STATE:${engine}`, 'bool', 500);
const [engineState] = useSimVar(`L:A32NX_ENGINE_STATE:${engine}`, 'enum', 500);
const [N1Percent] = useSimVar(`L:A32NX_ENGINE_N1:${engine}`, 'percent', 100);
const [N1Idle] = useSimVar('L:A32NX_ENGINE_IDLE_N1', 'percent', 1000);
const showBorder = !!((N1Percent < Math.floor(N1Idle) - 1) && (engineState === 2));
Expand Down
3 changes: 1 addition & 2 deletions fbw-a380x/src/wasm/fadec_a380/src/EngineControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,6 @@ class EngineControl {
double ambientTemp,
double ambientPressure,
double mach,
double simN1highest,
double packs,
double nai,
double wai) {
Expand Down Expand Up @@ -1470,7 +1469,7 @@ class EngineControl {

updateFuel(deltaTime);

updateThrustLimits(simulationTime, pressAltitude, ambientTemp, ambientPressure, mach, simN1highest, packs, nai, wai);
updateThrustLimits(simulationTime, pressAltitude, ambientTemp, ambientPressure, mach, packs, nai, wai);
// timer.elapsed();
}

Expand Down
13 changes: 7 additions & 6 deletions fbw-a380x/src/wasm/fadec_a380/src/FadecGauge.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,18 @@ class FadecGauge {
SimConnect_AddToDataDefinition(hSimConnect, DataTypesID::PayloadStation8, "PAYLOAD STATION WEIGHT:8", "Pounds");

// SimConnect Tanker Definitions
SimConnect_AddToDataDefinition(hSimConnect, DataTypesID::FuelSystemLeftOuter, "FUELSYSTEM TANK QUANTITY:1", "Gallons");
SimConnect_AddToDataDefinition(hSimConnect, DataTypesID::FuelSystemFeedOne, "FUELSYSTEM TANK QUANTITY:2", "Gallons");
SimConnect_AddToDataDefinition(hSimConnect, DataTypesID::FuelSystemLeftMid, "FUELSYSTEM TANK QUANTITY:3", "Gallons");
SimConnect_AddToDataDefinition(hSimConnect, DataTypesID::FuelSystemLeftInner, "FUELSYSTEM TANK QUANTITY:4", "Gallons");
SimConnect_AddToDataDefinition(hSimConnect, DataTypesID::FuelSystemFeedTwo, "FUELSYSTEM TANK QUANTITY:5", "Gallons");
SimConnect_AddToDataDefinition(hSimConnect, DataTypesID::FuelSystemFeedThree, "FUELSYSTEM TANK QUANTITY:6", "Gallons");
SimConnect_AddToDataDefinition(hSimConnect, DataTypesID::FuelSystemRightInner, "FUELSYSTEM TANK QUANTITY:7", "Gallons");
SimConnect_AddToDataDefinition(hSimConnect, DataTypesID::FuelSystemRightMid, "FUELSYSTEM TANK QUANTITY:8", "Gallons");
SimConnect_AddToDataDefinition(hSimConnect, DataTypesID::FuelSystemFeedFour, "FUELSYSTEM TANK QUANTITY:9", "Gallons");

SimConnect_AddToDataDefinition(hSimConnect, DataTypesID::FuelSystemLeftOuter, "FUELSYSTEM TANK QUANTITY:1", "Gallons");
SimConnect_AddToDataDefinition(hSimConnect, DataTypesID::FuelSystemLeftMid, "FUELSYSTEM TANK QUANTITY:3", "Gallons");
SimConnect_AddToDataDefinition(hSimConnect, DataTypesID::FuelSystemLeftInner, "FUELSYSTEM TANK QUANTITY:4", "Gallons");
SimConnect_AddToDataDefinition(hSimConnect, DataTypesID::FuelSystemRightInner, "FUELSYSTEM TANK QUANTITY:7", "Gallons");
SimConnect_AddToDataDefinition(hSimConnect, DataTypesID::FuelSystemRightMid, "FUELSYSTEM TANK QUANTITY:8", "Gallons");
SimConnect_AddToDataDefinition(hSimConnect, DataTypesID::FuelSystemRightOuter, "FUELSYSTEM TANK QUANTITY:10", "Gallons");
SimConnect_AddToDataDefinition(hSimConnect, DataTypesID::FuelSystemTrim, "FUELSYSTEM TANK QUANTITY:11", "Gallons");
SimConnect_AddToDataDefinition(hSimConnect, DataTypesID::FuelSystemTrim, "FUELSYSTEM TANK QUANTITY:11", "Gallons");

// SimConnect Oil Temperature Definitions
SimConnect_AddToDataDefinition(hSimConnect, DataTypesID::OilTempEngine1, "GENERAL ENG OIL TEMPERATURE:1", "Celsius");
Expand Down
1 change: 0 additions & 1 deletion fbw-a380x/src/wasm/fadec_a380x/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ include_directories(
${FBW_COMMON}/fadec_common_v2/src/
)


# define the source files
set(SOURCE_FILES
${FBW_COMMON}/fadec_common_v2/src/Fadec.cpp
Expand Down
Loading

0 comments on commit b5eb550

Please sign in to comment.