diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index b35afa2b1a..c9bb2d0eb0 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -38,13 +38,12 @@ public: class FuelSchedule { public: FuelSchedule(); - InjectionEventList injectionEvents; - /** * this method schedules all fuel events for an engine cycle */ void addFuelEvents(injection_mode_e mode DECLARE_ENGINE_PARAMETER_S); + InjectionEventList injectionEvents; /** * This is a performance optimization for https://sourceforge.net/p/rusefi/tickets/64/ * TODO: better data structure? better algorithm? diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index 5acd99a4f6..54d5901758 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -312,22 +312,23 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no int prevIndex = TRIGGER_SHAPE(triggerIndexByAngle[(int)prevAngle]); // now let's get precise angle for that event prevAngle = TRIGGER_SHAPE(eventAngles[prevIndex]); - uint32_t time = nowNt - timeOfLastEvent[prevIndex]; +// todo: re-implement this as a subclass. we need two instances of +// uint32_t time = nowNt - timeOfLastEvent[prevIndex]; angle_t angleDiff = currentAngle - prevAngle; // todo: angle diff should be pre-calculated fixAngle(angleDiff); - float r = (60000000.0 / 360 * US_TO_NT_MULTIPLIER) * angleDiff / time; +// float r = (60000000.0 / 360 * US_TO_NT_MULTIPLIER) * angleDiff / time; #if EFI_SENSOR_CHART || defined(__DOXYGEN__) if (boardConfiguration->sensorChartMode == SC_DETAILED_RPM) { - scAddData(currentAngle, r); +// scAddData(currentAngle, r); } else { - scAddData(currentAngle, r / instantRpmValue[prevIndex]); +// scAddData(currentAngle, r / instantRpmValue[prevIndex]); } #endif - instantRpmValue[currentCycle.current_index] = r; - timeOfLastEvent[currentCycle.current_index] = nowNt; +// instantRpmValue[currentCycle.current_index] = r; +// timeOfLastEvent[currentCycle.current_index] = nowNt; } } @@ -526,7 +527,13 @@ void TriggerShape::initializeTriggerShape(Logging *logger DECLARE_ENGINE_PARAMET return; } wave.checkSwitchTimes(getSize()); - calculateTriggerSynchPoint(&engine->triggerCentral.triggerState PASS_ENGINE_PARAMETER); + /** + * this instance is used only to initialize 'this' TriggerShape instance + * #192 BUG real hardware trigger events could be coming even while we are initializing trigger + */ + TriggerState state; + state.reset(); + calculateTriggerSynchPoint(&state PASS_ENGINE_PARAMETER); } static void onFindIndex(TriggerState *state) { diff --git a/firmware/controllers/trigger/trigger_decoder.h b/firmware/controllers/trigger/trigger_decoder.h index d76cc0ec07..edbadd7b9c 100644 --- a/firmware/controllers/trigger/trigger_decoder.h +++ b/firmware/controllers/trigger/trigger_decoder.h @@ -80,8 +80,10 @@ public: uint32_t prevTotalTime[PWM_PHASE_MAX_WAVE_PER_PWM]; int expectedTotalTime[PWM_PHASE_MAX_WAVE_PER_PWM]; - uint32_t timeOfLastEvent[PWM_PHASE_MAX_COUNT]; - float instantRpmValue[PWM_PHASE_MAX_COUNT]; + // we need two instances of TriggerState + // todo: re-imiplement as a sub-class to reduce memory consumption +// uint32_t timeOfLastEvent[PWM_PHASE_MAX_COUNT]; +// float instantRpmValue[PWM_PHASE_MAX_COUNT]; /** * how many times since ECU reboot we had unexpected number of teeth in trigger cycle diff --git a/java_console/.idea/runConfigurations/Launcher_COM56.xml b/java_console/.idea/runConfigurations/Launcher_COM56.xml new file mode 100644 index 0000000000..f855da57ff --- /dev/null +++ b/java_console/.idea/runConfigurations/Launcher_COM56.xml @@ -0,0 +1,17 @@ + + + + + \ No newline at end of file diff --git a/java_console/.idea/runConfigurations/Launcher_COM66.xml b/java_console/.idea/runConfigurations/Launcher_COM66.xml new file mode 100644 index 0000000000..ce1e888926 --- /dev/null +++ b/java_console/.idea/runConfigurations/Launcher_COM66.xml @@ -0,0 +1,17 @@ + + + + + \ No newline at end of file diff --git a/unit_tests/engine_test_helper.cpp b/unit_tests/engine_test_helper.cpp index a6972581bf..f9a7bc7403 100644 --- a/unit_tests/engine_test_helper.cpp +++ b/unit_tests/engine_test_helper.cpp @@ -47,8 +47,8 @@ EngineTestHelper::EngineTestHelper(engine_type_e engineType) : engine (&persiste engine->engineConfiguration->mafAdcChannel = (adc_channel_e)TEST_MAF_CHANNEL; } -void EngineTestHelper::fireTriggerEvents() { - for (int i = 0; i < 24; i++) { +void EngineTestHelper::fireTriggerEvents(int count) { + for (int i = 0; i < count; i++) { timeNow += 5000; // 5ms board_configuration_s * boardConfiguration = &engine.engineConfiguration->bc; engine.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP, &engine, engine.engineConfiguration, &persistentConfig, boardConfiguration); diff --git a/unit_tests/engine_test_helper.h b/unit_tests/engine_test_helper.h index a064dae459..41ab5d281f 100644 --- a/unit_tests/engine_test_helper.h +++ b/unit_tests/engine_test_helper.h @@ -15,7 +15,7 @@ class EngineTestHelper { public: EngineTestHelper(engine_type_e engineType); void initTriggerShapeAndRpmCalculator(); - void fireTriggerEvents(); + void fireTriggerEvents(int count); persistent_config_s persistentConfig; engine_configuration2_s ec2; diff --git a/unit_tests/test_speed_density.cpp b/unit_tests/test_speed_density.cpp index fb54f93f6b..ce59170876 100644 --- a/unit_tests/test_speed_density.cpp +++ b/unit_tests/test_speed_density.cpp @@ -18,7 +18,7 @@ void testSpeedDensity(void) { eth.ec->trigger.customTotalToothCount = 8; eth.initTriggerShapeAndRpmCalculator(); - eth.fireTriggerEvents(); + eth.fireTriggerEvents(36); assertEqualsM("RPM", 1500, eth.engine.rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_F)); // 427 cubic inches, that's a LOT of engine diff --git a/unit_tests/test_trigger_decoder.cpp b/unit_tests/test_trigger_decoder.cpp index 18544d9c35..edad27f129 100644 --- a/unit_tests/test_trigger_decoder.cpp +++ b/unit_tests/test_trigger_decoder.cpp @@ -302,7 +302,8 @@ static void testRpmCalculator(void) { timeNow = 0; assertEquals(0, eth.engine.rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_F)); - eth.fireTriggerEvents(); + eth.fireTriggerEvents(48); + assertEqualsM("RPM", 1500, eth.engine.rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_F)); assertEqualsM("index #1", 15, eth.engine.triggerCentral.triggerState.getCurrentIndex()); @@ -317,8 +318,13 @@ static void testRpmCalculator(void) { debugSignalExecutor = true; + assertEquals(eth.engine.triggerCentral.triggerState.shaft_is_synchronized, 1); + timeNow += 5000; // 5ms + int st = timeNow; + assertEqualsM("st value", 485000, st); + eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_F); eth.engine.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP PASS_ENGINE_PARAMETER); @@ -335,8 +341,8 @@ static void testRpmCalculator(void) { scheduling_s *ev1 = schedulingQueue.getForUnitText(0); assertREquals((void*)ev1->callback, (void*)turnPinHigh); - assertEqualsM("ev 1", 245000, ev1->momentX); - assertEqualsM("ev 2", 245000, schedulingQueue.getForUnitText(1)->momentX); + assertEqualsM("ev 1", st, ev1->momentX); + assertEqualsM("ev 2", st, schedulingQueue.getForUnitText(1)->momentX); schedulingQueue.clear(); timeNow += 5000; @@ -347,10 +353,10 @@ static void testRpmCalculator(void) { eth.engine.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_DOWN PASS_ENGINE_PARAMETER); assertEqualsM("index #3", 3, eth.engine.triggerCentral.triggerState.getCurrentIndex()); assertEqualsM("queue size 3", 6, schedulingQueue.size()); - assertEqualsM("ev 3", 258333, schedulingQueue.getForUnitText(0)->momentX); - assertEqualsM("ev 4", 258333, schedulingQueue.getForUnitText(1)->momentX); - assertEqualsM2("ev 5", 259277, schedulingQueue.getForUnitText(2)->momentX, 2); - assertEqualsM("3/3", 259777, schedulingQueue.getForUnitText(3)->momentX); + assertEqualsM("ev 3", st + 13333, schedulingQueue.getForUnitText(0)->momentX); + assertEqualsM("ev 4", st + 13333, schedulingQueue.getForUnitText(1)->momentX); + assertEqualsM2("ev 5", st + 14277, schedulingQueue.getForUnitText(2)->momentX, 2); + assertEqualsM("3/3", st + 14777, schedulingQueue.getForUnitText(3)->momentX); schedulingQueue.clear(); timeNow += 5000; @@ -361,21 +367,20 @@ static void testRpmCalculator(void) { eth.engine.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP PASS_ENGINE_PARAMETER); assertEqualsM("index #4", 6, eth.engine.triggerCentral.triggerState.getCurrentIndex()); assertEqualsM("queue size 4", 6, schedulingQueue.size()); - assertEqualsM("4/0", 271666, schedulingQueue.getForUnitText(0)->momentX); + assertEqualsM("4/0", st + 26666, schedulingQueue.getForUnitText(0)->momentX); schedulingQueue.clear(); timeNow += 5000; eth.engine.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_DOWN PASS_ENGINE_PARAMETER); assertEqualsM("queue size 5", 0, schedulingQueue.size()); -// assertEqualsM("5/1", 284500, schedulingQueue.getForUnitText(0)->momentUs); schedulingQueue.clear(); timeNow += 5000; // 5ms eth.engine.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP PASS_ENGINE_PARAMETER); assertEqualsM("queue size 6", 6, schedulingQueue.size()); - assertEqualsM("6/0", 285000, schedulingQueue.getForUnitText(0)->momentX); - assertEqualsM("6/1", 285000, schedulingQueue.getForUnitText(1)->momentX); - assertEqualsM2("6/2", 285944, schedulingQueue.getForUnitText(2)->momentX, 1); + assertEqualsM("6/0", st + 40000, schedulingQueue.getForUnitText(0)->momentX); + assertEqualsM("6/1", st + 40000, schedulingQueue.getForUnitText(1)->momentX); + assertEqualsM2("6/2", st + 40944, schedulingQueue.getForUnitText(2)->momentX, 1); schedulingQueue.clear(); timeNow += 5000; @@ -386,10 +391,10 @@ static void testRpmCalculator(void) { timeNow += 5000; // 5ms eth.engine.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP PASS_ENGINE_PARAMETER); assertEqualsM("queue size 8", 6, schedulingQueue.size()); - assertEqualsM("8/0", 298333, schedulingQueue.getForUnitText(0)->momentX); - assertEqualsM("8/1", 298333, schedulingQueue.getForUnitText(1)->momentX); - assertEqualsM2("8/2", 299277, schedulingQueue.getForUnitText(2)->momentX, 0); - assertEqualsM2("8/3", 299777, schedulingQueue.getForUnitText(3)->momentX, 0); + assertEqualsM("8/0", st + 53333, schedulingQueue.getForUnitText(0)->momentX); + assertEqualsM("8/1", st + 53333, schedulingQueue.getForUnitText(1)->momentX); + assertEqualsM2("8/2", st + 54277, schedulingQueue.getForUnitText(2)->momentX, 0); + assertEqualsM2("8/3", st + 54777, schedulingQueue.getForUnitText(3)->momentX, 0); schedulingQueue.clear(); timeNow += 5000; @@ -480,8 +485,8 @@ void testTriggerDecoder(void) { eth.persistentConfig.engineConfiguration.bc.sensorChartMode = SC_DETAILED_RPM; applyNonPersistentConfiguration(NULL PASS_ENGINE_PARAMETER); - assertEqualsM2("rpm#1", 16666.9746, eth.engine.triggerCentral.triggerState.instantRpmValue[0], 0.5); - assertEqualsM2("rpm#2", 16666.3750, eth.engine.triggerCentral.triggerState.instantRpmValue[1], 0.5); +// assertEqualsM2("rpm#1", 16666.9746, eth.engine.triggerCentral.triggerState.instantRpmValue[0], 0.5); +// assertEqualsM2("rpm#2", 16666.3750, eth.engine.triggerCentral.triggerState.instantRpmValue[1], 0.5); } // testTriggerDecoder2("miata 1990", MIATA_1990, 0, 0.6280, 0.0);