only: VVT refactoring reducing magic index math
This commit is contained in:
parent
9e8dc8976f
commit
3b1fe9da7f
|
@ -18,10 +18,10 @@ using vvt_map_t = Map3D<SCRIPT_TABLE_8, SCRIPT_TABLE_8, int8_t, uint16_t, uint16
|
|||
static vvt_map_t vvtTable1;
|
||||
static vvt_map_t vvtTable2;
|
||||
|
||||
VvtController::VvtController(int index, int bankIndex, int camIndex)
|
||||
VvtController::VvtController(int index)
|
||||
: index(index)
|
||||
, m_bank(bankIndex)
|
||||
, m_cam(camIndex)
|
||||
, m_bank(BANK_BY_INDEX(index))
|
||||
, m_cam(CAM_BY_INDEX(index))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -20,9 +20,12 @@ void startVvtControlPins();
|
|||
void stopVvtControlPins();
|
||||
OutputPin* getVvtOutputPin(int index);
|
||||
|
||||
#define BANK_BY_INDEX(index) (index / CAMS_PER_BANK)
|
||||
#define CAM_BY_INDEX(index) (index % CAMS_PER_BANK)
|
||||
|
||||
class VvtController : public EngineModule, public ClosedLoopController<angle_t, percent_t>, public vvt_s {
|
||||
public:
|
||||
VvtController(int index, int bankIndex, int camIndex);
|
||||
VvtController(int index);
|
||||
|
||||
void init(const ValueProvider3D* targetMap, IPwm* pwm);
|
||||
|
||||
|
@ -39,11 +42,11 @@ public:
|
|||
void setOutput(expected<percent_t> outputValue) override;
|
||||
|
||||
private:
|
||||
const int index = 0;
|
||||
const int index;
|
||||
// Bank index, 0 or 1
|
||||
const uint8_t m_bank = 0;
|
||||
const uint8_t m_bank;
|
||||
// Cam index, 0 = intake, 1 = exhaust
|
||||
const uint8_t m_cam = 0;
|
||||
const uint8_t m_cam;
|
||||
|
||||
Pid m_pid;
|
||||
|
||||
|
@ -53,17 +56,17 @@ private:
|
|||
|
||||
// Unique types for each VVT so they can be engine modules
|
||||
struct VvtController1 : public VvtController {
|
||||
VvtController1() : VvtController(0, 0, 0) { }
|
||||
VvtController1() : VvtController(0) { }
|
||||
};
|
||||
|
||||
struct VvtController2 : public VvtController {
|
||||
VvtController2() : VvtController(1, 0, 1) { }
|
||||
VvtController2() : VvtController(1) { }
|
||||
};
|
||||
|
||||
struct VvtController3 : public VvtController {
|
||||
VvtController3() : VvtController(2, 1, 0) { }
|
||||
VvtController3() : VvtController(2) { }
|
||||
};
|
||||
|
||||
struct VvtController4 : public VvtController {
|
||||
VvtController4() : VvtController(3, 1, 1) { }
|
||||
VvtController4() : VvtController(3) { }
|
||||
};
|
||||
|
|
|
@ -267,8 +267,8 @@ void hwHandleVvtCamSignal(TriggerValue front, efitick_t nowNt, int index) {
|
|||
engine->outputChannels.vvtChannel4 = front == TriggerValue::RISE;
|
||||
}
|
||||
|
||||
int bankIndex = index / CAMS_PER_BANK;
|
||||
int camIndex = index % CAMS_PER_BANK;
|
||||
int bankIndex = BANK_BY_INDEX(index);
|
||||
int camIndex = CAM_BY_INDEX(index);
|
||||
if (front == TriggerValue::RISE) {
|
||||
tc->vvtEventRiseCounter[index]++;
|
||||
} else {
|
||||
|
|
|
@ -17,7 +17,7 @@ TEST(Vvt, TestSetPoint) {
|
|||
engine->engineState.fuelingLoad = 55;
|
||||
Sensor::setMockValue(SensorType::Rpm, 4321);
|
||||
|
||||
VvtController dut(0, 0, 0);
|
||||
VvtController dut(0);
|
||||
dut.init(&targetMap, nullptr);
|
||||
|
||||
// Test dut
|
||||
|
@ -29,14 +29,14 @@ TEST(Vvt, observePlant) {
|
|||
|
||||
engine->triggerCentral.vvtPosition[0][0] = 23;
|
||||
|
||||
VvtController dut(0, 0, 0);
|
||||
VvtController dut(0);
|
||||
dut.init(nullptr, nullptr);
|
||||
|
||||
EXPECT_EQ(23, dut.observePlant().value_or(0));
|
||||
}
|
||||
|
||||
TEST(Vvt, openLoop) {
|
||||
VvtController dut(0, 0, 0);
|
||||
VvtController dut(0);
|
||||
|
||||
// No open loop for now
|
||||
EXPECT_EQ(dut.getOpenLoop(10), 0);
|
||||
|
@ -45,7 +45,7 @@ TEST(Vvt, openLoop) {
|
|||
TEST(Vvt, ClosedLoopNotInverted) {
|
||||
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
||||
|
||||
VvtController dut(0, 0, 0);
|
||||
VvtController dut(0);
|
||||
dut.init(nullptr, nullptr);
|
||||
|
||||
engineConfiguration->auxPid[0].pFactor = 1.5f;
|
||||
|
@ -60,14 +60,16 @@ TEST(Vvt, ClosedLoopNotInverted) {
|
|||
TEST(Vvt, ClosedLoopInverted) {
|
||||
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
||||
|
||||
VvtController dut(0, 0, 0);
|
||||
int index = 0;
|
||||
int camIndex = 0;
|
||||
VvtController dut(index);
|
||||
dut.init(nullptr, 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;
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue