From 4b95262a5d30705e8c045e6fd89da46b6102b108 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Wed, 21 Jul 2021 15:48:05 -0700 Subject: [PATCH] simplify quad vvt test (#3018) * use single tooth in quad cam test * mod == remainder * now the test works without changes --- unit_tests/tests/trigger/test_quad_cam.cpp | 92 ++++++++++------------ 1 file changed, 43 insertions(+), 49 deletions(-) diff --git a/unit_tests/tests/trigger/test_quad_cam.cpp b/unit_tests/tests/trigger/test_quad_cam.cpp index 39e169fe37..d60092455c 100644 --- a/unit_tests/tests/trigger/test_quad_cam.cpp +++ b/unit_tests/tests/trigger/test_quad_cam.cpp @@ -9,10 +9,12 @@ TEST(trigger, testQuadCam) { // setting some weird engine WITH_ENGINE_TEST_HELPER(FORD_ESCORT_GT); + setOperationMode(engineConfiguration, FOUR_STROKE_CRANK_SENSOR); + // changing to 'ONE TOOTH' trigger on CRANK with CAM/VVT engineConfiguration->useOnlyRisingEdgeForTrigger = true; - engineConfiguration->vvtMode[0] = VVT_2JZ; - engineConfiguration->vvtMode[1] = VVT_MIATA_NB2; + engineConfiguration->vvtMode[0] = VVT_FIRST_HALF; + engineConfiguration->vvtMode[1] = VVT_FIRST_HALF; engineConfiguration->camInputs[0] = GPIOA_10; // we just need to indicate that we have CAM @@ -20,21 +22,20 @@ TEST(trigger, testQuadCam) { eth.setTriggerType(TT_ONE PASS_ENGINE_PARAMETER_SUFFIX); engineConfiguration->useOnlyRisingEdgeForTrigger = true; + engineConfiguration->vvtCamSensorUseRise = true; - ASSERT_EQ( 0, GET_RPM()) << "testQuadCam RPM no sync"; - for (int i = 0; i < 1;i++) { + ASSERT_EQ(0, GET_RPM()); + for (int i = 0; i < 3;i++) { eth.fireRise(25); - ASSERT_EQ( 0, GET_RPM()) << "testQuadCam RPM still no sync"; + ASSERT_EQ( 0, GET_RPM()); } eth.fireRise(25); // first time we have RPM - ASSERT_EQ(4800, GET_RPM()) << "testQuadCam RPM"; + ASSERT_EQ(2400, GET_RPM()); - int totalRevolutionCountBeforeVvtSync = 4; // 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()); eth.moveTimeForwardUs(MS2US(3)); // shifting VVT phase a few angles @@ -43,52 +44,45 @@ TEST(trigger, testQuadCam) { int firstCam = 0; int secondCam = 1; - // this would be ignored since we only consume the other kind of fronts here - hwHandleVvtCamSignal(TV_FALL, getTimeNowNt(), secondCam PASS_ENGINE_PARAMETER_SUFFIX); - eth.moveTimeForwardUs(MS2US(20 / d)); - hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), firstCam PASS_ENGINE_PARAMETER_SUFFIX); - // this would be be first VVT signal - gap duration would be calculated against 'DEEP_IN_THE_PAST_SECONDS' initial value - hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), secondCam PASS_ENGINE_PARAMETER_SUFFIX); - - eth.moveTimeForwardUs(MS2US(20 / d)); - hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), secondCam PASS_ENGINE_PARAMETER_SUFFIX); - // this second important front would give us first real VVT gap duration - hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), secondCam PASS_ENGINE_PARAMETER_SUFFIX); - - ASSERT_FLOAT_EQ(0, engine->triggerCentral.getVVTPosition(0, firstCam)); - ASSERT_EQ(totalRevolutionCountBeforeVvtSync, engine->triggerCentral.triggerState.getTotalRevolutionCounter()); - - eth.moveTimeForwardUs(MS2US(130 / d)); - // this third important front would give us first comparison between two real gaps - hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), secondCam PASS_ENGINE_PARAMETER_SUFFIX); - - ASSERT_NEAR(0, engine->triggerCentral.getVVTPosition(0, secondCam), EPS3D); - // actually position based on VVT! - ASSERT_EQ(totalRevolutionCountBeforeVvtSync, engine->triggerCentral.triggerState.getTotalRevolutionCounter()); - - + int firstBank = 0; int secondBank = 1; + + int firstCamSecondBank = secondBank * CAMS_PER_BANK + firstCam; int secondCamSecondBank = secondBank * CAMS_PER_BANK + secondCam; - // this would be ignored since we only consume the other kind of fronts here - hwHandleVvtCamSignal(TV_FALL, getTimeNowNt(), secondCamSecondBank PASS_ENGINE_PARAMETER_SUFFIX); - eth.moveTimeForwardUs(MS2US(20 / d)); - // this would be be first VVT signal - gap duration would be calculated against 'DEEP_IN_THE_PAST_SECONDS' initial value + // Cams should have no position yet + ASSERT_EQ(0, engine->triggerCentral.getVVTPosition(firstBank, firstCam)); + ASSERT_EQ(0, engine->triggerCentral.getVVTPosition(firstBank, secondCam)); + ASSERT_EQ(0, engine->triggerCentral.getVVTPosition(secondBank, firstCam)); + ASSERT_EQ(0, engine->triggerCentral.getVVTPosition(secondBank, secondCam)); + + hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), firstCam PASS_ENGINE_PARAMETER_SUFFIX); + hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), secondCam PASS_ENGINE_PARAMETER_SUFFIX); + hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), firstCamSecondBank PASS_ENGINE_PARAMETER_SUFFIX); hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), secondCamSecondBank PASS_ENGINE_PARAMETER_SUFFIX); - eth.moveTimeForwardUs(MS2US(20 / d)); - // this second important front would give us first real VVT gap duration + float basePos = -80.2f; + + // All four cams should now have the same position + EXPECT_NEAR(basePos, engine->triggerCentral.getVVTPosition(firstBank, firstCam), EPS3D); + EXPECT_NEAR(basePos, engine->triggerCentral.getVVTPosition(firstBank, secondCam), EPS3D); + EXPECT_NEAR(basePos, engine->triggerCentral.getVVTPosition(secondBank, firstCam), EPS3D); + EXPECT_NEAR(basePos, engine->triggerCentral.getVVTPosition(secondBank, secondCam), EPS3D); + + // Now fire cam events again, but with time gaps between each + eth.moveTimeForwardMs(1); + hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), firstCam PASS_ENGINE_PARAMETER_SUFFIX); + eth.moveTimeForwardMs(1); + hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), secondCam PASS_ENGINE_PARAMETER_SUFFIX); + eth.moveTimeForwardMs(1); + hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), firstCamSecondBank PASS_ENGINE_PARAMETER_SUFFIX); + eth.moveTimeForwardMs(1); hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), secondCamSecondBank PASS_ENGINE_PARAMETER_SUFFIX); - ASSERT_FLOAT_EQ(0, engine->triggerCentral.getVVTPosition(0, firstCam)); - ASSERT_EQ(totalRevolutionCountBeforeVvtSync, engine->triggerCentral.triggerState.getTotalRevolutionCounter()); - - eth.moveTimeForwardUs(MS2US(130 / d)); - // this third important front would give us first comparison between two real gaps - hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), secondCamSecondBank PASS_ENGINE_PARAMETER_SUFFIX); - - ASSERT_NEAR(308.6, engine->triggerCentral.getVVTPosition(secondBank, secondCam), EPS3D); - // actually position based on VVT! - ASSERT_EQ(totalRevolutionCountBeforeVvtSync, engine->triggerCentral.triggerState.getTotalRevolutionCounter()); - + // All four cams should have different positions, each retarded by 1ms from the last + float oneMsDegrees = 1000 / ENGINE(rpmCalculator).oneDegreeUs; + EXPECT_NEAR(basePos - oneMsDegrees * 1, engine->triggerCentral.getVVTPosition(firstBank, firstCam), EPS3D); + EXPECT_NEAR(basePos - oneMsDegrees * 2, engine->triggerCentral.getVVTPosition(firstBank, secondCam), EPS3D); + EXPECT_NEAR(basePos - oneMsDegrees * 3, engine->triggerCentral.getVVTPosition(secondBank, firstCam), EPS3D); + EXPECT_NEAR(basePos - oneMsDegrees * 4, engine->triggerCentral.getVVTPosition(secondBank, secondCam), EPS3D); }