Selectable AFR axis override (#1771)

* add config fields

* config options

* new output channels

* dump out state to ts

* s

* implement override

* enums

* this test is no longer used

* test new behavior

* old

* comments

* impl

* unhide option

* fix

* tests
This commit is contained in:
Matthew Kennedy 2020-09-08 14:15:18 -07:00 committed by GitHub
parent 4ce758db88
commit 6d1acb40f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 4 deletions

View File

@ -1,13 +1,15 @@
#include "fuel_computer.h"
#include "map.h"
EXTERN_ENGINE;
mass_t FuelComputerBase::getCycleFuel(mass_t airmass, int rpm, float load) const {
load = getTargetLambdaLoadAxis(load);
float stoich = getStoichiometricRatio();
float lambda = getTargetLambda(rpm, load);
float afr = stoich * lambda;
// TODO: override target AFR load axis value
ENGINE(engineState.currentAfrLoad) = load;
ENGINE(engineState.targetAFR) = afr;
@ -33,4 +35,16 @@ float FuelComputer::getTargetLambda(int rpm, float load) const {
// TODO: set the table value in lambda instead of afr
return m_afrTable->getValue(rpm, load) / 14.7f;
};
}
float FuelComputer::getTargetLambdaLoadAxis(float defaultLoad) const {
switch(CONFIG(afrOverrideMode)) {
case AFR_None: return defaultLoad;
case AFR_MAP: return getMap(PASS_ENGINE_PARAMETER_SIGNATURE);
// TPS/pedal default to 100% - failed TPS goes rich
case AFR_Tps: return Sensor::get(SensorType::Tps1).value_or(100);
case AFR_AccPedal: return Sensor::get(SensorType::AcceleratorPedal).value_or(100);
case AFR_CylFilling: return 100 * ENGINE(engineState.sd.airMassInOneCylinder) / ENGINE(standardAirCharge);
default: return 0;
}
}

View File

@ -20,6 +20,7 @@ public:
protected:
virtual float getStoichiometricRatio() const = 0;
virtual float getTargetLambda(int rpm, float load) const = 0;
virtual float getTargetLambdaLoadAxis(float defaultLoad) const = 0;
};
// This class is a usable implemenation of a fuel model that reads real configuration
@ -30,6 +31,7 @@ public:
protected:
float getStoichiometricRatio() const override;
float getTargetLambda(int rpm, float load) const override;
float getTargetLambdaLoadAxis(float defaultLoad) const override;
private:
const ValueProvider3D* const m_afrTable;

View File

@ -1592,8 +1592,7 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00"
field = "#Batch injection with individual wiring"
field = "Two wire batch emulation", twoWireBatchInjection, {isInjectionEnabled == 1 && injectionMode == 2}
field = "Override VE table load axis", veOverrideMode, { isInjectionEnabled }
;field = "Override AFR table load axis", afrOverrideMode, { isInjectionEnabled }
; ^^^ Not yet implemented, hidden for now! ^^^
field = "Override AFR table load axis", afrOverrideMode, { isInjectionEnabled }
dialog = ignitionOutputs, "Ignition Outputs"
field = "Ignition Pin Mode", ignitionPinMode, {isIgnitionEnabled == 1}

View File

@ -13,6 +13,7 @@ class MockFuelComputer : public FuelComputerBase {
public:
MOCK_METHOD(float, getStoichiometricRatio, (), (const, override));
MOCK_METHOD(float, getTargetLambda, (int rpm, float load), (const, override));
MOCK_METHOD(float, getTargetLambdaLoadAxis, (float defaultLoad), (const, override));
};
TEST(FuelComputer, getCycleFuel) {
@ -21,6 +22,8 @@ TEST(FuelComputer, getCycleFuel) {
MockFuelComputer dut;
INJECT_ENGINE_REFERENCE(&dut);
EXPECT_CALL(dut, getTargetLambdaLoadAxis(FloatEq(0.8f)))
.WillOnce(Return(0.8f));
EXPECT_CALL(dut, getStoichiometricRatio())
.WillOnce(Return(3.0f));
EXPECT_CALL(dut, getTargetLambda(1000, FloatEq(0.8f)))