decouple TPS accel enrichment from trigger (#3825)
* move call site * move thresholding out of fast path * adjust config * test
This commit is contained in:
parent
a1647fd66e
commit
b07127614b
|
@ -369,7 +369,6 @@ void setDodgeNeonNGCEngineConfiguration() {
|
||||||
engineConfiguration->canNbcType = CAN_BUS_NBC_BMW;
|
engineConfiguration->canNbcType = CAN_BUS_NBC_BMW;
|
||||||
// engineConfiguration->canNbcType = CAN_BUS_MAZDA_RX8;
|
// engineConfiguration->canNbcType = CAN_BUS_MAZDA_RX8;
|
||||||
|
|
||||||
engineConfiguration->tpsAccelLength = 12;
|
|
||||||
engineConfiguration->tpsAccelEnrichmentThreshold = 10;
|
engineConfiguration->tpsAccelEnrichmentThreshold = 10;
|
||||||
|
|
||||||
engineConfiguration->wwaeTau = 1.0f;
|
engineConfiguration->wwaeTau = 1.0f;
|
||||||
|
|
|
@ -29,14 +29,11 @@ static tps_tps_Map3D_t tpsTpsMap;
|
||||||
floatms_t TpsAccelEnrichment::getTpsEnrichment() {
|
floatms_t TpsAccelEnrichment::getTpsEnrichment() {
|
||||||
ScopePerf perf(PE::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) {
|
if (isAboveAccelThreshold) {
|
||||||
valueFromTable = tpsTpsMap.getValue(tpsFrom, tpsTo);
|
valueFromTable = tpsTpsMap.getValue(tpsFrom, tpsTo);
|
||||||
extraFuel = valueFromTable;
|
extraFuel = valueFromTable;
|
||||||
|
@ -119,7 +116,6 @@ void TpsAccelEnrichment::onEngineCycleTps() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int TpsAccelEnrichment::getMaxDeltaIndex() {
|
int TpsAccelEnrichment::getMaxDeltaIndex() {
|
||||||
|
|
||||||
int len = minI(cb.getSize(), cb.getCount());
|
int len = minI(cb.getSize(), cb.getCount());
|
||||||
tooShort = len < 2;
|
tooShort = len < 2;
|
||||||
if (tooShort)
|
if (tooShort)
|
||||||
|
@ -166,7 +162,20 @@ void TpsAccelEnrichment::setLength(int length) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TpsAccelEnrichment::onNewValue(float currentValue) {
|
void TpsAccelEnrichment::onNewValue(float currentValue) {
|
||||||
|
// Push new value in to the history buffer
|
||||||
cb.add(currentValue);
|
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() {
|
TpsAccelEnrichment::TpsAccelEnrichment() {
|
||||||
|
@ -208,7 +217,8 @@ void setTpsAccelLen(int length) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateAccelParameters() {
|
void updateAccelParameters() {
|
||||||
setTpsAccelLen(engineConfiguration->tpsAccelLength);
|
constexpr float slowCallbackPeriodSecond = SLOW_CALLBACK_PERIOD_MS / 1000.0f;
|
||||||
|
setTpsAccelLen(engineConfiguration->tpsAccelLookback / slowCallbackPeriodSecond);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* ! EFI_UNIT_TEST */
|
#endif /* ! EFI_UNIT_TEST */
|
||||||
|
|
|
@ -231,7 +231,6 @@ void setDefaultFuel() {
|
||||||
// Decel fuel cut
|
// Decel fuel cut
|
||||||
setDefaultFuelCutParameters();
|
setDefaultFuelCutParameters();
|
||||||
|
|
||||||
engineConfiguration->tpsAccelLength = 12;
|
|
||||||
engineConfiguration->tpsAccelEnrichmentThreshold = 40; // TPS % change, per engine cycle
|
engineConfiguration->tpsAccelEnrichmentThreshold = 40; // TPS % change, per engine cycle
|
||||||
|
|
||||||
#if !EFI_UNIT_TEST
|
#if !EFI_UNIT_TEST
|
||||||
|
|
|
@ -221,6 +221,8 @@ void Engine::periodicSlowCallback() {
|
||||||
updateSlowSensors();
|
updateSlowSensors();
|
||||||
checkShutdown();
|
checkShutdown();
|
||||||
|
|
||||||
|
tpsAccelEnrichment.onNewValue(Sensor::getOrZero(SensorType::Tps1));
|
||||||
|
|
||||||
updateVrPwm();
|
updateVrPwm();
|
||||||
|
|
||||||
#if EFI_FSIO
|
#if EFI_FSIO
|
||||||
|
|
|
@ -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_STACK_6627, getCurrentRemainingStack() > 128, "lowstck#3");
|
||||||
efiAssertVoid(CUSTOM_ERR_6628, trgEventIndex < engine->engineCycleEventCount, "handleFuel/event index");
|
efiAssertVoid(CUSTOM_ERR_6628, trgEventIndex < engine->engineCycleEventCount, "handleFuel/event index");
|
||||||
|
|
||||||
engine->tpsAccelEnrichment.onNewValue(Sensor::getOrZero(SensorType::Tps1));
|
|
||||||
if (trgEventIndex == 0) {
|
if (trgEventIndex == 0) {
|
||||||
engine->tpsAccelEnrichment.onEngineCycleTps();
|
engine->tpsAccelEnrichment.onEngineCycleTps();
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@
|
||||||
! Any time an incompatible change is made to the configuration format stored in flash,
|
! 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
|
! update this string to the current date! It is required to also update TS_SIGNATURE above
|
||||||
! when this happens.
|
! when this happens.
|
||||||
#define FLASH_DATA_VERSION 10008
|
#define FLASH_DATA_VERSION 10009
|
||||||
|
|
||||||
#define LOG_DELIMITER "`"
|
#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;
|
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
|
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
|
int engineLoadAccelLength;;"cycles", 1, 0, 1, 200, 0
|
||||||
|
|
|
@ -3220,7 +3220,7 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00"
|
||||||
|
|
||||||
dialog = TpsAccelPanel, "TPS"
|
dialog = TpsAccelPanel, "TPS"
|
||||||
field = "Set 'Debug Mode' to see detailed 'TPS acceleration enrichment' diagnostics"
|
field = "Set 'Debug Mode' to see detailed 'TPS acceleration enrichment' diagnostics"
|
||||||
field = "Length", tpsAccelLength
|
field = "Length", tpsAccelLookback
|
||||||
field = "Accel Threshold", tpsAccelEnrichmentThreshold
|
field = "Accel Threshold", tpsAccelEnrichmentThreshold
|
||||||
field = "Decel Threshold", tpsDecelEnleanmentThreshold
|
field = "Decel Threshold", tpsDecelEnleanmentThreshold
|
||||||
; field = "Decel Multiplier", tpsDecelEnleanmentMultiplier
|
; field = "Decel Multiplier", tpsDecelEnleanmentMultiplier
|
||||||
|
|
|
@ -45,9 +45,16 @@ TEST(fuel, testTpsAccelEnrichmentScheduling) {
|
||||||
setOperationMode(engineConfiguration, FOUR_STROKE_CRANK_SENSOR);
|
setOperationMode(engineConfiguration, FOUR_STROKE_CRANK_SENSOR);
|
||||||
engineConfiguration->useOnlyRisingEdgeForTrigger = true;
|
engineConfiguration->useOnlyRisingEdgeForTrigger = true;
|
||||||
|
|
||||||
|
engineConfiguration->tpsAccelEnrichmentThreshold = 5;
|
||||||
|
engineConfiguration->tpsAccelLookback = 2;
|
||||||
|
|
||||||
eth.setTriggerType(TT_ONE);
|
eth.setTriggerType(TT_ONE);
|
||||||
|
|
||||||
|
|
||||||
|
Sensor::setMockValue(SensorType::Tps1, 0);
|
||||||
|
engine->periodicSlowCallback();
|
||||||
Sensor::setMockValue(SensorType::Tps1, 7);
|
Sensor::setMockValue(SensorType::Tps1, 7);
|
||||||
|
engine->periodicSlowCallback();
|
||||||
|
|
||||||
eth.fireTriggerEvents2(/* count */ 4, 25 /* ms */);
|
eth.fireTriggerEvents2(/* count */ 4, 25 /* ms */);
|
||||||
ASSERT_EQ( 1200, Sensor::getOrZero(SensorType::Rpm)) << "RPM";
|
ASSERT_EQ( 1200, Sensor::getOrZero(SensorType::Rpm)) << "RPM";
|
||||||
|
@ -57,7 +64,7 @@ TEST(fuel, testTpsAccelEnrichmentScheduling) {
|
||||||
Sensor::setMockValue(SensorType::Tps1, 70);
|
Sensor::setMockValue(SensorType::Tps1, 70);
|
||||||
eth.fireTriggerEvents2(/* count */ 1, 25 /* ms */);
|
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
|
// it does not matter how many times we invoke 'getTpsEnrichment' - state does not change
|
||||||
for (int i = 0; i <20;i++) {
|
for (int i = 0; i <20;i++) {
|
||||||
ASSERT_NEAR(expectedAEValue, engine->tpsAccelEnrichment.getTpsEnrichment(), EPS4D);
|
ASSERT_NEAR(expectedAEValue, engine->tpsAccelEnrichment.getTpsEnrichment(), EPS4D);
|
||||||
|
@ -95,6 +102,7 @@ TEST(fuel, testAccelEnrichmentFractionalTps) {
|
||||||
|
|
||||||
// setup
|
// setup
|
||||||
engineConfiguration->tpsAccelEnrichmentThreshold = 5;
|
engineConfiguration->tpsAccelEnrichmentThreshold = 5;
|
||||||
|
engineConfiguration->tpsAccelLookback = 2;
|
||||||
|
|
||||||
// fill tps2tps map (todo: there should be a better way?)
|
// fill tps2tps map (todo: there should be a better way?)
|
||||||
static const float tpsTpsConst = 1.0f;
|
static const float tpsTpsConst = 1.0f;
|
||||||
|
|
Loading…
Reference in New Issue