fome-fw/unit_tests/tests/test_fasterEngineSpinningUp...

121 lines
4.7 KiB
C++
Raw Normal View History

/*
* test_fasterEngineSpinningUp.cpp
*
* Created on: Mar 6, 2018
*/
#include "engine_math.h"
#include "engine_test_helper.h"
2019-01-20 19:21:12 -08:00
TEST(cranking, testFasterEngineSpinningUp) {
2019-01-19 17:42:29 -08:00
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
// turn on FasterEngineSpinUp mode
engineConfiguration->isFasterEngineSpinUpEnabled = true;
engineConfiguration->cranking.baseFuel = 12;
2019-01-21 19:45:37 -08:00
// set ignition mode
engineConfiguration->ignitionMode = IM_INDIVIDUAL_COILS;
// set cranking threshold (used below)
engineConfiguration->cranking.rpm = 999;
// set sequential injection mode to test auto-change to simultaneous when spinning-up
setupSimpleTestEngineWithMafAndTT_ONE_trigger(&eth, IM_SEQUENTIAL);
ASSERT_EQ(IM_INDIVIDUAL_COILS, getCurrentIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE));
eth.fireRise(1000 /*ms*/);
// check if it's true
2019-01-14 12:45:35 -08:00
ASSERT_EQ(IM_SEQUENTIAL, engine->getCurrentInjectionMode(PASS_ENGINE_PARAMETER_SIGNATURE));
ASSERT_EQ(IM_WASTED_SPARK, getCurrentIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE));
// check if the engine has the right state
ASSERT_EQ(SPINNING_UP, engine->rpmCalculator.getState());
// check RPM
2019-01-21 18:48:58 -08:00
ASSERT_EQ( 0, GET_RPM()) << "RPM=0";
// the queue should be empty, no trigger events yet
2019-01-14 12:31:56 -08:00
ASSERT_EQ(0, engine->executor.size()) << "plain#1";
// check all events starting from now
// advance 1 revolution
2019-01-13 21:21:08 -08:00
// because we have trivial TT_ONE trigger here synchronization would happen with just one rise front
2018-07-28 16:51:41 -07:00
eth.fireRise(200);
// check if the mode is changed
2019-01-14 12:31:56 -08:00
ASSERT_EQ(SPINNING_UP, engine->rpmCalculator.getState());
// due to isFasterEngineSpinUp=true, we should have already detected RPM!
2019-01-21 18:48:58 -08:00
ASSERT_EQ( 300, GET_RPM()) << "spinning-RPM#1";
// two simultaneous injections
2019-01-14 12:31:56 -08:00
ASSERT_EQ(4, engine->executor.size()) << "plain#2";
// test if they are simultaneous
2019-01-14 12:31:56 -08:00
ASSERT_EQ(IM_SIMULTANEOUS, engine->getCurrentInjectionMode(PASS_ENGINE_PARAMETER_SIGNATURE));
// test if ignition mode is temporary changed to wasted spark, if set to individual coils
ASSERT_EQ(IM_WASTED_SPARK, getCurrentIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE));
// check real events
eth.assertEvent5("inj start#1", 0, (void*)startSimultaniousInjection, 98125);
eth.assertEvent5("inj end#1", 1, (void*)endSimultaniousInjection, 99999);
// skip the rest of the cycle
2018-07-28 17:02:01 -07:00
eth.fireFall(200);
// now clear and advance more
eth.clearQueue();
2018-07-28 16:51:41 -07:00
eth.fireRise(200);
// check if the mode is changed when fully synched
2019-01-14 12:31:56 -08:00
ASSERT_EQ(CRANKING, engine->rpmCalculator.getState());
// check RPM
2019-01-21 18:48:58 -08:00
ASSERT_EQ( 200, GET_RPM()) << "RPM#2";
// test if they are simultaneous in cranking mode too
2019-01-14 12:31:56 -08:00
ASSERT_EQ(IM_SIMULTANEOUS, engine->getCurrentInjectionMode(PASS_ENGINE_PARAMETER_SIGNATURE));
// test if ignition mode is restored to ind.coils
ASSERT_EQ(IM_INDIVIDUAL_COILS, getCurrentIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE));
// two simultaneous injections
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 4, engine->executor.size()) << "plain#2";
// check real events
eth.assertEvent5("inj start#2", 0, (void*)startSimultaniousInjection, 148125);
eth.assertEvent5("inj end#2", 1, (void*)endSimultaniousInjection, 149999);
// skip, clear & advance 1 more revolution at higher RPM
2018-07-28 17:02:01 -07:00
eth.fireFall(60);
eth.clearQueue();
2018-07-28 16:37:10 -07:00
eth.fireTriggerEventsWithDuration(60);
// check if the mode is now changed to 'running' at higher RPM
2019-01-14 12:45:35 -08:00
ASSERT_EQ(RUNNING, engine->rpmCalculator.getState());
// check RPM
2019-01-21 18:48:58 -08:00
ASSERT_EQ( 1000, GET_RPM()) << "RPM#3";
// check if the injection mode is back to sequential now
2019-01-14 12:45:35 -08:00
ASSERT_EQ(IM_SEQUENTIAL, engine->getCurrentInjectionMode(PASS_ENGINE_PARAMETER_SIGNATURE));
// 4 sequential injections for the full cycle
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 8, engine->executor.size()) << "plain#3";
// check real events for sequential injection
// Note: See addFuelEvents() fix inside setRpmValue()!
2020-01-10 20:17:58 -08:00
eth.assertEvent5("inj start#3", 0, (void*)turnInjectionPinHigh, -31875);
eth.assertEvent5("inj end#3", 1, (void*)turnInjectionPinLow, -30001);
}
2019-01-20 19:21:12 -08:00
static void doTestFasterEngineSpinningUp60_2(int startUpDelayMs, int rpm1, int expectedRpm) {
2019-01-20 19:21:12 -08:00
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
// turn on FasterEngineSpinUp mode
engineConfiguration->isFasterEngineSpinUpEnabled = true;
2019-01-20 19:21:12 -08:00
2019-01-21 12:34:39 -08:00
setupSimpleTestEngineWithMaf(&eth, IM_SEQUENTIAL, TT_TOOTHED_WHEEL_60_2);
2019-01-21 19:45:37 -08:00
eth.moveTimeForwardMs(startUpDelayMs);
2019-01-20 19:21:12 -08:00
// fire 30 tooth rise/fall signals
2019-01-21 17:33:21 -08:00
eth.fireTriggerEvents2(30 /* count */, 1 /*ms*/);
// now fire missed tooth rise/fall
eth.fireRise(4 /*ms*/);
EXPECT_EQ(rpm1, GET_RPM()) << "test RPM: After rise " + std::to_string(startUpDelayMs);
eth.fireFall(4 /*ms*/);
EXPECT_EQ(expectedRpm, GET_RPM()) << "test RPM: with " + std::to_string(startUpDelayMs) + " startUpDelayMs";
2019-01-21 19:45:37 -08:00
}
TEST(cranking, testFasterEngineSpinningUp60_2) {
doTestFasterEngineSpinningUp60_2(0, 288, 263);
doTestFasterEngineSpinningUp60_2(100, 288, 263);
doTestFasterEngineSpinningUp60_2(1000, 288, 263);
2019-01-20 19:21:12 -08:00
}