Move ve logic (#1762)
* move ve * fix build * fix rendering * duh * cleaning * correct scaling * put some back Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
parent
f010e8555d
commit
6e7d72170f
|
@ -62,7 +62,6 @@
|
||||||
#include "cdm_ion_sense.h"
|
#include "cdm_ion_sense.h"
|
||||||
#include "binary_logging.h"
|
#include "binary_logging.h"
|
||||||
|
|
||||||
extern afr_Map3D_t afrMap;
|
|
||||||
extern bool main_loop_started;
|
extern bool main_loop_started;
|
||||||
|
|
||||||
#if EFI_PROD_CODE
|
#if EFI_PROD_CODE
|
||||||
|
@ -606,12 +605,12 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_
|
||||||
// 288
|
// 288
|
||||||
tsOutputChannels->injectionOffset = engine->engineState.injectionOffset;
|
tsOutputChannels->injectionOffset = engine->engineState.injectionOffset;
|
||||||
|
|
||||||
|
// offset 112
|
||||||
|
tsOutputChannels->veValue = engine->engineState.currentVe;
|
||||||
|
tsOutputChannels->currentTargetAfr = ENGINE(engineState.targetAFR);
|
||||||
|
|
||||||
if (hasMapSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) {
|
if (hasMapSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) {
|
||||||
float mapValue = getMap(PASS_ENGINE_PARAMETER_SIGNATURE);
|
float mapValue = getMap(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
// // offset 112
|
|
||||||
tsOutputChannels->veValue = engine->engineState.currentBaroCorrectedVE * PERCENT_MULT;
|
|
||||||
// todo: bug here? target afr could work based on real MAF?
|
|
||||||
tsOutputChannels->currentTargetAfr = afrMap.getValue(rpm, mapValue);
|
|
||||||
// offset 40
|
// offset 40
|
||||||
tsOutputChannels->manifoldAirPressure = mapValue;
|
tsOutputChannels->manifoldAirPressure = mapValue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
#include "airmass.h"
|
#include "airmass.h"
|
||||||
|
#include "sensor.h"
|
||||||
|
|
||||||
|
EXTERN_ENGINE;
|
||||||
|
|
||||||
AirmassModelBase::AirmassModelBase(const ValueProvider3D& veTable) : m_veTable(&veTable) {}
|
AirmassModelBase::AirmassModelBase(const ValueProvider3D& veTable) : m_veTable(&veTable) {}
|
||||||
|
|
||||||
|
@ -6,5 +9,16 @@ float AirmassModelBase::getVe(int rpm, float load) const {
|
||||||
efiAssert(OBD_PCM_Processor_Fault, m_veTable != nullptr, "VE table null", 0);
|
efiAssert(OBD_PCM_Processor_Fault, m_veTable != nullptr, "VE table null", 0);
|
||||||
|
|
||||||
// TODO: allow override of the Y axis value based on a config field
|
// TODO: allow override of the Y axis value based on a config field
|
||||||
return m_veTable->getValue(rpm, load);
|
float ve = m_veTable->getValue(rpm, load);
|
||||||
|
|
||||||
|
auto tps = Sensor::get(SensorType::Tps1);
|
||||||
|
// get VE from the separate table for Idle
|
||||||
|
if (tps.Valid && CONFIG(useSeparateVeForIdle)) {
|
||||||
|
float idleVe = interpolate2d("idleVe", rpm, config->idleVeBins, config->idleVe);
|
||||||
|
// interpolate between idle table and normal (running) table using TPS threshold
|
||||||
|
ve = interpolateClamped(0.0f, idleVe, CONFIG(idlePidDeactivationTpsThreshold), ve, tps.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
ENGINE(engineState.currentVe) = ve;
|
||||||
|
return ve * 0.01f;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ AirmassResult AlphaNAirmass::getAirmass(int rpm) {
|
||||||
|
|
||||||
// TODO: should this be barometric pressure and/or temperature compensated?
|
// TODO: should this be barometric pressure and/or temperature compensated?
|
||||||
float airmass = getAirmassImpl(
|
float airmass = getAirmassImpl(
|
||||||
ve / 100.0f,
|
ve,
|
||||||
101.325f, // std atmosphere pressure
|
101.325f, // std atmosphere pressure
|
||||||
273.0f + 20.0f // std atmosphere pressure
|
273.0f + 20.0f // std atmosphere pressure
|
||||||
PASS_ENGINE_PARAMETER_SUFFIX
|
PASS_ENGINE_PARAMETER_SUFFIX
|
||||||
|
|
|
@ -37,7 +37,7 @@ AirmassResult MafAirmass::getAirmassImpl(float massAirFlow, int rpm) const {
|
||||||
float airChargeLoad = 100 * cylinderAirmass / ENGINE(standardAirCharge);
|
float airChargeLoad = 100 * cylinderAirmass / ENGINE(standardAirCharge);
|
||||||
|
|
||||||
//Correct air mass by VE table
|
//Correct air mass by VE table
|
||||||
float correctedAirmass = cylinderAirmass * getVe(rpm, airChargeLoad) / 100;
|
float correctedAirmass = cylinderAirmass * getVe(rpm, airChargeLoad);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
correctedAirmass,
|
correctedAirmass,
|
||||||
|
|
|
@ -26,7 +26,9 @@ AirmassResult SpeedDensityAirmass::getAirmass(int rpm) {
|
||||||
float adjustedMap = engine->engineState.sd.adjustedManifoldAirPressure = map + engine->engineState.sd.manifoldAirPressureAccelerationAdjustment;
|
float adjustedMap = engine->engineState.sd.adjustedManifoldAirPressure = map + engine->engineState.sd.manifoldAirPressureAccelerationAdjustment;
|
||||||
efiAssert(CUSTOM_ERR_ASSERT, !cisnan(adjustedMap), "NaN adjustedMap", {});
|
efiAssert(CUSTOM_ERR_ASSERT, !cisnan(adjustedMap), "NaN adjustedMap", {});
|
||||||
|
|
||||||
float airMass = getAirmassImpl(ENGINE(engineState.currentBaroCorrectedVE), adjustedMap, tChargeK PASS_ENGINE_PARAMETER_SUFFIX);
|
float ve = getVe(rpm, adjustedMap);
|
||||||
|
|
||||||
|
float airMass = getAirmassImpl(ve, adjustedMap, tChargeK PASS_ENGINE_PARAMETER_SUFFIX);
|
||||||
if (cisnan(airMass)) {
|
if (cisnan(airMass)) {
|
||||||
warning(CUSTOM_ERR_6685, "NaN airMass");
|
warning(CUSTOM_ERR_6685, "NaN airMass");
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -171,32 +171,8 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
|
|
||||||
baroCorrection = getBaroCorrection(PASS_ENGINE_PARAMETER_SIGNATURE);
|
baroCorrection = getBaroCorrection(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
|
||||||
multispark.count = getMultiSparkCount(rpm PASS_ENGINE_PARAMETER_SUFFIX);
|
|
||||||
|
|
||||||
if (engineConfiguration->fuelAlgorithm == LM_SPEED_DENSITY) {
|
|
||||||
auto tps = Sensor::get(SensorType::Tps1);
|
auto tps = Sensor::get(SensorType::Tps1);
|
||||||
updateTChargeK(rpm, tps.value_or(0) PASS_ENGINE_PARAMETER_SUFFIX);
|
updateTChargeK(rpm, tps.value_or(0) PASS_ENGINE_PARAMETER_SUFFIX);
|
||||||
float map = getMap(PASS_ENGINE_PARAMETER_SIGNATURE);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* *0.01 because of https://sourceforge.net/p/rusefi/tickets/153/
|
|
||||||
*/
|
|
||||||
if (CONFIG(useTPSBasedVeTable)) {
|
|
||||||
// todo: should we have 'veTpsMap' fuel_Map3D_t variable here?
|
|
||||||
currentRawVE = interpolate3d<float, float>(tps.value_or(50), CONFIG(ignitionTpsBins), IGN_TPS_COUNT, rpm, config->veRpmBins, FUEL_RPM_COUNT, veMap.pointers);
|
|
||||||
} else {
|
|
||||||
currentRawVE = veMap.getValue(rpm, map);
|
|
||||||
}
|
|
||||||
|
|
||||||
// get VE from the separate table for Idle
|
|
||||||
if (tps.Valid && CONFIG(useSeparateVeForIdle)) {
|
|
||||||
float idleVe = interpolate2d("idleVe", rpm, config->idleVeBins, config->idleVe);
|
|
||||||
// interpolate between idle table and normal (running) table using TPS threshold
|
|
||||||
currentRawVE = interpolateClamped(0.0f, idleVe, CONFIG(idlePidDeactivationTpsThreshold), currentRawVE, tps.Value);
|
|
||||||
}
|
|
||||||
currentBaroCorrectedVE = baroCorrection * currentRawVE * PERCENT_DIV;
|
|
||||||
}
|
|
||||||
|
|
||||||
ENGINE(injectionDuration) = getInjectionDuration(rpm PASS_ENGINE_PARAMETER_SUFFIX);
|
ENGINE(injectionDuration) = getInjectionDuration(rpm PASS_ENGINE_PARAMETER_SUFFIX);
|
||||||
|
|
||||||
float fuelLoad = getFuelingLoad(PASS_ENGINE_PARAMETER_SIGNATURE);
|
float fuelLoad = getFuelingLoad(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
@ -204,6 +180,7 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
|
|
||||||
float ignitionLoad = getIgnitionLoad(PASS_ENGINE_PARAMETER_SIGNATURE);
|
float ignitionLoad = getIgnitionLoad(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
timingAdvance = getAdvance(rpm, ignitionLoad PASS_ENGINE_PARAMETER_SUFFIX);
|
timingAdvance = getAdvance(rpm, ignitionLoad PASS_ENGINE_PARAMETER_SUFFIX);
|
||||||
|
multispark.count = getMultiSparkCount(rpm PASS_ENGINE_PARAMETER_SUFFIX);
|
||||||
#endif // EFI_ENGINE_CONTROL
|
#endif // EFI_ENGINE_CONTROL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ public:
|
||||||
|
|
||||||
efitick_t timeSinceLastTChargeK;
|
efitick_t timeSinceLastTChargeK;
|
||||||
|
|
||||||
float currentRawVE = 0;
|
float currentVe = 0;
|
||||||
|
|
||||||
int vssEventCounter = 0;
|
int vssEventCounter = 0;
|
||||||
|
|
||||||
|
|
|
@ -137,11 +137,13 @@ floatms_t getRunningFuel(floatms_t baseFuel DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||||
float postCrankingFuelCorrection = ENGINE(engineState.DISPLAY_PREFIX(running).DISPLAY_FIELD(postCrankingFuelCorrection));
|
float postCrankingFuelCorrection = ENGINE(engineState.DISPLAY_PREFIX(running).DISPLAY_FIELD(postCrankingFuelCorrection));
|
||||||
DISPLAY_TEXT(eol);
|
DISPLAY_TEXT(eol);
|
||||||
|
|
||||||
|
float baroCorrection = ENGINE(engineState.baroCorrection);
|
||||||
|
|
||||||
efiAssert(CUSTOM_ERR_ASSERT, !cisnan(iatCorrection), "NaN iatCorrection", 0);
|
efiAssert(CUSTOM_ERR_ASSERT, !cisnan(iatCorrection), "NaN iatCorrection", 0);
|
||||||
efiAssert(CUSTOM_ERR_ASSERT, !cisnan(cltCorrection), "NaN cltCorrection", 0);
|
efiAssert(CUSTOM_ERR_ASSERT, !cisnan(cltCorrection), "NaN cltCorrection", 0);
|
||||||
efiAssert(CUSTOM_ERR_ASSERT, !cisnan(postCrankingFuelCorrection), "NaN postCrankingFuelCorrection", 0);
|
efiAssert(CUSTOM_ERR_ASSERT, !cisnan(postCrankingFuelCorrection), "NaN postCrankingFuelCorrection", 0);
|
||||||
|
|
||||||
floatms_t runningFuel = baseFuel * iatCorrection * cltCorrection * postCrankingFuelCorrection * ENGINE(engineState.running.pidCorrection);
|
floatms_t runningFuel = baseFuel * baroCorrection * iatCorrection * cltCorrection * postCrankingFuelCorrection * ENGINE(engineState.running.pidCorrection);
|
||||||
efiAssert(CUSTOM_ERR_ASSERT, !cisnan(runningFuel), "NaN runningFuel", 0);
|
efiAssert(CUSTOM_ERR_ASSERT, !cisnan(runningFuel), "NaN runningFuel", 0);
|
||||||
DISPLAY_TEXT(eol);
|
DISPLAY_TEXT(eol);
|
||||||
|
|
||||||
|
|
|
@ -234,5 +234,5 @@ TEST(fuel, testTpsBasedVeDefect799) {
|
||||||
|
|
||||||
engine->engineState.periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
|
engine->engineState.periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
// value in the middle of the map as expected
|
// value in the middle of the map as expected
|
||||||
ASSERT_EQ(107, engine->engineState.currentRawVE);
|
ASSERT_EQ(107, engine->engineState.currentVe);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue