2020-02-13 21:37:36 -08:00
|
|
|
/*
|
|
|
|
* @file test_symmetrical_crank.cpp
|
|
|
|
*
|
|
|
|
* @date Feb 14, 2020
|
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
|
|
|
*/
|
|
|
|
|
2021-08-03 19:05:01 -07:00
|
|
|
#include "pch.h"
|
2020-02-13 21:37:36 -08:00
|
|
|
|
2020-02-14 06:33:29 -08:00
|
|
|
static void postFourEvents(EngineTestHelper *eth, float mult) {
|
2021-07-23 13:43:24 -07:00
|
|
|
eth->fireFall(mult * 394);
|
2020-02-14 06:33:29 -08:00
|
|
|
eth->fireRise(mult * 16);
|
2021-07-23 13:43:24 -07:00
|
|
|
eth->fireFall(mult * 294);
|
2020-02-14 06:33:29 -08:00
|
|
|
eth->fireRise(mult * 16);
|
|
|
|
}
|
|
|
|
|
2021-07-17 14:47:13 -07:00
|
|
|
TEST(engine, testAngleLogicInSymmetricalCrankIssue2980) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(FRANKENSO_MAZDA_MIATA_2003);
|
2021-07-17 14:47:13 -07:00
|
|
|
|
2021-11-17 00:54:21 -08:00
|
|
|
TriggerFormDetails *triggerForm = &engine->triggerCentral.triggerFormDetails;
|
2021-07-17 14:47:13 -07:00
|
|
|
|
2021-11-17 00:54:21 -08:00
|
|
|
TriggerWaveform * form = &engine->triggerCentral.triggerShape;
|
2021-07-17 14:47:13 -07:00
|
|
|
|
2021-07-17 20:27:20 -07:00
|
|
|
#define EXPECT_FINDANGLE(angle, idx) EXPECT_EQ(form->findAngleIndex(triggerForm, angle) & 0xFFFF'FFFE, idx);
|
2021-07-17 16:43:17 -07:00
|
|
|
|
2021-07-17 20:27:20 -07:00
|
|
|
// Check one angle just after every trigger tooth, for two full revolutions (720 degrees, one engine cycle, 4 loops of the trigger)
|
2021-07-17 16:43:17 -07:00
|
|
|
|
2021-07-17 20:27:20 -07:00
|
|
|
// First quarter
|
|
|
|
EXPECT_FINDANGLE(0 * 180 + 5, 0); // 5
|
|
|
|
EXPECT_FINDANGLE(0 * 180 + 115, 2); // 115
|
2021-07-17 16:43:17 -07:00
|
|
|
|
2021-07-17 20:27:20 -07:00
|
|
|
// Second quarter
|
|
|
|
EXPECT_FINDANGLE(1 * 180 + 5, 4); // 180+5 = 185
|
|
|
|
EXPECT_FINDANGLE(1 * 180 + 115, 6); // 180+115 = 295
|
|
|
|
|
|
|
|
// Third quarter
|
|
|
|
EXPECT_FINDANGLE(2 * 180 + 5, 8); // 360+5 = 365
|
|
|
|
EXPECT_FINDANGLE(2 * 180 + 115, 10); // 360+115 = 475
|
|
|
|
|
|
|
|
// Fourth quarter
|
|
|
|
EXPECT_FINDANGLE(3 * 180 + 5, 12); // 540+5 = 545
|
|
|
|
EXPECT_FINDANGLE(3 * 180 + 115, 14); // 540+115 = 655
|
2021-07-17 14:47:13 -07:00
|
|
|
}
|
|
|
|
|
2020-02-13 21:37:36 -08:00
|
|
|
TEST(engine, testSymmetricalCrank) {
|
|
|
|
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(FRANKENSO_MAZDA_MIATA_2003);
|
2020-02-13 21:37:36 -08:00
|
|
|
|
2020-02-14 06:33:29 -08:00
|
|
|
// this test is not about isFasterEngineSpinUpEnabled so let's disable it to simplify things
|
2021-11-17 00:54:21 -08:00
|
|
|
engineConfiguration->isFasterEngineSpinUpEnabled = false;
|
2022-08-19 12:03:20 -07:00
|
|
|
engineConfiguration->alwaysInstantRpm = true;
|
2020-02-14 07:49:22 -08:00
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
ASSERT_EQ(FOUR_STROKE_SYMMETRICAL_CRANK_SENSOR, engine->getOperationMode());
|
2020-02-14 07:49:22 -08:00
|
|
|
|
|
|
|
float mult = 0.02;
|
2020-02-13 21:37:36 -08:00
|
|
|
|
2022-01-20 20:19:48 -08:00
|
|
|
ASSERT_EQ( 0, round(Sensor::getOrZero(SensorType::Rpm))) << "RPM#0";
|
2020-02-13 21:37:36 -08:00
|
|
|
|
2020-02-14 07:49:22 -08:00
|
|
|
postFourEvents(ð, mult);
|
2022-01-20 20:19:48 -08:00
|
|
|
ASSERT_EQ( 0, round(Sensor::getOrZero(SensorType::Rpm))) << "RPM#0";
|
2020-02-14 07:49:22 -08:00
|
|
|
|
2021-07-23 13:43:24 -07:00
|
|
|
eth.fireFall(mult * 394);
|
2020-02-14 07:49:22 -08:00
|
|
|
eth.fireRise(mult * 16);
|
2021-07-23 13:43:24 -07:00
|
|
|
eth.fireFall(mult * 294);
|
2021-07-03 07:37:03 -07:00
|
|
|
ASSERT_FALSE(engine->triggerCentral.triggerState.getShaftSynchronized());
|
2020-02-14 07:49:22 -08:00
|
|
|
eth.fireRise(mult * 16);
|
2021-07-03 07:37:03 -07:00
|
|
|
ASSERT_TRUE(engine->triggerCentral.triggerState.getShaftSynchronized());
|
2020-02-14 07:49:22 -08:00
|
|
|
|
2022-01-20 20:19:48 -08:00
|
|
|
ASSERT_EQ( 0, round(Sensor::getOrZero(SensorType::Rpm))) << "RPM#0";
|
2020-02-14 07:49:22 -08:00
|
|
|
|
|
|
|
postFourEvents(ð, mult);
|
2022-01-20 20:19:48 -08:00
|
|
|
ASSERT_EQ(2084, round(Sensor::getOrZero(SensorType::Rpm))) << "RPM#11";
|
2020-02-13 21:37:36 -08:00
|
|
|
|
2020-02-14 07:49:22 -08:00
|
|
|
postFourEvents(ð, mult);
|
2022-01-20 20:19:48 -08:00
|
|
|
ASSERT_EQ(2084, round(Sensor::getOrZero(SensorType::Rpm))) << "RPM#11";
|
2020-02-13 21:37:36 -08:00
|
|
|
|
2020-02-14 07:49:22 -08:00
|
|
|
postFourEvents(ð, mult);
|
2022-01-20 20:19:48 -08:00
|
|
|
ASSERT_EQ(2084, round(Sensor::getOrZero(SensorType::Rpm))) << "RPM#11";
|
2020-02-13 21:37:36 -08:00
|
|
|
}
|