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:
Matthew Kennedy 2020-09-06 16:06:32 -07:00 committed by GitHub
parent f010e8555d
commit 6e7d72170f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 32 additions and 38 deletions

View File

@ -62,7 +62,6 @@
#include "cdm_ion_sense.h"
#include "binary_logging.h"
extern afr_Map3D_t afrMap;
extern bool main_loop_started;
#if EFI_PROD_CODE
@ -606,12 +605,12 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_
// 288
tsOutputChannels->injectionOffset = engine->engineState.injectionOffset;
// offset 112
tsOutputChannels->veValue = engine->engineState.currentVe;
tsOutputChannels->currentTargetAfr = ENGINE(engineState.targetAFR);
if (hasMapSensor(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
tsOutputChannels->manifoldAirPressure = mapValue;
}

View File

@ -1,4 +1,7 @@
#include "airmass.h"
#include "sensor.h"
EXTERN_ENGINE;
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);
// 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;
}

View File

@ -14,7 +14,7 @@ AirmassResult AlphaNAirmass::getAirmass(int rpm) {
// TODO: should this be barometric pressure and/or temperature compensated?
float airmass = getAirmassImpl(
ve / 100.0f,
ve,
101.325f, // std atmosphere pressure
273.0f + 20.0f // std atmosphere pressure
PASS_ENGINE_PARAMETER_SUFFIX

View File

@ -37,7 +37,7 @@ AirmassResult MafAirmass::getAirmassImpl(float massAirFlow, int rpm) const {
float airChargeLoad = 100 * cylinderAirmass / ENGINE(standardAirCharge);
//Correct air mass by VE table
float correctedAirmass = cylinderAirmass * getVe(rpm, airChargeLoad) / 100;
float correctedAirmass = cylinderAirmass * getVe(rpm, airChargeLoad);
return {
correctedAirmass,

View File

@ -26,7 +26,9 @@ AirmassResult SpeedDensityAirmass::getAirmass(int rpm) {
float adjustedMap = engine->engineState.sd.adjustedManifoldAirPressure = map + engine->engineState.sd.manifoldAirPressureAccelerationAdjustment;
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)) {
warning(CUSTOM_ERR_6685, "NaN airMass");
return {};

View File

@ -171,32 +171,8 @@ void EngineState::periodicFastCallback(DECLARE_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);
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;
}
auto tps = Sensor::get(SensorType::Tps1);
updateTChargeK(rpm, tps.value_or(0) PASS_ENGINE_PARAMETER_SUFFIX);
ENGINE(injectionDuration) = getInjectionDuration(rpm PASS_ENGINE_PARAMETER_SUFFIX);
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);
timingAdvance = getAdvance(rpm, ignitionLoad PASS_ENGINE_PARAMETER_SUFFIX);
multispark.count = getMultiSparkCount(rpm PASS_ENGINE_PARAMETER_SUFFIX);
#endif // EFI_ENGINE_CONTROL
}

View File

@ -59,7 +59,7 @@ public:
efitick_t timeSinceLastTChargeK;
float currentRawVE = 0;
float currentVe = 0;
int vssEventCounter = 0;

View File

@ -137,11 +137,13 @@ floatms_t getRunningFuel(floatms_t baseFuel DECLARE_ENGINE_PARAMETER_SUFFIX) {
float postCrankingFuelCorrection = ENGINE(engineState.DISPLAY_PREFIX(running).DISPLAY_FIELD(postCrankingFuelCorrection));
DISPLAY_TEXT(eol);
float baroCorrection = ENGINE(engineState.baroCorrection);
efiAssert(CUSTOM_ERR_ASSERT, !cisnan(iatCorrection), "NaN iatCorrection", 0);
efiAssert(CUSTOM_ERR_ASSERT, !cisnan(cltCorrection), "NaN cltCorrection", 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);
DISPLAY_TEXT(eol);

View File

@ -234,5 +234,5 @@ TEST(fuel, testTpsBasedVeDefect799) {
engine->engineState.periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
// value in the middle of the map as expected
ASSERT_EQ(107, engine->engineState.currentRawVE);
ASSERT_EQ(107, engine->engineState.currentVe);
}