2020-08-10 21:40:19 -07:00
|
|
|
#include "fuel_computer.h"
|
|
|
|
|
|
|
|
EXTERN_ENGINE;
|
|
|
|
|
|
|
|
mass_t FuelComputerBase::getCycleFuel(mass_t airmass, int rpm, float load) const {
|
|
|
|
float stoich = getStoichiometricRatio();
|
|
|
|
float lambda = getTargetLambda(rpm, load);
|
|
|
|
float afr = stoich * lambda;
|
|
|
|
|
2020-09-07 07:15:42 -07:00
|
|
|
// TODO: override target AFR load axis value
|
|
|
|
ENGINE(engineState.currentAfrLoad) = load;
|
2020-08-10 21:40:19 -07:00
|
|
|
ENGINE(engineState.targetAFR) = afr;
|
|
|
|
|
|
|
|
return airmass / afr;
|
|
|
|
}
|
|
|
|
|
|
|
|
FuelComputer::FuelComputer(const ValueProvider3D& afrTable) : m_afrTable(&afrTable) {}
|
|
|
|
|
|
|
|
float FuelComputer::getStoichiometricRatio() const {
|
|
|
|
// TODO: vary this with ethanol content/configured setting/whatever
|
2020-08-21 16:43:30 -07:00
|
|
|
float rawConfig = (float)CONFIG(stoichRatioPrimary) / PACK_MULT_AFR_CFG;
|
|
|
|
|
|
|
|
// Config compatibility: this field may be zero on ECUs with old defaults
|
|
|
|
if (rawConfig < 5) {
|
|
|
|
return 14.7f;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rawConfig;
|
2020-08-10 21:40:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
float FuelComputer::getTargetLambda(int rpm, float load) const {
|
|
|
|
efiAssert(OBD_PCM_Processor_Fault, m_afrTable != nullptr, "AFR table null", 0);
|
|
|
|
|
|
|
|
// TODO: set the table value in lambda instead of afr
|
2020-08-21 16:43:30 -07:00
|
|
|
return m_afrTable->getValue(rpm, load) / 14.7f;
|
2020-08-10 21:40:19 -07:00
|
|
|
};
|