Integrate stft (#1475)

* code changes

* missed a spot

* update UI

* gauge name

* adjust gauge scaling

Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
Matthew Kennedy 2020-05-31 13:59:05 -07:00 committed by GitHub
parent 76277ee6d8
commit d24b5d5e93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 50 additions and 55 deletions

View File

@ -127,7 +127,7 @@ typedef struct {
scaled_percent iatCorrection; // 64
scaled_percent cltCorrection; // 66
scaled_percent baroCorrection; // 68
scaled_ms fuelPidCorrection; // 70
scaled_percent shortTermFuelTrim; // 70
// Wall model AE
scaled_ms wallFuelAmount; // 72

View File

@ -27,7 +27,7 @@ static const LogField fields[] = {
{tsOutputChannels.veValue, GAUGE_NAME_FUEL_VE, "%", 1},
{tsOutputChannels.tCharge, "tCharge", "C", 1},
{tsOutputChannels.injectorLagMs, GAUGE_NAME_INJECTOR_LAG, "ms", 3},
{tsOutputChannels.fuelPidCorrection, GAUGE_NAME_FUEL_PID_CORR, "ms", 3},
{tsOutputChannels.shortTermFuelTrim, GAUGE_NAME_FUEL_PID_CORR, "%", 3},
{tsOutputChannels.wallFuelCorrection, GAUGE_NAME_FUEL_WALL_CORRECTION, "ms", 3},
{tsOutputChannels.tpsAccelFuel, GAUGE_NAME_FUEL_TPS_EXTRA, "ms", 3},
{tsOutputChannels.ignitionAdvance, GAUGE_NAME_TIMING_ADVANCE, "deg", 1},

View File

@ -582,7 +582,7 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_
// 120
tsOutputChannels->firmwareVersion = getRusEfiVersion();
// 268
tsOutputChannels->fuelPidCorrection = ENGINE(engineState.running.pidCorrection);
tsOutputChannels->shortTermFuelTrim = 100.0f * (ENGINE(engineState.running.pidCorrection) - 1.0f);
// 276
tsOutputChannels->accelerationX = engine->sensors.accelerometer.x;
// 278

View File

@ -16,6 +16,7 @@
#include "advance_map.h"
#include "aux_valves.h"
#include "perf_trace.h"
#include "closed_loop_fuel.h"
#include "sensor.h"
#if EFI_PROD_CODE
@ -146,6 +147,8 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
// todo: move this into slow callback, no reason for CLT corr to be here
running.coolantTemperatureCoefficient = getCltFuelCorrection(PASS_ENGINE_PARAMETER_SIGNATURE);
running.pidCorrection = fuelClosedLoopCorrection(PASS_ENGINE_PARAMETER_SIGNATURE);
// update fuel consumption states
fuelConsumption.update(nowNt PASS_ENGINE_PARAMETER_SUFFIX);

View File

@ -125,7 +125,7 @@ floatms_t getRunningFuel(floatms_t baseFuel DECLARE_ENGINE_PARAMETER_SUFFIX) {
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 * iatCorrection * cltCorrection * postCrankingFuelCorrection * ENGINE(engineState.running.pidCorrection);
efiAssert(CUSTOM_ERR_ASSERT, !cisnan(runningFuel), "NaN runningFuel", 0);
DISPLAY_TEXT(eol);

View File

@ -58,9 +58,6 @@ static const char *prevOutputName = nullptr;
static InjectionEvent primeInjEvent;
static Logging *logger;
#if ! EFI_UNIT_TEST
static Pid fuelPid(&persistentState.persistentConfiguration.engineConfiguration.fuelClosedLoopPid);
#endif
// todo: figure out if this even helps?
//#if defined __GNUC__
@ -284,30 +281,6 @@ void handleFuelInjectionEvent(int injEventIndex, InjectionEvent *event,
#endif /* EFI_DEFAILED_LOGGING */
}
static void fuelClosedLoopCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
#if ! EFI_UNIT_TEST
if (GET_RPM_VALUE < CONFIG(fuelClosedLoopRpmThreshold) ||
Sensor::get(SensorType::Clt).value_or(0) < CONFIG(fuelClosedLoopCltThreshold) ||
Sensor::get(SensorType::Tps1).value_or(100) > CONFIG(fuelClosedLoopTpsThreshold) ||
ENGINE(sensors.currentAfr) < CONFIG(fuelClosedLoopAfrLowThreshold) ||
ENGINE(sensors.currentAfr) > engineConfiguration->fuelClosedLoopAfrHighThreshold) {
engine->engineState.running.pidCorrection = 0;
fuelPid.reset();
return;
}
engine->engineState.running.pidCorrection = fuelPid.getOutput(ENGINE(engineState.targetAFR), ENGINE(sensors.currentAfr), NOT_TIME_BASED_PID);
if (engineConfiguration->debugMode == DBG_FUEL_PID_CORRECTION) {
#if EFI_TUNER_STUDIO
tsOutputChannels.debugFloatField1 = engine->engineState.running.pidCorrection;
fuelPid.postState(&tsOutputChannels);
#endif /* EFI_TUNER_STUDIO */
}
#endif
}
static ALWAYS_INLINE void handleFuel(const bool limitedFuel, uint32_t trgEventIndex, int rpm, efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) {
ScopePerf perf(PE::HandleFuel);
@ -442,10 +415,6 @@ static void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t trgEvent
// we need this to apply new 'triggerIndexByAngle' values
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
}
if (CONFIG(fuelClosedLoopCorrectionEnabled)) {
fuelClosedLoopCorrection(PASS_ENGINE_PARAMETER_SIGNATURE);
}
}
efiAssertVoid(CUSTOM_IGN_MATH_STATE, !CONFIG(useOnlyRisingEdgeForTrigger) || CONFIG(ignMathCalculateAtIndex) % 2 == 0, "invalid ignMathCalculateAtIndex");

View File

@ -1484,7 +1484,7 @@ end_struct
#define GAUGE_NAME_FUEL_RUNNING "fuel: running"
#define GAUGE_NAME_FUEL_LAST_INJECTION "fuel: Last injection"
#define GAUGE_NAME_FUEL_BASE "fuel: base"
#define GAUGE_NAME_FUEL_PID_CORR "fuel: Short-term closed loop correction"
#define GAUGE_NAME_FUEL_PID_CORR "fuel: Short-term fuel trim"
#define GAUGE_NAME_FUEL_WALL_AMOUNT "fuel: wall amount"
#define GAUGE_NAME_FUEL_WALL_CORRECTION "fuel: wall corr ms"

View File

@ -264,7 +264,7 @@ enable2ndByteCanID = false
iatCorrection = scalar, S16, 64, "%",{1/@@PACK_MULT_PERCENT@@}, 0
cltCorrection = scalar, S16, 66, "%",{1/@@PACK_MULT_PERCENT@@}, 0
baroCorrection = scalar, S16, 68, "%",{1/@@PACK_MULT_PERCENT@@}, 0
fuelPidCorrection=scalar, S16, 70, "ms",{1/@@PACK_MULT_MS@@}, 0
fuelPidCorrection=scalar, S16, 70, "ms",{1/@@PACK_MULT_PERCENT@@}, 0
; Wall model AE
wallFuelAmount = scalar, U16, 72, "ms",{1/@@PACK_MULT_MS@@}, 0
@ -999,7 +999,7 @@ gaugeCategory = Fueling
injectorLagMsGauge = injectorLagMs, @@GAUGE_NAME_INJECTOR_LAG@@, "mSec", 0, 25.5, 1.0, 1.2, 20, 25, 3, 1
fuelRunningGauge = fuelRunning, @@GAUGE_NAME_FUEL_RUNNING@@, "mSec", 0, 25.5, 1.0, 1.2, 20, 25, 3, 1
baseFuelGauge = baseFuel, @@GAUGE_NAME_FUEL_BASE@@, "mSec", 0, 25.5, 1.0, 1.2, 20, 25, 3, 1
fuelPidCorrectionGauge = fuelPidCorrection, @@GAUGE_NAME_FUEL_PID_CORR@@, "mSec", -11, 11, 1.0, 1.2, 20, 25, 3, 1
fuelPidCorrectionGauge = fuelPidCorrection, @@GAUGE_NAME_FUEL_PID_CORR@@, "%", -10, 10, -8, -5, 5, 8, 3, 1
gaugeCategory = Throttle Body (incl. ETB)
pedalPositionGauge = throttlePedalPosition, @@GAUGE_NAME_THROTTLE_PEDAL@@, "%", 0, 120, 0, 0, 100, 100, 1, 1
@ -1271,7 +1271,7 @@ menuDialog = main
# Targets & closed loop
subMenu = afrTableTbl, "Target AFR", 0, {isInjectionEnabled == 1 && (fuelAlgorithm == LM_SPEED_DENSITY || fuelAlgorithm == LM_REAL_MAF)}
subMenu = fuelClosedLoopDialog, "Closed loop correction", 0, {isInjectionEnabled == 1}
subMenu = fuelClosedLoopDialog, "Closed loop fuel correction", 0, {isInjectionEnabled == 1}
subMenu = coastingFuelCutControl, "Deceleration fuel cutoff (DFCO)", 0, {isInjectionEnabled == 1}
subMenu = std_separator
@ -2433,23 +2433,46 @@ cmd_set_engine_type_default = "w\x00\x31\x00\x00"
field = "SPI3sck mode", spi3SckMode, {is_enabled_spi_3 == 1}
field = "LIS302DLCsPin", LIS302DLCsPin
dialog = fuelClosedLoopDialog, "Fuel short-term closed-loop correction"
field = "#This is just the cherry on the cake once you have good VE table"
field = "Enabled", fuelClosedLoopCorrectionEnabled
field = "!No correction below these value"
field = "CLT - low threshod", fuelClosedLoopCltThreshold, {fuelClosedLoopCorrectionEnabled == 1}
field = "RPM - low threshod", fuelClosedLoopRpmThreshold, {fuelClosedLoopCorrectionEnabled == 1}
field = "EGO - low threshod", fuelClosedLoopAfrLowThreshold, {fuelClosedLoopCorrectionEnabled == 1}
field = "!No correction above these value"
field = "TPS - high threshod", fuelClosedLoopTpsThreshold, {fuelClosedLoopCorrectionEnabled == 1}
field = "EGO - high threshod", fuelClosedLoopAfrHighThreshold, {fuelClosedLoopCorrectionEnabled == 1}
field = "!PID settings"
field = "P factor", fuelClosedLoopPid_pFactor, {fuelClosedLoopCorrectionEnabled == 1}
field = "I factor", fuelClosedLoopPid_iFactor, {fuelClosedLoopCorrectionEnabled == 1}
field = "D factor", fuelClosedLoopPid_dFactor, {fuelClosedLoopCorrectionEnabled == 1}
field = "min", fuelClosedLoopPid_minValue, {fuelClosedLoopCorrectionEnabled == 1}
field = "max", fuelClosedLoopPid_maxValue, {fuelClosedLoopCorrectionEnabled == 1}
dialog = stftPartitioning, "Region Configuration"
field = "Idle region RPM", stft_maxIdleRegionRpm
field = "Overrun region load", stft_maxOverrunLoad
field = "Power region load", stft_minPowerLoad
dialog = stftPartitionSettingsMain, "Main Region", xAxis
field = "Time Const", stft_cellCfgs4_timeConstant
field = "Max add", stft_cellCfgs4_maxAdd
field = "Max remove", stft_cellCfgs4_maxRemove
dialog = stftPartitionSettingsIdle, "Idle Region", xAxis
field = "Time Const", stft_cellCfgs1_timeConstant
field = "Max add", stft_cellCfgs1_maxAdd
field = "Max remove", stft_cellCfgs1_maxRemove
dialog = stftPartitionSettingsPower, "Power Region", xAxis
field = "Time Const", stft_cellCfgs3_timeConstant
field = "Max add", stft_cellCfgs3_maxAdd
field = "Max remove", stft_cellCfgs3_maxRemove
dialog = stftPartitionSettingsOverrun, "Overrun Region", xAxis
field = "Time Const", stft_cellCfgs2_timeConstant
field = "Max add", stft_cellCfgs2_maxAdd
field = "Max remove", stft_cellCfgs2_maxRemove
dialog = fuelClosedLoopDialog, "Short-term fuel trim"
field = "Enabled", fuelClosedLoopCorrectionEnabled
field = "Startup delay" stft_startupDelay, {fuelClosedLoopCorrectionEnabled == 1}
field = "Minimum CLT for correction", stft_minClt, {fuelClosedLoopCorrectionEnabled == 1}
field = "Minimum AFR for correction", stft_minAfr, {fuelClosedLoopCorrectionEnabled == 1}
field = "Maximum AFR for correction", stft_maxAfr, {fuelClosedLoopCorrectionEnabled == 1}
field = "Adjustment deadband", stft_deadband, {fuelClosedLoopCorrectionEnabled == 1}
field = "Ignore error magnitude", stftIgnoreErrorMagnitude, {fuelClosedLoopCorrectionEnabled == 1}
panel = stftPartitioning, {fuelClosedLoopCorrectionEnabled == 1}
panel = stftPartitionSettingsMain, {fuelClosedLoopCorrectionEnabled == 1}
panel = stftPartitionSettingsIdle, {fuelClosedLoopCorrectionEnabled == 1}
panel = stftPartitionSettingsPower, {fuelClosedLoopCorrectionEnabled == 1}
panel = stftPartitionSettingsOverrun, {fuelClosedLoopCorrectionEnabled == 1}
dialog = auxPidDialog, "Aux PID"
field = "Enabled", activateAuxPid1