VVT control is broken on second bank fix #5599

This commit is contained in:
Andrey 2023-10-07 12:54:45 -04:00
parent 3b1fe9da7f
commit 680d18e433
4 changed files with 16 additions and 10 deletions

View File

@ -27,7 +27,7 @@ VvtController::VvtController(int index)
void VvtController::init(const ValueProvider3D* targetMap, IPwm* pwm) {
// Use the same settings for the Nth cam in every bank (ie, all exhaust cams use the same PID)
m_pid.initPidClass(&engineConfiguration->auxPid[index]);
m_pid.initPidClass(&engineConfiguration->auxPid[m_cam]);
m_targetMap = targetMap;
m_pwm = pwm;
@ -43,7 +43,7 @@ void VvtController::onFastCallback() {
}
void VvtController::onConfigurationChange(engine_configuration_s const * previousConfig) {
if (!m_pid.isSame(&previousConfig->auxPid[index])) {
if (!m_pid.isSame(&previousConfig->auxPid[m_cam])) {
m_pid.reset();
}
}

View File

@ -41,6 +41,10 @@ public:
expected<percent_t> getClosedLoop(angle_t setpoint, angle_t observation) override;
void setOutput(expected<percent_t> outputValue) override;
uint8_t getCamIndex() {
return m_cam;
}
private:
const int index;
// Bank index, 0 or 1

View File

@ -45,13 +45,15 @@ TEST(Vvt, openLoop) {
TEST(Vvt, ClosedLoopNotInverted) {
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
VvtController dut(0);
VvtController dut(/* second cam on second bank*/3);
int camIndex = 1;
ASSERT_EQ(dut.getCamIndex(), camIndex);
dut.init(nullptr, nullptr);
engineConfiguration->auxPid[0].pFactor = 1.5f;
engineConfiguration->auxPid[0].iFactor = 0;
engineConfiguration->auxPid[0].dFactor = 0;
engineConfiguration->auxPid[0].offset = 0;
engineConfiguration->auxPid[camIndex].pFactor = 1.5f;
engineConfiguration->auxPid[camIndex].iFactor = 0;
engineConfiguration->auxPid[camIndex].dFactor = 0;
engineConfiguration->auxPid[camIndex].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);
@ -60,9 +62,9 @@ TEST(Vvt, ClosedLoopNotInverted) {
TEST(Vvt, ClosedLoopInverted) {
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
int index = 0;
VvtController dut(/*first cam on second bank*/2);
int camIndex = 0;
VvtController dut(index);
ASSERT_EQ(dut.getCamIndex(), camIndex);
dut.init(nullptr, nullptr);
engineConfiguration->invertVvtControlIntake = true;

View File

@ -5,7 +5,7 @@
#include "pch.h"
TEST(trigger, testQuadCam) {
TEST(trigger, testQuadCamInput) {
// setting some weird engine
EngineTestHelper eth(engine_type_e::FORD_ESCORT_GT);
engineConfiguration->isFasterEngineSpinUpEnabled = false;