2021-08-03 19:05:01 -07:00
|
|
|
#include "pch.h"
|
|
|
|
|
2021-03-14 16:31:46 -07:00
|
|
|
#include "vvt.h"
|
|
|
|
|
|
|
|
using ::testing::StrictMock;
|
|
|
|
using ::testing::Return;
|
|
|
|
|
2022-01-20 19:31:07 -08:00
|
|
|
TEST(Vvt, TestSetPoint) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2021-03-14 16:31:46 -07:00
|
|
|
|
|
|
|
// Set up a mock target map
|
|
|
|
StrictMock<MockVp3d> targetMap;
|
|
|
|
EXPECT_CALL(targetMap, getValue(4321, 55))
|
|
|
|
.WillOnce(Return(20));
|
|
|
|
|
|
|
|
// Mock necessary inputs
|
|
|
|
engine->engineState.fuelingLoad = 55;
|
2022-01-20 19:31:07 -08:00
|
|
|
Sensor::setMockValue(SensorType::Rpm, 4321);
|
2021-03-14 16:31:46 -07:00
|
|
|
|
|
|
|
VvtController dut;
|
2021-03-25 04:39:23 -07:00
|
|
|
dut.init(0, 0, 0, &targetMap);
|
2021-03-14 16:31:46 -07:00
|
|
|
|
|
|
|
// Test dut
|
|
|
|
EXPECT_EQ(20, dut.getSetpoint().value_or(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Vvt, observePlant) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2021-03-14 16:31:46 -07:00
|
|
|
|
|
|
|
engine->triggerCentral.vvtPosition[0][0] = 23;
|
|
|
|
|
|
|
|
VvtController dut;
|
2021-03-25 04:39:23 -07:00
|
|
|
dut.init(0, 0, 0, nullptr);
|
2021-03-14 16:31:46 -07:00
|
|
|
|
|
|
|
EXPECT_EQ(23, dut.observePlant().value_or(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Vvt, openLoop) {
|
|
|
|
VvtController dut;
|
|
|
|
|
|
|
|
// No open loop for now
|
|
|
|
EXPECT_EQ(dut.getOpenLoop(10), 0);
|
|
|
|
}
|
2022-08-20 17:12:32 -07:00
|
|
|
|
|
|
|
TEST(Vvt, ClosedLoopNotInverted) {
|
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
|
|
|
|
|
|
|
VvtController dut;
|
|
|
|
dut.init(0, 0, 0, nullptr);
|
|
|
|
|
|
|
|
engineConfiguration->auxPid[0].pFactor = 1.5f;
|
|
|
|
engineConfiguration->auxPid[0].iFactor = 0;
|
|
|
|
engineConfiguration->auxPid[0].dFactor = 0;
|
|
|
|
engineConfiguration->auxPid[0].offset = 0;
|
|
|
|
|
|
|
|
// Target of 30 with position 20 should yield positive duty, P=1.5 means 15% duty for 10% error
|
|
|
|
EXPECT_EQ(dut.getClosedLoop(30, 20).value_or(0), 15);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Vvt, ClosedLoopInverted) {
|
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
|
|
|
|
|
|
|
VvtController dut;
|
|
|
|
dut.init(0, 0, 0, nullptr);
|
|
|
|
|
|
|
|
engineConfiguration->invertVvtControlIntake = true;
|
|
|
|
engineConfiguration->auxPid[0].pFactor = 1.5f;
|
|
|
|
engineConfiguration->auxPid[0].iFactor = 0;
|
|
|
|
engineConfiguration->auxPid[0].dFactor = 0;
|
|
|
|
engineConfiguration->auxPid[0].offset = 0;
|
|
|
|
|
|
|
|
// Target of -30 with position -20 should yield positive duty, P=1.5 means 15% duty for 10% error
|
|
|
|
EXPECT_EQ(dut.getClosedLoop(-30, -20).value_or(0), 15);
|
|
|
|
}
|