2019-01-13 19:52:22 -08:00
|
|
|
/*
|
2020-05-09 21:59:32 -07:00
|
|
|
* test_cam_vvt_input.cpp
|
2019-01-13 19:52:22 -08:00
|
|
|
*
|
|
|
|
* Created on: Jan 13, 2019
|
2020-01-07 21:02:40 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2019-01-13 19:52:22 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "engine_test_helper.h"
|
2019-05-10 19:55:08 -07:00
|
|
|
extern WarningCodeState unitTestWarningCodeState;
|
|
|
|
|
2021-04-04 19:48:48 -07:00
|
|
|
#include "engine_sniffer.h"
|
|
|
|
extern WaveChart waveChart;
|
|
|
|
|
2021-02-08 13:16:26 -08:00
|
|
|
TEST(trigger, testNoStartUpWarningsNoSyncronizationTrigger) {
|
2019-05-10 19:55:08 -07:00
|
|
|
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
|
|
|
|
// one tooth does not need synchronization it just counts tooth
|
|
|
|
eth.setTriggerType(TT_ONE PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
ASSERT_EQ( 0, GET_RPM()) << "testNoStartUpWarnings RPM";
|
|
|
|
|
|
|
|
eth.fireTriggerEvents2(/*count*/10, /*duration*/50);
|
|
|
|
ASSERT_EQ(1200, GET_RPM()) << "testNoStartUpWarnings RPM";
|
|
|
|
ASSERT_EQ( 0, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#testNoStartUpWarningsNoSyncronizationTrigger";
|
|
|
|
}
|
|
|
|
|
2021-02-08 13:16:26 -08:00
|
|
|
TEST(trigger, testNoStartUpWarnings) {
|
2019-05-10 19:55:08 -07:00
|
|
|
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
|
2019-05-10 20:12:36 -07:00
|
|
|
// for this test we need a trigger with isSynchronizationNeeded=true
|
|
|
|
engineConfiguration->trigger.customTotalToothCount = 3;
|
|
|
|
engineConfiguration->trigger.customSkippedToothCount = 1;
|
|
|
|
eth.setTriggerType(TT_TOOTHED_WHEEL PASS_ENGINE_PARAMETER_SUFFIX);
|
2019-05-10 19:55:08 -07:00
|
|
|
ASSERT_EQ( 0, GET_RPM()) << "testNoStartUpWarnings RPM";
|
|
|
|
|
2019-05-10 20:12:36 -07:00
|
|
|
for (int i = 0;i < 10;i++) {
|
|
|
|
eth.fireRise(50);
|
|
|
|
eth.fireFall(50);
|
|
|
|
eth.fireRise(50);
|
|
|
|
eth.fireFall(150);
|
|
|
|
}
|
2019-05-10 19:55:08 -07:00
|
|
|
|
2019-05-10 20:12:36 -07:00
|
|
|
ASSERT_EQ(400, GET_RPM()) << "testNoStartUpWarnings RPM";
|
2019-05-10 19:55:08 -07:00
|
|
|
ASSERT_EQ( 0, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#testNoStartUpWarnings";
|
2019-05-10 20:12:36 -07:00
|
|
|
// now let's post something unneeded
|
2019-05-10 19:55:08 -07:00
|
|
|
eth.fireRise(50);
|
2019-05-10 20:12:36 -07:00
|
|
|
eth.fireFall(50);
|
|
|
|
eth.fireRise(50); // this is noise
|
|
|
|
eth.fireFall(50); // this is noise
|
2019-05-10 19:55:08 -07:00
|
|
|
eth.fireRise(50);
|
2019-05-10 20:12:36 -07:00
|
|
|
eth.fireFall(150);
|
|
|
|
for (int i = 0;i < 1;i++) {
|
|
|
|
eth.fireRise(50);
|
|
|
|
eth.fireFall(50);
|
|
|
|
eth.fireRise(50);
|
|
|
|
eth.fireFall(150);
|
|
|
|
}
|
|
|
|
ASSERT_EQ( 2, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#testNoStartUpWarnings CUSTOM_SYNC_COUNT_MISMATCH expected";
|
|
|
|
ASSERT_EQ(CUSTOM_SYNC_ERROR, unitTestWarningCodeState.recentWarnings.get(0));
|
|
|
|
ASSERT_EQ(CUSTOM_SYNC_COUNT_MISMATCH, unitTestWarningCodeState.recentWarnings.get(1));
|
2019-05-10 19:55:08 -07:00
|
|
|
}
|
|
|
|
|
2021-02-08 13:16:26 -08:00
|
|
|
TEST(trigger, testNoisyInput) {
|
2019-05-10 20:20:42 -07:00
|
|
|
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
|
2019-05-10 18:56:33 -07:00
|
|
|
|
2019-05-10 20:20:42 -07:00
|
|
|
ASSERT_EQ( 0, GET_RPM()) << "testNoisyInput RPM";
|
2019-05-10 18:56:33 -07:00
|
|
|
|
|
|
|
eth.firePrimaryTriggerRise();
|
2019-05-10 19:55:08 -07:00
|
|
|
eth.firePrimaryTriggerFall();
|
2019-05-10 18:56:33 -07:00
|
|
|
eth.firePrimaryTriggerRise();
|
2019-05-10 19:55:08 -07:00
|
|
|
eth.firePrimaryTriggerFall();
|
2019-05-10 18:56:33 -07:00
|
|
|
eth.firePrimaryTriggerRise();
|
2019-05-10 19:55:08 -07:00
|
|
|
eth.firePrimaryTriggerFall();
|
2019-05-10 18:56:33 -07:00
|
|
|
eth.firePrimaryTriggerRise();
|
2019-05-10 19:55:08 -07:00
|
|
|
eth.firePrimaryTriggerFall();
|
|
|
|
// error condition since events happened too quick while time does not move
|
2019-05-10 20:20:42 -07:00
|
|
|
ASSERT_EQ(NOISY_RPM, GET_RPM()) << "testNoisyInput RPM should be noisy";
|
|
|
|
|
|
|
|
ASSERT_EQ( 2, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#testNoisyInput";
|
|
|
|
ASSERT_EQ(CUSTOM_SYNC_COUNT_MISMATCH, unitTestWarningCodeState.recentWarnings.get(0)) << "@0";
|
2019-05-10 20:52:55 -07:00
|
|
|
ASSERT_EQ(OBD_Crankshaft_Position_Sensor_A_Circuit_Malfunction, unitTestWarningCodeState.recentWarnings.get(1)) << "@0";
|
2019-05-10 20:20:42 -07:00
|
|
|
}
|
|
|
|
|
2021-02-08 13:16:26 -08:00
|
|
|
TEST(trigger, testCamInput) {
|
2019-05-10 20:20:42 -07:00
|
|
|
// setting some weird engine
|
|
|
|
WITH_ENGINE_TEST_HELPER(FORD_ESCORT_GT);
|
|
|
|
|
2020-02-04 22:08:39 -08:00
|
|
|
// changing to 'ONE TOOTH' trigger on CRANK with CAM/VVT
|
2019-05-10 20:20:42 -07:00
|
|
|
setOperationMode(engineConfiguration, FOUR_STROKE_CRANK_SENSOR);
|
|
|
|
engineConfiguration->useOnlyRisingEdgeForTrigger = true;
|
2021-02-08 18:50:31 -08:00
|
|
|
engineConfiguration->vvtMode[0] = VVT_FIRST_HALF;
|
2021-07-03 09:02:00 -07:00
|
|
|
engineConfiguration->vvtOffsets[0] = 360;
|
2019-05-10 20:52:55 -07:00
|
|
|
eth.setTriggerType(TT_ONE PASS_ENGINE_PARAMETER_SUFFIX);
|
2019-07-12 11:24:45 -07:00
|
|
|
engineConfiguration->camInputs[0] = GPIOA_10; // we just need to indicate that we have CAM
|
2019-05-10 20:20:42 -07:00
|
|
|
|
|
|
|
ASSERT_EQ( 0, GET_RPM()) << "testCamInput RPM";
|
2019-05-10 18:56:33 -07:00
|
|
|
|
2019-05-10 21:21:37 -07:00
|
|
|
for (int i = 0; i < 5;i++) {
|
|
|
|
eth.fireRise(50);
|
|
|
|
}
|
2019-05-10 20:52:55 -07:00
|
|
|
|
2019-05-10 18:56:33 -07:00
|
|
|
ASSERT_EQ(1200, GET_RPM()) << "testCamInput RPM";
|
2019-05-10 20:52:55 -07:00
|
|
|
ASSERT_EQ(0, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#testCamInput";
|
2019-05-10 19:55:08 -07:00
|
|
|
|
2019-05-10 21:21:37 -07:00
|
|
|
for (int i = 0; i < 600;i++) {
|
2019-05-10 19:55:08 -07:00
|
|
|
eth.fireRise(50);
|
2019-05-10 20:52:55 -07:00
|
|
|
}
|
|
|
|
|
2020-02-04 22:08:39 -08:00
|
|
|
// asserting that lack of camshaft signal would be detecting
|
2019-05-10 21:21:37 -07:00
|
|
|
ASSERT_EQ(1, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#testCamInput #2";
|
|
|
|
ASSERT_EQ(OBD_Camshaft_Position_Sensor_Circuit_Range_Performance, unitTestWarningCodeState.recentWarnings.get(0)) << "@0";
|
|
|
|
unitTestWarningCodeState.recentWarnings.clear();
|
2019-05-10 20:52:55 -07:00
|
|
|
|
2019-05-10 21:21:37 -07:00
|
|
|
for (int i = 0; i < 600;i++) {
|
2020-02-04 22:08:39 -08:00
|
|
|
eth.moveTimeForwardUs(MS2US(10));
|
2021-01-31 19:24:45 -08:00
|
|
|
hwHandleVvtCamSignal(TV_FALL, getTimeNowNt(), 0 PASS_ENGINE_PARAMETER_SUFFIX);
|
2020-02-04 22:08:39 -08:00
|
|
|
eth.moveTimeForwardUs(MS2US(40));
|
|
|
|
eth.firePrimaryTriggerRise();
|
2019-05-10 20:52:55 -07:00
|
|
|
}
|
|
|
|
|
2020-02-04 22:08:39 -08:00
|
|
|
// asserting that error code has cleared
|
2019-05-10 20:52:55 -07:00
|
|
|
ASSERT_EQ(0, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#testCamInput #3";
|
2021-04-08 12:01:12 -07:00
|
|
|
ASSERT_NEAR(360 - 181, engine->triggerCentral.getVVTPosition(0, 0), EPS3D);
|
2019-01-13 19:52:22 -08:00
|
|
|
}
|
2020-01-29 22:47:34 -08:00
|
|
|
|
|
|
|
TEST(sensors, testNB2CamInput) {
|
|
|
|
WITH_ENGINE_TEST_HELPER(MAZDA_MIATA_2003);
|
|
|
|
|
|
|
|
// this crank trigger would be easier to test, crank shape is less important for this test
|
|
|
|
eth.setTriggerType(TT_ONE PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
|
2021-02-08 18:07:43 -08:00
|
|
|
engineConfiguration->useOnlyRisingEdgeForTrigger = true;
|
|
|
|
|
2020-01-29 22:47:34 -08:00
|
|
|
ASSERT_EQ( 0, GET_RPM()) << "testNB2CamInput RPM";
|
2020-02-14 10:02:27 -08:00
|
|
|
for (int i = 0; i < 7;i++) {
|
|
|
|
eth.fireRise(25);
|
|
|
|
ASSERT_EQ( 0, GET_RPM()) << "testNB2CamInput RPM";
|
2020-01-29 22:47:34 -08:00
|
|
|
}
|
2020-02-14 10:02:27 -08:00
|
|
|
eth.fireRise(25);
|
|
|
|
// first time we have RPM
|
2020-01-29 22:47:34 -08:00
|
|
|
ASSERT_EQ(1200, GET_RPM()) << "testNB2CamInput RPM";
|
|
|
|
|
2020-02-14 10:02:27 -08:00
|
|
|
int totalRevolutionCountBeforeVvtSync = 10;
|
|
|
|
// need to be out of VVT sync to see VVT sync in action
|
|
|
|
eth.fireRise(25);
|
|
|
|
eth.fireRise(25);
|
|
|
|
ASSERT_EQ(totalRevolutionCountBeforeVvtSync, engine->triggerCentral.triggerState.getTotalRevolutionCounter());
|
|
|
|
ASSERT_TRUE((totalRevolutionCountBeforeVvtSync % SYMMETRICAL_CRANK_SENSOR_DIVIDER) != 0);
|
|
|
|
|
2020-05-09 22:21:54 -07:00
|
|
|
eth.moveTimeForwardUs(MS2US(3)); // shifting VVT phase a few angles
|
2020-02-14 10:02:27 -08:00
|
|
|
|
|
|
|
// this would be ignored since we only consume the other kind of fronts here
|
2021-01-31 19:24:45 -08:00
|
|
|
hwHandleVvtCamSignal(TV_FALL, getTimeNowNt(), 0 PASS_ENGINE_PARAMETER_SUFFIX);
|
2020-01-29 22:47:34 -08:00
|
|
|
eth.moveTimeForwardUs(MS2US(20));
|
2020-01-30 22:23:01 -08:00
|
|
|
// this would be be first VVT signal - gap duration would be calculated against 'DEEP_IN_THE_PAST_SECONDS' initial value
|
2021-01-31 19:24:45 -08:00
|
|
|
hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), 0 PASS_ENGINE_PARAMETER_SUFFIX);
|
2020-01-30 22:23:01 -08:00
|
|
|
|
2021-04-06 22:21:28 -07:00
|
|
|
eth.moveTimeForwardUs(MS2US(10));
|
|
|
|
hwHandleVvtCamSignal(TV_FALL, getTimeNowNt(), 0 PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
eth.moveTimeForwardUs(MS2US(10));
|
2020-01-30 22:23:01 -08:00
|
|
|
// this second important front would give us first real VVT gap duration
|
2021-01-31 19:24:45 -08:00
|
|
|
hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), 0 PASS_ENGINE_PARAMETER_SUFFIX);
|
2020-01-30 22:23:01 -08:00
|
|
|
|
2021-03-25 04:39:23 -07:00
|
|
|
ASSERT_FLOAT_EQ(0, engine->triggerCentral.getVVTPosition(0, 0));
|
2020-02-14 10:02:27 -08:00
|
|
|
ASSERT_EQ(totalRevolutionCountBeforeVvtSync, engine->triggerCentral.triggerState.getTotalRevolutionCounter());
|
2020-01-30 22:49:10 -08:00
|
|
|
|
2021-04-06 22:21:28 -07:00
|
|
|
eth.moveTimeForwardUs(MS2US(100));
|
|
|
|
hwHandleVvtCamSignal(TV_FALL, getTimeNowNt(), 0 PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
eth.moveTimeForwardUs(MS2US( 30));
|
2020-01-30 22:23:01 -08:00
|
|
|
// this third important front would give us first comparison between two real gaps
|
2021-01-31 19:24:45 -08:00
|
|
|
hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), 0 PASS_ENGINE_PARAMETER_SUFFIX);
|
2020-01-30 22:49:10 -08:00
|
|
|
|
2021-03-25 04:39:23 -07:00
|
|
|
ASSERT_NEAR(-67.6 - 720 - 720, engine->triggerCentral.getVVTPosition(0, 0), EPS3D);
|
2020-01-31 10:45:15 -08:00
|
|
|
// actually position based on VVT!
|
2020-02-14 10:02:27 -08:00
|
|
|
ASSERT_EQ(totalRevolutionCountBeforeVvtSync + 2, engine->triggerCentral.triggerState.getTotalRevolutionCounter());
|
2021-04-04 19:48:48 -07:00
|
|
|
|
2021-04-06 22:21:28 -07:00
|
|
|
float dutyCycleNt = engine->triggerCentral.vvtState[0][0].currentCycle.totalTimeNtCopy[0];
|
|
|
|
ASSERT_FLOAT_EQ(6'000'000, dutyCycleNt);
|
|
|
|
ASSERT_FLOAT_EQ(0.059722222, engine->triggerCentral.vvtShape[0].expectedDutyCycle[0]);
|
|
|
|
|
2021-04-04 20:12:07 -07:00
|
|
|
ASSERT_EQ(26, waveChart.getSize());
|
2020-01-29 22:47:34 -08:00
|
|
|
}
|