2018-03-10 17:58:51 -08:00
|
|
|
/*
|
|
|
|
* test_fasterEngineSpinningUp.cpp
|
|
|
|
*
|
|
|
|
* Created on: Mar 6, 2018
|
|
|
|
*/
|
|
|
|
|
2021-08-03 19:05:01 -07:00
|
|
|
#include "pch.h"
|
2024-02-29 06:49:03 -08:00
|
|
|
#include "fuel_math.h"
|
2018-03-10 17:58:51 -08:00
|
|
|
|
2019-01-20 19:21:12 -08:00
|
|
|
TEST(cranking, testFasterEngineSpinningUp) {
|
2023-05-31 22:31:28 -07:00
|
|
|
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
2024-05-02 21:49:08 -07:00
|
|
|
extern bool unitTestBusyWaitHack;
|
|
|
|
unitTestBusyWaitHack = true;
|
2024-02-28 20:22:01 -08:00
|
|
|
float phase = 181;
|
|
|
|
setTable(config->injectionPhase, -phase);
|
2021-11-17 00:54:21 -08:00
|
|
|
engine->tdcMarkEnabled = false;
|
2018-03-10 17:58:51 -08:00
|
|
|
// turn on FasterEngineSpinUp mode
|
2019-12-11 14:48:55 -08:00
|
|
|
engineConfiguration->isFasterEngineSpinUpEnabled = true;
|
2020-11-03 11:12:26 -08:00
|
|
|
engineConfiguration->cranking.baseFuel = 12;
|
2019-01-21 19:45:37 -08:00
|
|
|
|
2018-03-10 17:58:51 -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(ð, IM_SEQUENTIAL);
|
2022-06-09 14:21:22 -07:00
|
|
|
// Lie that this trigger requires disambiguation
|
|
|
|
engine->triggerCentral.triggerState.setNeedsDisambiguation(true);
|
2018-03-10 17:58:51 -08:00
|
|
|
|
2022-06-09 14:21:22 -07:00
|
|
|
ASSERT_EQ(IM_WASTED_SPARK, getCurrentIgnitionMode());
|
2019-01-24 18:12:55 -08:00
|
|
|
|
2019-11-05 21:01:08 -08:00
|
|
|
eth.fireRise(1000 /*ms*/);
|
2019-01-24 18:12:55 -08:00
|
|
|
|
2018-03-10 17:58:51 -08:00
|
|
|
// check if it's true
|
2022-09-04 23:44:06 -07:00
|
|
|
ASSERT_EQ(IM_SEQUENTIAL, getCurrentInjectionMode());
|
2021-11-16 01:15:29 -08:00
|
|
|
ASSERT_EQ(IM_WASTED_SPARK, getCurrentIgnitionMode());
|
2018-03-10 17:58:51 -08:00
|
|
|
// check if the engine has the right state
|
2019-01-24 18:12:55 -08:00
|
|
|
ASSERT_EQ(SPINNING_UP, engine->rpmCalculator.getState());
|
2024-02-29 06:49:03 -08:00
|
|
|
ASSERT_NEAR(0, getInjectionMass(200), EPS5D);
|
2018-03-10 17:58:51 -08:00
|
|
|
// check RPM
|
2024-02-28 20:22:01 -08:00
|
|
|
eth.assertRpm( 0, "RPM=0");
|
2018-03-10 17:58:51 -08:00
|
|
|
// the queue should be empty, no trigger events yet
|
2024-07-11 17:03:13 -07:00
|
|
|
ASSERT_EQ(0, engine->scheduler.size()) << "plain#1";
|
2018-03-10 17:58:51 -08:00
|
|
|
|
|
|
|
// 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);
|
2018-03-10 17:58:51 -08:00
|
|
|
|
|
|
|
// check if the mode is changed
|
2019-01-14 12:31:56 -08:00
|
|
|
ASSERT_EQ(SPINNING_UP, engine->rpmCalculator.getState());
|
2018-03-10 17:58:51 -08:00
|
|
|
// due to isFasterEngineSpinUp=true, we should have already detected RPM!
|
2024-02-28 20:22:01 -08:00
|
|
|
eth.assertRpm( 300, "spinning-RPM#1");
|
2018-03-10 17:58:51 -08:00
|
|
|
// two simultaneous injections
|
2024-07-11 17:03:13 -07:00
|
|
|
ASSERT_EQ(4, engine->scheduler.size()) << "plain#2";
|
2018-03-10 17:58:51 -08:00
|
|
|
// test if they are simultaneous
|
2022-09-04 23:44:06 -07:00
|
|
|
ASSERT_EQ(IM_SIMULTANEOUS, getCurrentInjectionMode());
|
2019-01-20 08:33:40 -08:00
|
|
|
// test if ignition mode is temporary changed to wasted spark, if set to individual coils
|
2021-11-16 01:15:29 -08:00
|
|
|
ASSERT_EQ(IM_WASTED_SPARK, getCurrentIgnitionMode());
|
2018-03-10 17:58:51 -08:00
|
|
|
// check real events
|
2024-02-28 20:22:01 -08:00
|
|
|
|
|
|
|
float expectedSimultaneousTimestamp = eth.angleToTimeUs(360 - phase);
|
|
|
|
|
|
|
|
eth.assertEvent5("inj start#1", 0, (void*)startSimultaneousInjection, expectedSimultaneousTimestamp - MS2US(engine->engineState.injectionDuration));
|
|
|
|
eth.assertEvent5("inj end#1", 1, (void*)endSimultaneousInjection, expectedSimultaneousTimestamp);
|
2018-03-10 17:58:51 -08:00
|
|
|
|
|
|
|
// skip the rest of the cycle
|
2024-04-12 12:13:25 -07:00
|
|
|
eth.moveTimeForwardUs(MS2US(200));
|
2018-03-10 17:58:51 -08:00
|
|
|
|
|
|
|
// now clear and advance more
|
2021-10-01 19:33:06 -07:00
|
|
|
eth.executeActions();
|
2018-07-28 16:51:41 -07:00
|
|
|
|
|
|
|
eth.fireRise(200);
|
2018-03-10 17:58:51 -08:00
|
|
|
|
|
|
|
// check if the mode is changed when fully synched
|
2019-01-14 12:31:56 -08:00
|
|
|
ASSERT_EQ(CRANKING, engine->rpmCalculator.getState());
|
2018-03-10 17:58:51 -08:00
|
|
|
// check RPM
|
2024-02-28 20:22:01 -08:00
|
|
|
eth.assertRpm(200, "RPM#2");
|
2018-03-10 17:58:51 -08:00
|
|
|
// test if they are simultaneous in cranking mode too
|
2022-09-04 23:44:06 -07:00
|
|
|
ASSERT_EQ(IM_SIMULTANEOUS, getCurrentInjectionMode());
|
2022-06-09 14:21:22 -07:00
|
|
|
// Should still be in wasted spark since we don't have cam sync yet
|
|
|
|
ASSERT_EQ(IM_WASTED_SPARK, getCurrentIgnitionMode());
|
2018-03-10 17:58:51 -08:00
|
|
|
// two simultaneous injections
|
2024-07-11 17:03:13 -07:00
|
|
|
ASSERT_EQ( 4, engine->scheduler.size()) << "plain#2";
|
2018-03-10 17:58:51 -08:00
|
|
|
// check real events
|
2024-02-28 20:22:01 -08:00
|
|
|
expectedSimultaneousTimestamp = eth.angleToTimeUs(360 - phase);
|
|
|
|
|
|
|
|
eth.assertEvent5("inj start#2", 0, (void*)startSimultaneousInjection, expectedSimultaneousTimestamp - 1625);
|
|
|
|
eth.assertEvent5("inj end#2", 1, (void*)endSimultaneousInjection, expectedSimultaneousTimestamp);
|
2018-03-10 17:58:51 -08:00
|
|
|
|
2022-06-09 14:21:22 -07:00
|
|
|
// Now perform a fake VVT sync and check that ignition mode changes to sequential
|
2024-05-06 10:44:12 -07:00
|
|
|
engine->triggerCentral.syncEnginePhaseAndReport(2, 0);
|
2022-06-09 14:21:22 -07:00
|
|
|
ASSERT_EQ(IM_SEQUENTIAL, getCurrentIgnitionMode());
|
2024-02-29 06:49:03 -08:00
|
|
|
// still cranking fuel
|
|
|
|
ASSERT_NEAR(0.0039, getInjectionMass(200), EPS3D);
|
2022-06-09 14:21:22 -07:00
|
|
|
|
2018-03-10 17:58:51 -08:00
|
|
|
// skip, clear & advance 1 more revolution at higher RPM
|
2018-07-28 17:02:01 -07:00
|
|
|
eth.fireFall(60);
|
2018-03-10 17:58:51 -08:00
|
|
|
|
|
|
|
eth.clearQueue();
|
2018-07-28 16:37:10 -07:00
|
|
|
eth.fireTriggerEventsWithDuration(60);
|
2018-03-10 17:58:51 -08:00
|
|
|
|
|
|
|
// 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());
|
2018-03-10 17:58:51 -08:00
|
|
|
// check RPM
|
2024-02-28 20:22:01 -08:00
|
|
|
eth.assertRpm( 1000, "RPM#3");
|
2018-03-10 17:58:51 -08:00
|
|
|
// check if the injection mode is back to sequential now
|
2022-09-04 23:44:06 -07:00
|
|
|
ASSERT_EQ(IM_SEQUENTIAL, getCurrentInjectionMode());
|
2024-02-29 06:49:03 -08:00
|
|
|
ASSERT_NEAR(0.0, getInjectionMass(200), EPS3D); // in this test fuel calculation is not active in running mode
|
2018-03-10 17:58:51 -08:00
|
|
|
// 4 sequential injections for the full cycle
|
2024-07-11 17:03:13 -07:00
|
|
|
ASSERT_EQ( 8, engine->scheduler.size()) << "plain#3";
|
2018-03-10 17:58:51 -08:00
|
|
|
|
|
|
|
// check real events for sequential injection
|
|
|
|
// Note: See addFuelEvents() fix inside setRpmValue()!
|
2024-02-28 20:22:01 -08:00
|
|
|
expectedSimultaneousTimestamp = eth.angleToTimeUs(phase);
|
|
|
|
ASSERT_EQ(180, eth.timeToAngle(30.000));
|
|
|
|
eth.assertEvent5("inj start#3", 0, (void*)turnInjectionPinHigh, -expectedSimultaneousTimestamp - 1625);
|
|
|
|
eth.assertEvent5("inj end#3", 1, (void*)turnInjectionPinLow, -expectedSimultaneousTimestamp);
|
2018-03-10 17:58:51 -08:00
|
|
|
}
|
2019-01-20 19:21:12 -08:00
|
|
|
|
2019-01-24 18:12:55 -08:00
|
|
|
static void doTestFasterEngineSpinningUp60_2(int startUpDelayMs, int rpm1, int expectedRpm) {
|
2023-05-31 22:31:28 -07:00
|
|
|
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
2019-01-20 19:21:12 -08:00
|
|
|
// turn on FasterEngineSpinUp mode
|
2019-12-11 14:48:55 -08:00
|
|
|
engineConfiguration->isFasterEngineSpinUpEnabled = true;
|
2019-01-20 19:21:12 -08:00
|
|
|
|
2023-05-31 23:11:27 -07:00
|
|
|
setupSimpleTestEngineWithMaf(ð, IM_SEQUENTIAL, trigger_type_e::TT_TOOTHED_WHEEL_60_2);
|
2019-01-21 19:45:37 -08:00
|
|
|
eth.moveTimeForwardMs(startUpDelayMs);
|
2019-01-20 19:21:12 -08:00
|
|
|
|
2022-09-25 04:40:28 -07:00
|
|
|
// fire 30 tooth rise/fall signals
|
|
|
|
eth.fireTriggerEvents2(30 /* count */, 1 /*ms*/);
|
|
|
|
// now fire missed tooth rise/fall
|
|
|
|
eth.fireRise(5 /*ms*/);
|
|
|
|
EXPECT_EQ(rpm1, round(Sensor::getOrZero(SensorType::Rpm)));
|
|
|
|
|
|
|
|
eth.fireFall(1);
|
|
|
|
eth.fireTriggerEvents2(30, 1);
|
|
|
|
|
|
|
|
// After some more regular teeth, instant RPM is still correct
|
|
|
|
EXPECT_EQ(rpm1, round(Sensor::getOrZero(SensorType::Rpm)));
|
|
|
|
}
|
|
|
|
|
2019-01-21 19:45:37 -08:00
|
|
|
TEST(cranking, testFasterEngineSpinningUp60_2) {
|
2021-08-03 22:17:14 -07:00
|
|
|
doTestFasterEngineSpinningUp60_2(0, 1000, 1000);
|
|
|
|
doTestFasterEngineSpinningUp60_2(100, 1000, 1000);
|
|
|
|
doTestFasterEngineSpinningUp60_2(1000, 1000, 1000);
|
2019-01-20 19:21:12 -08:00
|
|
|
}
|