From 00a4adf5cf4076ca6c28f50ba465b5147dd79a76 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Fri, 22 Dec 2023 21:41:31 -0800 Subject: [PATCH] clamp injector model baro values to avoid whacky sensor killing engine --- firmware/controllers/algo/fuel/injector_model.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/firmware/controllers/algo/fuel/injector_model.cpp b/firmware/controllers/algo/fuel/injector_model.cpp index 48583a009b..464e950dba 100644 --- a/firmware/controllers/algo/fuel/injector_model.cpp +++ b/firmware/controllers/algo/fuel/injector_model.cpp @@ -52,14 +52,19 @@ InjectorNonlinearMode InjectorModel::getNonlinearMode() const { expected InjectorModel::getFuelDifferentialPressure() const { auto map = Sensor::get(SensorType::Map); - float baro = Sensor::get(SensorType::BarometricPressure).value_or(101.325f); + auto baro = Sensor::get(SensorType::BarometricPressure); + + float baroKpa = baro.Value; + if (!baro || baro.Value > 120 || baro.Value < 50) { + baroKpa = 101.325f; + } switch (engineConfiguration->injectorCompensationMode) { case ICM_FixedRailPressure: // Add barometric pressure, as "fixed" really means "fixed pressure above atmosphere" return engineConfiguration->fuelReferencePressure - + baro + + baroKpa - map.value_or(101.325); case ICM_SensedRailPressure: { if (!Sensor::hasSensor(SensorType::FuelPressureInjector)) { @@ -83,7 +88,7 @@ expected InjectorModel::getFuelDifferentialPressure() const { return unexpected; } - return fps.Value + baro - map.Value; + return fps.Value + baroKpa - map.Value; case FPM_Absolute: default: if (!map) {