decouple TPS accel enrichment from trigger (#3825)

* move call site

* move thresholding out of fast path

* adjust config

* test
This commit is contained in:
Matthew Kennedy 2022-01-23 12:31:39 -08:00 committed by GitHub
parent 6aac4b2f6d
commit b5232ab5e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 34 additions and 16 deletions

View File

@ -369,7 +369,6 @@ void setDodgeNeonNGCEngineConfiguration() {
engineConfiguration->canNbcType = CAN_BUS_NBC_BMW;
// engineConfiguration->canNbcType = CAN_BUS_MAZDA_RX8;
engineConfiguration->tpsAccelLength = 12;
engineConfiguration->tpsAccelEnrichmentThreshold = 10;
engineConfiguration->wwaeTau = 1.0f;

View File

@ -29,14 +29,11 @@ static tps_tps_Map3D_t tpsTpsMap;
floatms_t TpsAccelEnrichment::getTpsEnrichment() {
ScopePerf perf(PE::GetTpsEnrichment);
int maxDeltaIndex = getMaxDeltaIndex();
if (engineConfiguration->tpsAccelLookback == 0) {
// If disabled, return 0.
return 0;
}
tpsTo = cb.get(maxDeltaIndex);
tpsFrom = cb.get(maxDeltaIndex - 1);
deltaTps = tpsTo - tpsFrom;
isAboveAccelThreshold = deltaTps > engineConfiguration->tpsAccelEnrichmentThreshold;
isBelowDecelThreshold = deltaTps < -engineConfiguration->tpsDecelEnleanmentThreshold;
if (isAboveAccelThreshold) {
valueFromTable = tpsTpsMap.getValue(tpsFrom, tpsTo);
extraFuel = valueFromTable;
@ -119,7 +116,6 @@ void TpsAccelEnrichment::onEngineCycleTps() {
}
int TpsAccelEnrichment::getMaxDeltaIndex() {
int len = minI(cb.getSize(), cb.getCount());
tooShort = len < 2;
if (tooShort)
@ -166,7 +162,20 @@ void TpsAccelEnrichment::setLength(int length) {
}
void TpsAccelEnrichment::onNewValue(float currentValue) {
// Push new value in to the history buffer
cb.add(currentValue);
// Update deltas
int maxDeltaIndex = getMaxDeltaIndex();
tpsFrom = cb.get(maxDeltaIndex - 1);
tpsTo = cb.get(maxDeltaIndex);
deltaTps = tpsTo - tpsFrom;
// Update threshold detection
isAboveAccelThreshold = deltaTps > engineConfiguration->tpsAccelEnrichmentThreshold;
// TODO: can deltaTps actually be negative? Will this ever trigger?
isBelowDecelThreshold = deltaTps < -engineConfiguration->tpsDecelEnleanmentThreshold;
}
TpsAccelEnrichment::TpsAccelEnrichment() {
@ -208,7 +217,8 @@ void setTpsAccelLen(int length) {
}
void updateAccelParameters() {
setTpsAccelLen(engineConfiguration->tpsAccelLength);
constexpr float slowCallbackPeriodSecond = SLOW_CALLBACK_PERIOD_MS / 1000.0f;
setTpsAccelLen(engineConfiguration->tpsAccelLookback / slowCallbackPeriodSecond);
}
#endif /* ! EFI_UNIT_TEST */

View File

@ -231,7 +231,6 @@ void setDefaultFuel() {
// Decel fuel cut
setDefaultFuelCutParameters();
engineConfiguration->tpsAccelLength = 12;
engineConfiguration->tpsAccelEnrichmentThreshold = 40; // TPS % change, per engine cycle
#if !EFI_UNIT_TEST

View File

@ -221,6 +221,8 @@ void Engine::periodicSlowCallback() {
updateSlowSensors();
checkShutdown();
tpsAccelEnrichment.onNewValue(Sensor::getOrZero(SensorType::Tps1));
updateVrPwm();
#if EFI_FSIO

View File

@ -285,7 +285,6 @@ static void handleFuel(const bool limitedFuel, uint32_t trgEventIndex, int rpm,
efiAssertVoid(CUSTOM_STACK_6627, getCurrentRemainingStack() > 128, "lowstck#3");
efiAssertVoid(CUSTOM_ERR_6628, trgEventIndex < engine->engineCycleEventCount, "handleFuel/event index");
engine->tpsAccelEnrichment.onNewValue(Sensor::getOrZero(SensorType::Tps1));
if (trgEventIndex == 0) {
engine->tpsAccelEnrichment.onEngineCycleTps();
}

View File

@ -70,7 +70,7 @@
! Any time an incompatible change is made to the configuration format stored in flash,
! update this string to the current date! It is required to also update TS_SIGNATURE above
! when this happens.
#define FLASH_DATA_VERSION 10008
#define FLASH_DATA_VERSION 10009
#define LOG_DELIMITER "`"
@ -1171,7 +1171,8 @@ int16_t tps2Max;Full throttle#2. tpsMax value as 10 bit ADC value. Not Voltage!\
brain_pin_e LIS302DLCsPin;
int tpsAccelLength;+This is the number of engine cycles that the TPS position change can occur over, a longer duration will make the enrichment more active but too long may affect steady state driving, a good default is 30-60 cycles. ;"cycles", 1, 0, 1, 200, 0
uint8_t tpsAccelLookback;+How long to look back for TPS-based acceleration enrichment. Increasing this time will trigger enrichment for longer when a throttle position change occurs.;"sec", 0.05, 0, 0, 5, 2
uint8_t[3] unused1689;;"", 1,0,0,0,0
float tpsAccelEnrichmentThreshold;+Maximum change delta of TPS percentage over the 'length'. Actual TPS change has to be above this value in order for TPS/TPS acceleration to kick in.;"roc", 1, 0, 0, 200, 3
int engineLoadAccelLength;;"cycles", 1, 0, 1, 200, 0

View File

@ -3220,7 +3220,7 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00"
dialog = TpsAccelPanel, "TPS"
field = "Set 'Debug Mode' to see detailed 'TPS acceleration enrichment' diagnostics"
field = "Length", tpsAccelLength
field = "Length", tpsAccelLookback
field = "Accel Threshold", tpsAccelEnrichmentThreshold
field = "Decel Threshold", tpsDecelEnleanmentThreshold
; field = "Decel Multiplier", tpsDecelEnleanmentMultiplier

View File

@ -45,9 +45,16 @@ TEST(fuel, testTpsAccelEnrichmentScheduling) {
setOperationMode(engineConfiguration, FOUR_STROKE_CRANK_SENSOR);
engineConfiguration->useOnlyRisingEdgeForTrigger = true;
engineConfiguration->tpsAccelEnrichmentThreshold = 5;
engineConfiguration->tpsAccelLookback = 2;
eth.setTriggerType(TT_ONE);
Sensor::setMockValue(SensorType::Tps1, 0);
engine->periodicSlowCallback();
Sensor::setMockValue(SensorType::Tps1, 7);
engine->periodicSlowCallback();
eth.fireTriggerEvents2(/* count */ 4, 25 /* ms */);
ASSERT_EQ( 1200, Sensor::getOrZero(SensorType::Rpm)) << "RPM";
@ -57,7 +64,7 @@ TEST(fuel, testTpsAccelEnrichmentScheduling) {
Sensor::setMockValue(SensorType::Tps1, 70);
eth.fireTriggerEvents2(/* count */ 1, 25 /* ms */);
float expectedAEValue = 29.2;
float expectedAEValue = 7;
// it does not matter how many times we invoke 'getTpsEnrichment' - state does not change
for (int i = 0; i <20;i++) {
ASSERT_NEAR(expectedAEValue, engine->tpsAccelEnrichment.getTpsEnrichment(), EPS4D);
@ -95,6 +102,7 @@ TEST(fuel, testAccelEnrichmentFractionalTps) {
// setup
engineConfiguration->tpsAccelEnrichmentThreshold = 5;
engineConfiguration->tpsAccelLookback = 2;
// fill tps2tps map (todo: there should be a better way?)
static const float tpsTpsConst = 1.0f;