rusefi/unit_tests/tests/trigger/test_quad_cam.cpp

89 lines
3.3 KiB
C++
Raw Normal View History

2021-02-08 13:16:26 -08:00
/**
* @file test_quad_cam.cpp
*
*/
#include "pch.h"
2021-02-08 13:16:26 -08:00
TEST(trigger, testQuadCam) {
2021-02-08 15:08:26 -08:00
// setting some weird engine
EngineTestHelper eth(FORD_ESCORT_GT);
2021-02-08 13:16:26 -08:00
setOperationMode(engineConfiguration, FOUR_STROKE_CRANK_SENSOR);
2021-02-08 15:08:26 -08:00
// changing to 'ONE TOOTH' trigger on CRANK with CAM/VVT
engineConfiguration->useOnlyRisingEdgeForTrigger = true;
engineConfiguration->vvtMode[0] = VVT_FIRST_HALF;
engineConfiguration->vvtMode[1] = VVT_FIRST_HALF;
2021-02-08 15:08:26 -08:00
engineConfiguration->camInputs[0] = GPIOA_10; // we just need to indicate that we have CAM
2021-02-08 18:07:43 -08:00
// this crank trigger would be easier to test, crank shape is less important for this test
eth.setTriggerType(TT_ONE);
2021-02-08 18:07:43 -08:00
engineConfiguration->useOnlyRisingEdgeForTrigger = true;
engineConfiguration->vvtCamSensorUseRise = true;
2021-02-08 18:07:43 -08:00
ASSERT_EQ(0, GET_RPM());
for (int i = 0; i < 3;i++) {
2021-02-08 18:07:43 -08:00
eth.fireRise(25);
ASSERT_EQ( 0, GET_RPM());
2021-02-08 18:07:43 -08:00
}
eth.fireRise(25);
// first time we have RPM
ASSERT_EQ(2400, GET_RPM());
2021-02-08 18:07:43 -08:00
// need to be out of VVT sync to see VVT sync in action
eth.fireRise(25);
eth.fireRise(25);
eth.moveTimeForwardUs(MS2US(3)); // shifting VVT phase a few angles
float d = 4;
2021-07-05 17:56:24 -07:00
int firstCam = 0;
2021-02-08 19:41:31 -08:00
int secondCam = 1;
int firstBank = 0;
int secondBank = 1;
2021-02-08 18:07:43 -08:00
int firstCamSecondBank = secondBank * CAMS_PER_BANK + firstCam;
int secondCamSecondBank = secondBank * CAMS_PER_BANK + secondCam;
2021-02-08 18:07:43 -08:00
// 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));
2021-02-08 18:07:43 -08:00
hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), firstCam);
hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), secondCam);
hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), firstCamSecondBank);
hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), secondCamSecondBank);
2021-02-09 07:16:49 -08:00
float basePos = -80.2f;
2021-02-09 07:16:49 -08:00
// All four cams should now have the same position
EXPECT_NEAR(360 + 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);
2021-02-09 07:16:49 -08:00
// Now fire cam events again, but with time gaps between each
eth.moveTimeForwardMs(1);
hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), firstCam);
eth.moveTimeForwardMs(1);
hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), secondCam);
eth.moveTimeForwardMs(1);
hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), firstCamSecondBank);
eth.moveTimeForwardMs(1);
hwHandleVvtCamSignal(TV_RISE, getTimeNowNt(), secondCamSecondBank);
2021-02-09 07:16:49 -08:00
// 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);
2021-02-08 13:16:26 -08:00
}