auto-sync
This commit is contained in:
parent
0dab56dff9
commit
3f815a6475
|
@ -149,8 +149,9 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no
|
|||
nextTriggerEvent()
|
||||
;
|
||||
if (TRIGGER_SHAPE(gapBothDirections) && considerEventForGap()) {
|
||||
toothed_previous_duration = currentDuration;
|
||||
isFirstEvent = false;
|
||||
durationBeforePrevious = toothed_previous_duration;
|
||||
toothed_previous_duration = currentDuration;
|
||||
toothed_previous_time = nowNt;
|
||||
}
|
||||
return;
|
||||
|
@ -172,20 +173,27 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no
|
|||
bool_t isSynchronizationPoint;
|
||||
|
||||
if (TRIGGER_SHAPE(isSynchronizationNeeded)) {
|
||||
isSynchronizationPoint = currentDuration > toothed_previous_duration * TRIGGER_SHAPE(syncRatioFrom)
|
||||
&& currentDuration < toothed_previous_duration * TRIGGER_SHAPE(syncRatioTo);
|
||||
/**
|
||||
* Here I prefer to have two multiplications instead of one division, that's a micro-optimization
|
||||
*/
|
||||
isSynchronizationPoint = currentDuration > toothed_previous_duration * TRIGGER_SHAPE(syncRatioFrom) &&
|
||||
currentDuration < toothed_previous_duration * TRIGGER_SHAPE(syncRatioTo) &&
|
||||
toothed_previous_duration > durationBeforePrevious * TRIGGER_SHAPE(secondSyncRatioFrom) &&
|
||||
toothed_previous_duration < durationBeforePrevious * TRIGGER_SHAPE(secondSyncRatioTo)
|
||||
;
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
||||
if (engineConfiguration->isPrintTriggerSynchDetails) {
|
||||
#else
|
||||
if (printTriggerDebug) {
|
||||
#endif /* EFI_PROD_CODE */
|
||||
float gap = 1.0 * currentDuration / toothed_previous_duration;
|
||||
#if EFI_PROD_CODE
|
||||
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
||||
scheduleMsg(logger, "gap=%f @ %d", gap, currentCycle.current_index);
|
||||
#else
|
||||
actualSynchGap = gap;
|
||||
print("current gap %f c=%d prev=%d\r\n", gap, currentDuration, toothed_previous_duration);
|
||||
float prevGap = 1.0 * toothed_previous_duration / durationBeforePrevious;
|
||||
print("current gap %f/%f c=%d prev=%d\r\n", gap, prevGap, currentDuration, toothed_previous_duration);
|
||||
#endif /* EFI_PROD_CODE */
|
||||
}
|
||||
|
||||
|
@ -248,6 +256,7 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no
|
|||
;
|
||||
}
|
||||
|
||||
durationBeforePrevious = toothed_previous_duration;
|
||||
toothed_previous_duration = currentDuration;
|
||||
toothed_previous_time = nowNt;
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ public:
|
|||
*/
|
||||
bool shaft_is_synchronized;
|
||||
|
||||
uint32_t durationBeforePrevious;
|
||||
uint32_t toothed_previous_duration;
|
||||
/**
|
||||
* this could be a local variable, but it's better for debugging to have it as a field
|
||||
|
|
|
@ -47,6 +47,8 @@ TriggerShape::TriggerShape() :
|
|||
tdcPosition = 0;
|
||||
skippedToothCount = totalToothCount = 0;
|
||||
syncRatioFrom = syncRatioTo = 0;
|
||||
secondSyncRatioFrom = 0.000001;
|
||||
secondSyncRatioTo = 100000;
|
||||
memset(eventAngles, 0, sizeof(eventAngles));
|
||||
memset(frontOnlyIndexes, 0, sizeof(frontOnlyIndexes));
|
||||
memset(isFrontEvent, 0, sizeof(isFrontEvent));
|
||||
|
@ -153,6 +155,7 @@ TriggerState::TriggerState() {
|
|||
shaft_is_synchronized = false;
|
||||
toothed_previous_time = 0;
|
||||
toothed_previous_duration = 0;
|
||||
durationBeforePrevious = 0;
|
||||
|
||||
totalRevolutionCounter = 0;
|
||||
totalTriggerErrorCounter = 0;
|
||||
|
@ -236,7 +239,7 @@ operation_mode_e TriggerShape::getOperationMode() {
|
|||
return operationMode;
|
||||
}
|
||||
|
||||
#if EFI_UNIT_TEST
|
||||
#if EFI_UNIT_TEST || defined(__DOXYGEN__)
|
||||
extern bool printTriggerDebug;
|
||||
#endif
|
||||
|
||||
|
@ -245,7 +248,7 @@ void TriggerShape::addEvent(float angle, trigger_wheel_e const waveIndex, trigge
|
|||
|
||||
efiAssertVoid(waveIndex!= T_SECONDARY || needSecondTriggerInput, "secondary needed or not?");
|
||||
|
||||
#if EFI_UNIT_TEST
|
||||
#if EFI_UNIT_TEST || defined(__DOXYGEN__)
|
||||
if (printTriggerDebug) {
|
||||
printf("addEvent %f\r\n", angle);
|
||||
}
|
||||
|
|
|
@ -49,6 +49,13 @@ public:
|
|||
float syncRatioFrom;
|
||||
float syncRatioTo;
|
||||
|
||||
/**
|
||||
* Usually this is not needed, but some crazy triggers like 36-2-2-2 require two consecutive
|
||||
* gaps ratios to sync
|
||||
*/
|
||||
float secondSyncRatioFrom;
|
||||
float secondSyncRatioTo;
|
||||
|
||||
/**
|
||||
* that's the angle distance from trigger event #0 and actual engine TDC
|
||||
* see also globalTriggerAngleOffset
|
||||
|
|
|
@ -273,5 +273,5 @@ int getRusEfiVersion(void) {
|
|||
return 123; // this is here to make the compiler happy about the unused array
|
||||
if (UNUSED_CCM_SIZE[0] * 0 != 0)
|
||||
return 3211; // this is here to make the compiler happy about the unused array
|
||||
return 20150910;
|
||||
return 20150911;
|
||||
}
|
||||
|
|
|
@ -201,91 +201,6 @@ void testMazda323(void) {
|
|||
assertEquals(0, eth.engine.triggerShape.getTriggerShapeSynchPointIndex());
|
||||
}
|
||||
|
||||
void testMazdaMianaNbDecoder(void) {
|
||||
printf("*************************************************** testMazdaMianaNbDecoder\r\n");
|
||||
|
||||
EngineTestHelper eth(MAZDA_MIATA_NB);
|
||||
EXPAND_EngineTestHelper;
|
||||
|
||||
engine_configuration_s *ec = eth.ec;
|
||||
TriggerShape * shape = ð.engine.triggerShape;
|
||||
assertEquals(12, shape->getTriggerShapeSynchPointIndex());
|
||||
|
||||
TriggerState state;
|
||||
|
||||
int a = 0;
|
||||
state.decodeTriggerEvent(SHAFT_PRIMARY_DOWN, a + 20 PASS_ENGINE_PARAMETER);
|
||||
assertFalseM("0a shaft_is_synchronized", state.shaft_is_synchronized);
|
||||
state.decodeTriggerEvent(SHAFT_PRIMARY_UP, a + 340 PASS_ENGINE_PARAMETER);
|
||||
assertFalseM("0b shaft_is_synchronized", state.shaft_is_synchronized);
|
||||
|
||||
state.decodeTriggerEvent(SHAFT_PRIMARY_DOWN, a + 360 PASS_ENGINE_PARAMETER);
|
||||
assertFalseM("0c shaft_is_synchronized", state.shaft_is_synchronized);
|
||||
state.decodeTriggerEvent(SHAFT_PRIMARY_UP, a + 380 PASS_ENGINE_PARAMETER);
|
||||
assertFalseM("0d shaft_is_synchronized", state.shaft_is_synchronized);
|
||||
state.decodeTriggerEvent(SHAFT_PRIMARY_DOWN, a + 400 PASS_ENGINE_PARAMETER);
|
||||
assertTrueM("0e shaft_is_synchronized", state.shaft_is_synchronized);
|
||||
|
||||
state.decodeTriggerEvent(SHAFT_PRIMARY_UP, a + 720 PASS_ENGINE_PARAMETER);
|
||||
assertTrueM("0f shaft_is_synchronized", state.shaft_is_synchronized);
|
||||
|
||||
a = 720;
|
||||
state.decodeTriggerEvent(SHAFT_PRIMARY_DOWN, a + 20 PASS_ENGINE_PARAMETER);
|
||||
assertTrueM("1a shaft_is_synchronized", state.shaft_is_synchronized);
|
||||
state.decodeTriggerEvent(SHAFT_PRIMARY_UP, a + 340 PASS_ENGINE_PARAMETER);
|
||||
assertTrueM("1b shaft_is_synchronized", state.shaft_is_synchronized);
|
||||
|
||||
state.decodeTriggerEvent(SHAFT_PRIMARY_DOWN, a + 360 PASS_ENGINE_PARAMETER);
|
||||
assertTrueM("1c shaft_is_synchronized", state.shaft_is_synchronized);
|
||||
state.decodeTriggerEvent(SHAFT_PRIMARY_UP, a + 380 PASS_ENGINE_PARAMETER);
|
||||
assertTrueM("1d shaft_is_synchronized", state.shaft_is_synchronized);
|
||||
assertEquals(5, state.getCurrentIndex());
|
||||
|
||||
state.decodeTriggerEvent(SHAFT_PRIMARY_DOWN, a + 400 PASS_ENGINE_PARAMETER);
|
||||
assertTrueM("1e shaft_is_synchronized", state.shaft_is_synchronized);
|
||||
assertEquals(0, state.getCurrentIndex());
|
||||
|
||||
state.decodeTriggerEvent(SHAFT_PRIMARY_UP, a + 720 PASS_ENGINE_PARAMETER);
|
||||
assertTrueM("1f shaft_is_synchronized", state.shaft_is_synchronized);
|
||||
|
||||
event_trigger_position_s position;
|
||||
assertEqualsM("globalTriggerAngleOffset", 276, ec->globalTriggerAngleOffset);
|
||||
findTriggerPosition(&position, 0 PASS_ENGINE_PARAMETER);
|
||||
assertTriggerPosition(&position, 7, 0);
|
||||
|
||||
findTriggerPosition(&position, 180 PASS_ENGINE_PARAMETER);
|
||||
assertTriggerPosition(&position, 13, 0);
|
||||
|
||||
findTriggerPosition(&position, 360 PASS_ENGINE_PARAMETER);
|
||||
assertTriggerPosition(&position, 17, 0.0);
|
||||
|
||||
findTriggerPosition(&position, 444 PASS_ENGINE_PARAMETER);
|
||||
assertTriggerPosition(&position, 0, 0);
|
||||
|
||||
findTriggerPosition(&position, 444.1 PASS_ENGINE_PARAMETER);
|
||||
assertTriggerPosition(&position, 0, 0.1);
|
||||
|
||||
findTriggerPosition(&position, 445 PASS_ENGINE_PARAMETER);
|
||||
assertTriggerPosition(&position, 0, 1);
|
||||
|
||||
findTriggerPosition(&position, 494 PASS_ENGINE_PARAMETER);
|
||||
assertTriggerPosition(&position, 2, 20);
|
||||
|
||||
findTriggerPosition(&position, 719 PASS_ENGINE_PARAMETER);
|
||||
assertTriggerPosition(&position, 6, 65);
|
||||
|
||||
ec->globalTriggerAngleOffset = 0;
|
||||
findTriggerPosition(&position, 0 PASS_ENGINE_PARAMETER);
|
||||
assertTriggerPosition(&position, 0, 0);
|
||||
|
||||
ec->globalTriggerAngleOffset = 10;
|
||||
findTriggerPosition(&position, 0 PASS_ENGINE_PARAMETER);
|
||||
assertTriggerPosition(&position, 0, 10);
|
||||
|
||||
findTriggerPosition(&position, -10 PASS_ENGINE_PARAMETER);
|
||||
assertTriggerPosition(&position, 0, 0);
|
||||
}
|
||||
|
||||
static void testTriggerDecoder2(const char *msg, engine_type_e type, int synchPointIndex, float channel1duty, float channel2duty) {
|
||||
printf("*************************************************** %s\r\n", msg);
|
||||
|
||||
|
@ -358,7 +273,6 @@ static void assertREquals(void *expected, void *actual) {
|
|||
assertEquals((float)(uint64_t)expected, (float)(uint64_t)actual);
|
||||
}
|
||||
|
||||
extern engine_pins_s enginePins;
|
||||
extern bool_t debugSignalExecutor;
|
||||
|
||||
static void testRpmCalculator(void) {
|
||||
|
@ -518,7 +432,7 @@ void testTriggerDecoder(void) {
|
|||
testTriggerDecoder2("bmw", BMW_E34, 0, 0.4667, 0.0);
|
||||
|
||||
test1995FordInline6TriggerDecoder();
|
||||
testMazdaMianaNbDecoder();
|
||||
testTriggerDecoder2("Miata NB", MAZDA_MIATA_NB, 12, 0.0833, 0.0444);
|
||||
|
||||
testTriggerDecoder2("test engine", TEST_ENGINE, 0, 0.0, 0.0);
|
||||
testTriggerDecoder2("testGY6_139QMB", GY6_139QMB, 0, 0.4375, 0.0);
|
||||
|
|
Loading…
Reference in New Issue