Skip to content

Commit

Permalink
fix(fadec): fuel consumption at higher simrates
Browse files Browse the repository at this point in the history
FBW PR 8636

fix
  • Loading branch information
Revyn112 committed Oct 23, 2024
1 parent c31887b commit a3d6ca3
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CMakeLists-A333X.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ add_definitions(
-DNO_EXAMPLES
#PROFILING | NO_PROFILING - for logging of profiling information of pre-, post-, update() calls
-DNO_PROFILING
# disable MSFS header min/max macros which clobber std::min/max
-DNOMINMAX
# MSFS stdlib uses 64-bit off_t for lseek etc.
-D_FILE_OFFSET_BITS=64
)

# add the common components
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists-A339X.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ add_definitions(
-DNO_EXAMPLES
#PROFILING | NO_PROFILING - for logging of profiling information of pre-, post-, update() calls
-DNO_PROFILING
# disable MSFS header min/max macros which clobber std::min/max
-DNOMINMAX
# MSFS stdlib uses 64-bit off_t for lseek etc.
-D_FILE_OFFSET_BITS=64
)

# add the common components
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists-SU95X.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ add_definitions(
-DNO_EXAMPLES
#PROFILING | NO_PROFILING - for logging of profiling information of pre-, post-, update() calls
-DNO_PROFILING
# disable MSFS header min/max macros which clobber std::min/max
-DNOMINMAX
# MSFS stdlib uses 64-bit off_t for lseek etc.
-D_FILE_OFFSET_BITS=64
)

# add the common components
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2023-2024 FlyByWire Simulations
// SPDX-License-Identifier: GPL-3.0


#include "logging.h"
#ifdef PROFILING
#include "ScopedTimer.hpp"
Expand All @@ -14,6 +13,8 @@
#include "Tables1502_A32NX.hpp"
#include "ThrustLimits_A32NX.hpp"

#include <algorithm>

void EngineControl_A32NX::initialize(MsfsHandler* msfsHandler) {
this->msfsHandlerPtr = msfsHandler;
this->dataManagerPtr = &msfsHandler->getDataManager();
Expand All @@ -25,7 +26,7 @@ void EngineControl_A32NX::shutdown() {
LOG_INFO("Fadec::EngineControl_A32NX::shutdown()");
}

void EngineControl_A32NX::update(sGaugeDrawData* pData) {
void EngineControl_A32NX::update() {
#ifdef PROFILING
profilerUpdate.start();
#endif
Expand All @@ -43,7 +44,7 @@ void EngineControl_A32NX::update(sGaugeDrawData* pData) {
return;
}

const double deltaTime = pData->dt;
const double deltaTime = std::max(0.002, msfsHandlerPtr->getSimulationDeltaTime());
const double simTime = msfsHandlerPtr->getSimulationTime();
const double mach = simData.simVarsDataPtr->data().airSpeedMach;
const double pressureAltitude = simData.simVarsDataPtr->data().pressureAltitude;
Expand Down Expand Up @@ -556,7 +557,7 @@ double EngineControl_A32NX::updateFF(int engine,
// Checking Fuel Logic and final Fuel Flow
double outFlow = 0;
if (correctedFuelFlow >= 1) {
outFlow = (std::max)(0.0, //
outFlow = std::max(0.0, //
(correctedFuelFlow * Fadec::LBS_TO_KGS * EngineRatios::delta2(mach, ambientPressure) //
* (std::sqrt)(EngineRatios::theta2(mach, ambientTemperature))) //
- paramImbalance); //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,8 @@ class EngineControl_A32NX {

/**
* @brief Updates the EngineControl_A32NX class once per frame.
* @param pData
*/
void update(sGaugeDrawData* pData);
void update();

/**
* @brief Shuts down the EngineControl_A32NX class once during the gauge shutdown.
Expand Down
4 changes: 2 additions & 2 deletions hdw-a339x/src/wasm/fadec_a339x/src/Fadec/Fadec_A32NX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ bool Fadec_A32NX::initialize() {
return true;
}

bool Fadec_A32NX::update(sGaugeDrawData* pData) {
bool Fadec_A32NX::update([[maybe_unused]] sGaugeDrawData* pData) {
if (!_isInitialized) {
std::cerr << "Fadec_A32NX::update() - not initialized" << std::endl;
return false;
}

engineControl.update(pData);
engineControl.update();

return true;
}
Expand Down
7 changes: 5 additions & 2 deletions scripts/build-cmake-a333x.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
# Use set +x and set +v to turn off the above settings
#set -x

# exit early with status if the script fails
set -e

# get directory of this script relative to root
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
pushd "${DIR}" || exit
Expand Down Expand Up @@ -47,8 +50,8 @@ wasm-ld --version
echo ""

echo "Building extra-backend with CMAKE..."
cmake -DCMAKE_TOOLCHAIN_FILE=scripts/cmake/DockerToolchain.cmake -B${OUTPUT_DIR} -DCMAKE_BUILD_TYPE=${CONFIG} ../ || (echo "CMake config failed" && exit 1)
cmake --build ${OUTPUT_DIR} --config ${CONFIG} ${CLEAN} -j ${PARALLEL} || (echo "CMake build failed" && exit 1)
cmake -DCMAKE_TOOLCHAIN_FILE=scripts/cmake/DockerToolchain.cmake -B${OUTPUT_DIR} -DCMAKE_BUILD_TYPE=${CONFIG} ../ || (echo "CMake config failed"; exit 1)
cmake --build ${OUTPUT_DIR} --config ${CONFIG} ${CLEAN} -j ${PARALLEL} || (echo "CMake build failed"; exit 1)
echo ""

echo "WASM module built successfully!"
Expand Down
7 changes: 5 additions & 2 deletions scripts/build-cmake-a339x.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
# Use set +x and set +v to turn off the above settings
#set -x

# exit early with status if the script fails
set -e

# get directory of this script relative to root
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
pushd "${DIR}" || exit
Expand Down Expand Up @@ -47,8 +50,8 @@ wasm-ld --version
echo ""

echo "Building extra-backend with CMAKE..."
cmake -DCMAKE_TOOLCHAIN_FILE=scripts/cmake/DockerToolchain.cmake -B${OUTPUT_DIR} -DCMAKE_BUILD_TYPE=${CONFIG} ../ || (echo "CMake config failed" && exit 1)
cmake --build ${OUTPUT_DIR} --config ${CONFIG} ${CLEAN} -j ${PARALLEL} || (echo "CMake build failed" && exit 1)
cmake -DCMAKE_TOOLCHAIN_FILE=scripts/cmake/DockerToolchain.cmake -B${OUTPUT_DIR} -DCMAKE_BUILD_TYPE=${CONFIG} ../ || (echo "CMake config failed"; exit 1)
cmake --build ${OUTPUT_DIR} --config ${CONFIG} ${CLEAN} -j ${PARALLEL} || (echo "CMake build failed"; exit 1)
echo ""

echo "WASM module built successfully!"
Expand Down
7 changes: 5 additions & 2 deletions scripts/build-cmake-su95x.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
# Use set +x and set +v to turn off the above settings
#set -x

# exit early with status if the script fails
set -e

# get directory of this script relative to root
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
pushd "${DIR}" || exit
Expand Down Expand Up @@ -47,8 +50,8 @@ wasm-ld --version
echo ""

echo "Building extra-backend with CMAKE..."
cmake -DCMAKE_TOOLCHAIN_FILE=scripts/cmake/DockerToolchain.cmake -B${OUTPUT_DIR} -DCMAKE_BUILD_TYPE=${CONFIG} ../ || (echo "CMake config failed" && exit 1)
cmake --build ${OUTPUT_DIR} --config ${CONFIG} ${CLEAN} -j ${PARALLEL} || (echo "CMake build failed" && exit 1)
cmake -DCMAKE_TOOLCHAIN_FILE=scripts/cmake/DockerToolchain.cmake -B${OUTPUT_DIR} -DCMAKE_BUILD_TYPE=${CONFIG} ../ || (echo "CMake config failed"; exit 1)
cmake --build ${OUTPUT_DIR} --config ${CONFIG} ${CLEAN} -j ${PARALLEL} || (echo "CMake build failed"; exit 1)
echo ""

echo "WASM module built successfully!"
Expand Down

0 comments on commit a3d6ca3

Please sign in to comment.