trigger tweaks cleanup (#4278)

* simplify some math

* we say yes to the todo

* and put back that test

* test
This commit is contained in:
Matthew Kennedy 2022-06-23 20:11:29 -07:00 committed by GitHub
parent 4cc285e8da
commit fcd3d991ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 18 deletions

View File

@ -310,9 +310,9 @@ void hwHandleVvtCamSignal(trigger_value_e front, efitick_t nowNt, int index) {
return;
}
angle_t currentPosition = currentPhase.Value;
// convert engine cycle angle into trigger cycle angle
currentPosition -= tdcPosition();
angle_t angleFromPrimarySyncPoint = currentPhase.Value;
// convert trigger cycle angle into engine cycle angle
angle_t currentPosition = angleFromPrimarySyncPoint - tdcPosition();
// https://github.com/rusefi/rusefi/issues/1713 currentPosition could be negative that's expected
#if EFI_UNIT_TEST
@ -366,9 +366,9 @@ void hwHandleVvtCamSignal(trigger_value_e front, efitick_t nowNt, int index) {
default:
// else, do nothing
break;
}
}
if (absF(vvtPosition - tdcPosition()) < 7) {
if (absF(angleFromPrimarySyncPoint) < 7) {
/**
* we prefer not to have VVT sync right at trigger sync so that we do not have phase detection error if things happen a bit in
* wrong order due to belt flex or else

View File

@ -83,6 +83,7 @@ void TriggerDecoderBase::resetTriggerState() {
void TriggerDecoderBase::setTriggerErrorState() {
m_timeSinceDecodeError.reset();
totalTriggerErrorCounter++;
}
void TriggerDecoderBase::resetCurrentCycleState() {
@ -518,11 +519,8 @@ expected<TriggerDecodeResult> TriggerDecoderBase::decodeTriggerEvent(
}
#endif /* EFI_UNIT_TEST */
/**
* For less important events we simply increment the index.
*/
nextTriggerEvent()
;
// For less important events we simply increment the index.
nextTriggerEvent();
} else {
#if !EFI_PROD_CODE
if (printTriggerTrace) {
@ -657,7 +655,6 @@ expected<TriggerDecodeResult> TriggerDecoderBase::decodeTriggerEvent(
// so we clear the synchronized flag.
if (wasSynchronized && isDecodingError) {
setTriggerErrorState();
totalTriggerErrorCounter++;
// Something wrong, no longer synchronized
setShaftSynchronized(false);
@ -670,13 +667,11 @@ expected<TriggerDecodeResult> TriggerDecoderBase::decodeTriggerEvent(
}
// this call would update duty cycle values
nextTriggerEvent()
;
nextTriggerEvent();
onShaftSynchronization(wasSynchronized, nowNt, triggerShape);
} else { /* if (!isSynchronizationPoint) */
nextTriggerEvent()
;
nextTriggerEvent();
}
for (int i = triggerShape.gapTrackingLength; i > 0; i--) {
@ -694,8 +689,6 @@ expected<TriggerDecodeResult> TriggerDecoderBase::decodeTriggerEvent(
if (Sensor::getOrZero(SensorType::Rpm) != 0) {
warning(CUSTOM_SYNC_ERROR, "sync error for %s: index #%d above total size %d", name, currentCycle.current_index, triggerShape.getSize());
setTriggerErrorState();
// TODO: should we increment totalTriggerErrorCounter here too?
}
onTriggerError();

View File

@ -167,6 +167,9 @@ TEST(TriggerDecoder, TooManyTeeth_CausesError) {
EXPECT_TRUE(dut.getShaftSynchronized());
EXPECT_EQ(0, dut.currentCycle.current_index);
// Fake that we have RPM so that all trigger error detection is enabled
Sensor::setMockValue(SensorType::Rpm, 1000);
t += MS2NT(1);
doTooth(dut, shape, cfg, t);
EXPECT_TRUE(dut.getShaftSynchronized());
@ -176,12 +179,16 @@ TEST(TriggerDecoder, TooManyTeeth_CausesError) {
doTooth(dut, shape, cfg, t);
EXPECT_TRUE(dut.getShaftSynchronized());
EXPECT_EQ(4, dut.currentCycle.current_index);
EXPECT_EQ(0, dut.totalTriggerErrorCounter);
// This tooth is extra - expect a call to onTriggerError() and loss of sync!
t += MS2NT(1);
doTooth(dut, shape, cfg, t);
EXPECT_FALSE(dut.getShaftSynchronized());
EXPECT_EQ(6, dut.currentCycle.current_index);
EXPECT_EQ(1, dut.totalTriggerErrorCounter);
Sensor::resetAllMocks();
}
TEST(TriggerDecoder, NotEnoughTeeth_CausesError) {
@ -220,6 +227,7 @@ TEST(TriggerDecoder, NotEnoughTeeth_CausesError) {
EXPECT_TRUE(dut.getShaftSynchronized());
EXPECT_EQ(2, dut.currentCycle.current_index);
EXPECT_FALSE(dut.someSortOfTriggerError());
EXPECT_EQ(0, dut.totalTriggerErrorCounter);
// Missing tooth, but it comes early - not enough teeth have happened yet!
t += MS2NT(2);
@ -228,6 +236,7 @@ TEST(TriggerDecoder, NotEnoughTeeth_CausesError) {
// Sync is lost until we get to another sync point
EXPECT_FALSE(dut.getShaftSynchronized());
EXPECT_EQ(0, dut.currentCycle.current_index);
EXPECT_EQ(1, dut.totalTriggerErrorCounter);
EXPECT_TRUE(dut.someSortOfTriggerError());
}

View File

@ -152,7 +152,10 @@ static void testNoiselessDecoderProcedure(EngineTestHelper &eth, int errorTolera
// add noise7 - 34 short spikes across the entire signal pulse
fireNoisyCycle60_2(&eth, 2, 1000, 2, 10, 10, failProofNumSpikes + 1);
ASSERT_EQ(errorToleranceCnt, engine->triggerCentral.triggerState.totalTriggerErrorCounter);
// alas, this is a hard case even for noiseless decoder, and it fails...
// but still we're close to 33% signal-noise ratio threshold - not bad!
// so here's an error anyway!
ASSERT_EQ( 1, engine->triggerCentral.triggerState.totalTriggerErrorCounter) << "testNoiselessDecoder noise#7_fail_test";
}
TEST(trigger, noiselessDecoder) {