fome-fw/unit_tests/tests/ignition_injection/injection_mode_transition.cpp

92 lines
3.0 KiB
C++
Raw Normal View History

/*
* @file injection_mode_transition.cpp
*
* Created on: Jul 19, 2020
* @author Andrey Belomutskiy, (c) 2012-2020
*/
#include "pch.h"
2020-07-20 03:29:43 -07:00
static void doRevolution(EngineTestHelper& eth, int periodMs) {
float halfToothTime = (periodMs / 6.0f) / 2;
2020-07-20 12:40:23 -07:00
eth.smartFireRise(halfToothTime);
2020-07-20 03:29:43 -07:00
eth.fireFall(halfToothTime);
2020-07-20 12:40:23 -07:00
eth.smartFireRise(halfToothTime);
2020-07-20 03:29:43 -07:00
eth.fireFall(halfToothTime);
2020-07-20 12:40:23 -07:00
eth.smartFireRise(halfToothTime);
2020-07-20 03:29:43 -07:00
eth.fireFall(halfToothTime);
// now missing tooth
2020-07-20 12:40:23 -07:00
eth.smartFireRise(halfToothTime);
2020-07-20 03:29:43 -07:00
eth.fireFall(3 * halfToothTime);
// This tooth is the sync point!
2020-07-20 12:40:23 -07:00
eth.smartFireRise(halfToothTime);
2020-07-20 03:29:43 -07:00
eth.fireFall(halfToothTime);
}
// https://github.com/rusefi/rusefi/issues/1592
TEST(fuelControl, transitionIssue1592) {
EngineTestHelper eth(TEST_ENGINE);
ENGINE(tdcMarkEnabled) = false;
setupSimpleTestEngineWithMafAndTT_ONE_trigger(&eth, IM_SEQUENTIAL);
EXPECT_CALL(eth.mockAirmass, getAirmass(500))
2020-07-28 14:42:02 -07:00
.WillRepeatedly(Return(AirmassResult{0.1008f, 50.0f}));
2020-07-20 03:29:43 -07:00
// This is easiest to trip on a wheel that requires sync
engineConfiguration->trigger.customTotalToothCount = 6;
engineConfiguration->trigger.customSkippedToothCount = 1;
eth.setTriggerType(TT_TOOTHED_WHEEL);
2020-07-20 03:29:43 -07:00
engineConfiguration->ambiguousOperationMode = FOUR_STROKE_CAM_SENSOR;
engineConfiguration->isFasterEngineSpinUpEnabled = true;
setTable(config->injectionPhase, 0.0f);
2020-07-20 12:40:23 -07:00
setArrayValues(config->crankingFuelCoef, 1.0f);
setArrayValues(config->crankingCycleCoef, 1.0f);
2020-07-20 03:29:43 -07:00
engineConfiguration->globalTriggerAngleOffset = 20;
2020-07-20 03:29:43 -07:00
// Yes, this is a ton of fuel but it makes the repro easier
engineConfiguration->cranking.baseFuel = 213.6;
engineConfiguration->cranking.rpm = 501;
2020-07-20 03:29:43 -07:00
// Test the transition from batch cranking to sequential running
engineConfiguration->crankingInjectionMode = IM_BATCH;
engineConfiguration->twoWireBatchInjection = true;
2020-07-20 03:29:43 -07:00
// First sync point will schedule cranking pulse since we're in "faster spin up" mode
doRevolution(eth, 240);
2020-07-20 03:29:43 -07:00
{
// Injector 2 should be scheduled to open then close
void* inj2 = reinterpret_cast<void*>(&engine->injectionEvents.elements[1]);
2020-07-20 03:29:43 -07:00
ASSERT_EQ(engine->executor.size(), 2);
2020-07-19 21:36:10 -07:00
2020-07-20 03:29:43 -07:00
// Check that the action is correct - we don't care about the timing necessarily
auto sched_open = engine->executor.getForUnitTest(0);
ASSERT_EQ(sched_open->action.getArgument(), inj2);
2020-12-04 21:22:10 -08:00
ASSERT_EQ(sched_open->action.getCallback(), (void(*)(void*))turnInjectionPinHigh);
2020-07-19 21:36:10 -07:00
2020-07-20 03:29:43 -07:00
auto sched_close = engine->executor.getForUnitTest(1);
// Next action should be closing the same injector
ASSERT_EQ(sched_close->action.getArgument(), inj2);
2020-12-04 21:22:10 -08:00
ASSERT_EQ(sched_close->action.getCallback(), (void(*)(void*))turnInjectionPinLow);
2020-07-20 03:29:43 -07:00
}
2020-07-20 12:40:23 -07:00
// Run the engine for some revs
for (size_t i = 0; i < 10; i++) {
doRevolution(eth, 150);
2020-07-20 03:29:43 -07:00
}
2020-07-20 12:40:23 -07:00
// Check that no injectors are stuck open
2020-07-20 18:47:08 -07:00
// Injectors 1/3 should be open
2020-07-20 12:40:23 -07:00
EXPECT_EQ(enginePins.injectors[0].getOverlappingCounter(), 1);
EXPECT_EQ(enginePins.injectors[1].getOverlappingCounter(), 0);
2020-07-20 18:47:08 -07:00
EXPECT_EQ(enginePins.injectors[2].getOverlappingCounter(), 1);
2020-07-20 03:29:43 -07:00
EXPECT_EQ(enginePins.injectors[3].getOverlappingCounter(), 0);
}