Skip to content

Commit

Permalink
airmass takes a ptr for VE table
Browse files Browse the repository at this point in the history
  • Loading branch information
mck1117 committed Sep 25, 2024
1 parent 71c860b commit fca72c4
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions firmware/controllers/algo/airmass/airmass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "airmass.h"
#include "idle_thread.h"

AirmassVeModelBase::AirmassVeModelBase(const ValueProvider3D& veTable) : m_veTable(&veTable) {}
AirmassVeModelBase::AirmassVeModelBase(const ValueProvider3D* veTable) : m_veTable(veTable) {}

static float getVeLoadAxis(ve_override_e mode, float passedLoad) {
switch(mode) {
Expand All @@ -20,7 +20,7 @@ float AirmassVeModelBase::getVe(float rpm, float load, bool postState) const {
// Override the load value if necessary
load = getVeLoadAxis(engineConfiguration->veOverrideMode, load);

percent_t ve = m_veTable->getValue(rpm, load);
percent_t ve = m_veTable ? m_veTable->getValue(rpm, load) : getVeImpl(rpm, load);

#if EFI_IDLE_CONTROL
auto tps = Sensor::get(SensorType::Tps1);
Expand Down
4 changes: 3 additions & 1 deletion firmware/controllers/algo/airmass/airmass.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ struct AirmassModelBase {

class AirmassVeModelBase : public AirmassModelBase {
public:
explicit AirmassVeModelBase(const ValueProvider3D& veTable);
explicit AirmassVeModelBase(const ValueProvider3D* veTable);

// Retrieve the user-calibrated volumetric efficiency from the table
float getVe(float rpm, percent_t load, bool postState) const;

virtual float getVeImpl(float /*rpm*/, percent_t /*load*/) const { return 0.0f; }

private:
const ValueProvider3D* const m_veTable;
};
2 changes: 1 addition & 1 deletion firmware/controllers/algo/airmass/alphan_airmass.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class AlphaNAirmass : public SpeedDensityBase {
public:
explicit AlphaNAirmass(const ValueProvider3D& veTable) : SpeedDensityBase(veTable) {}
explicit AlphaNAirmass(const ValueProvider3D* veTable) : SpeedDensityBase(veTable) {}

AirmassResult getAirmass(float rpm, bool postState) override;
};
2 changes: 1 addition & 1 deletion firmware/controllers/algo/airmass/maf_airmass.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class MafAirmass final : public AirmassVeModelBase {
public:
explicit MafAirmass(const ValueProvider3D& veTable) : AirmassVeModelBase(veTable) {}
explicit MafAirmass(const ValueProvider3D* veTable = nullptr) : AirmassVeModelBase(veTable) {}

AirmassResult getAirmass(float rpm, bool postState) override;

Expand Down
2 changes: 1 addition & 1 deletion firmware/controllers/algo/airmass/speed_density_airmass.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class SpeedDensityAirmass : public SpeedDensityBase {
public:
explicit SpeedDensityAirmass(const ValueProvider3D& veTable, const ValueProvider3D& mapEstimationTable)
explicit SpeedDensityAirmass(const ValueProvider3D* veTable, const ValueProvider3D& mapEstimationTable)
: SpeedDensityBase(veTable)
, m_mapEstimationTable(&mapEstimationTable)
{}
Expand Down
2 changes: 1 addition & 1 deletion firmware/controllers/algo/airmass/speed_density_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mass_t idealGasLaw(float volume, float pressure, float temperature);

class SpeedDensityBase : public AirmassVeModelBase {
protected:
explicit SpeedDensityBase(const ValueProvider3D& veTable) : AirmassVeModelBase(veTable) {}
explicit SpeedDensityBase(const ValueProvider3D* veTable) : AirmassVeModelBase(veTable) {}

public:
static mass_t getAirmassImpl(float ve, float manifoldPressure, float temperature);
Expand Down
6 changes: 3 additions & 3 deletions firmware/controllers/algo/fuel_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ float getRunningFuel(float baseFuel) {
return runningFuel;
}

static SpeedDensityAirmass sdAirmass(veMap, mapEstimationTable);
static MafAirmass mafAirmass(veMap);
static AlphaNAirmass alphaNAirmass(veMap);
static SpeedDensityAirmass sdAirmass(&veMap, mapEstimationTable);
static MafAirmass mafAirmass(&veMap);
static AlphaNAirmass alphaNAirmass(&veMap);

AirmassModelBase* getAirmassModel(engine_load_mode_e mode) {
switch (mode) {
Expand Down
2 changes: 1 addition & 1 deletion unit_tests/mocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ MockOutputPin::~MockOutputPin() { }
MockExecutor::MockExecutor() { }
MockExecutor::~MockExecutor() { }

MockAirmass::MockAirmass() : AirmassVeModelBase(veTable) { }
MockAirmass::MockAirmass() : AirmassVeModelBase(&veTable) { }
MockAirmass::~MockAirmass() { }

MockInjectorModel2::MockInjectorModel2() { }
Expand Down
4 changes: 2 additions & 2 deletions unit_tests/tests/ignition_injection/test_fuel_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ TEST(AirmassModes, VeOverride) {
}

struct DummyAirmassModel : public AirmassVeModelBase {
DummyAirmassModel(const ValueProvider3D& veTable) : AirmassVeModelBase(veTable) {}
DummyAirmassModel(const ValueProvider3D* veTable) : AirmassVeModelBase(veTable) {}

AirmassResult getAirmass(float rpm, bool postState) override {
// Default load value 10, will be overriden
Expand All @@ -154,7 +154,7 @@ TEST(AirmassModes, VeOverride) {
};

EngineTestHelper eth(engine_type_e::TEST_ENGINE);
DummyAirmassModel dut(veTable);
DummyAirmassModel dut(&veTable);

// Use default mode - will call with 10
dut.getAirmass(0, true);
Expand Down

0 comments on commit fca72c4

Please sign in to comment.