refactoring: constexpr fuel computer (#4830)

* refactoring: constexpr fuel computer

* refactoring: constexpr fuel computer

* refactoring: constexpr fuel computer

Co-authored-by: rusefillc <sdfsdfqsf2334234234>
This commit is contained in:
rusefillc 2022-11-26 12:25:04 -05:00 committed by GitHub
parent d63f1af40d
commit c729b10bbe
10 changed files with 17 additions and 21 deletions

View File

@ -57,7 +57,7 @@ const ac_control_s* getLiveDataAddr() {
template<>
const fuel_computer_s* getLiveDataAddr() {
return engine->fuelComputer;
return &engine->fuelComputer;
}
template<>

View File

@ -458,11 +458,11 @@ static void updateThrottles() {
static void updateLambda() {
float lambdaValue = Sensor::getOrZero(SensorType::Lambda1);
engine->outputChannels.lambdaValue = lambdaValue;
engine->outputChannels.AFRValue = lambdaValue * engine->fuelComputer->stoichiometricRatio;
engine->outputChannels.AFRValue = lambdaValue * engine->fuelComputer.stoichiometricRatio;
float lambda2Value = Sensor::getOrZero(SensorType::Lambda2);
engine->outputChannels.lambdaValue2 = lambda2Value;
engine->outputChannels.AFRValue2 = lambda2Value * engine->fuelComputer->stoichiometricRatio;
engine->outputChannels.AFRValue2 = lambda2Value * engine->fuelComputer.stoichiometricRatio;
}
static void updateFuelSensors() {
@ -576,7 +576,7 @@ static void updateFuelCorrections() {
static void updateFuelResults() {
// todo: kill outputChannel while taking care of gauge name and scale!
engine->outputChannels.chargeAirMass = engine->fuelComputer->sdAirMassInOneCylinder;
engine->outputChannels.chargeAirMass = engine->fuelComputer.sdAirMassInOneCylinder;
engine->outputChannels.baseFuel = engine->engineState.baseFuel * 1000; // Convert grams to mg
engine->outputChannels.fuelRunning = engine->engineState.running.fuel;

View File

@ -115,8 +115,8 @@ public:
PinRepository pinRepository;
IEtbController *etbControllers[ETB_COUNT] = {nullptr};
// we have pointers mixed with... not pointers (reference?) between different controllers
IFuelComputer *fuelComputer = nullptr;
FuelComputer fuelComputer;
type_list<
Mockable<InjectorModel>,

View File

@ -197,7 +197,7 @@ void EngineState::periodicFastCallback() {
void EngineState::updateTChargeK(int rpm, float tps) {
#if EFI_ENGINE_CONTROL
float newTCharge = engine->fuelComputer->getTCharge(rpm, tps);
float newTCharge = engine->fuelComputer.getTCharge(rpm, tps);
// convert to microsecs and then to seconds
efitick_t curTime = getTimeNowNt();
float secsPassed = (float)NT2US(curTime - timeSinceLastTChargeK) / US_PER_SECOND_F;

View File

@ -176,9 +176,9 @@ static float getBaseFuelMass(int rpm) {
auto airmass = model->getAirmass(rpm);
// Plop some state for others to read
engine->fuelComputer->sdAirMassInOneCylinder = airmass.CylinderAirmass;
engine->fuelComputer.sdAirMassInOneCylinder = airmass.CylinderAirmass;
engine->engineState.fuelingLoad = airmass.EngineLoadPercent;
engine->engineState.ignitionLoad = engine->fuelComputer->getLoadOverride(airmass.EngineLoadPercent, engineConfiguration->ignOverrideMode);
engine->engineState.ignitionLoad = engine->fuelComputer.getLoadOverride(airmass.EngineLoadPercent, engineConfiguration->ignOverrideMode);
auto gramPerCycle = airmass.CylinderAirmass * engineConfiguration->specs.cylindersCount;
auto gramPerMs = rpm == 0 ? 0 : gramPerCycle / getEngineCycleDuration(rpm);
@ -186,7 +186,7 @@ static float getBaseFuelMass(int rpm) {
// convert g/s -> kg/h
engine->engineState.airflowEstimate = gramPerMs * 3600000 /* milliseconds per hour */ / 1000 /* grams per kg */;;
float baseFuelMass = engine->fuelComputer->getCycleFuel(airmass.CylinderAirmass, rpm, airmass.EngineLoadPercent);
float baseFuelMass = engine->fuelComputer.getCycleFuel(airmass.CylinderAirmass, rpm, airmass.EngineLoadPercent);
// Fudge it by the global correction factor
baseFuelMass *= engineConfiguration->globalFuelCorrection;
@ -330,16 +330,12 @@ float getInjectionMass(int rpm) {
#endif
}
static FuelComputer fuelComputer;
/**
* @brief Initialize fuel map data structure
* @note this method has nothing to do with fuel map VALUES - it's job
* is to prepare the fuel map data structure for 3d interpolation
*/
void initFuelMap() {
engine->fuelComputer = &fuelComputer;
mapEstimationTable.init(config->mapEstimateTable, config->mapEstimateTpsBins, config->mapEstimateRpmBins);
}

View File

@ -1284,8 +1284,8 @@ static void populateFrame(Aim5f7& msg) {
msg.LambdaErr1 = 0;
msg.LambdaErr2 = 0;
// both targets are the same for now
msg.LambdaTarget1 = (float)engine->fuelComputer->targetLambda;
msg.LambdaTarget2 = (float)engine->fuelComputer->targetLambda;
msg.LambdaTarget1 = (float)engine->fuelComputer.targetLambda;
msg.LambdaTarget2 = (float)engine->fuelComputer.targetLambda;
}
void canDashboardAim(CanCycle cycle) {

View File

@ -134,7 +134,7 @@ struct Fueling {
};
static void populateFrame(Fueling& msg) {
msg.cylAirmass = engine->fuelComputer->sdAirMassInOneCylinder;
msg.cylAirmass = engine->fuelComputer.sdAirMassInOneCylinder;
msg.estAirflow = engine->engineState.airflowEstimate;
msg.fuel_pulse = (float)engine->outputChannels.actualLastInjection;
msg.knockCount = engine->module<KnockController>()->getKnockCount();

View File

@ -53,7 +53,7 @@ float ClosedLoopFuelCellImpl::getLambdaError() const {
return 0;
}
return lambda.Value - engine->fuelComputer->targetLambda;
return lambda.Value - engine->fuelComputer.targetLambda;
}
#define MAX_ADJ (0.25f)

View File

@ -143,7 +143,7 @@ void Gm4l6xTransmissionController::setPcState(gear_e gear) {
return;
}
float duty = 0.01f * interpolate2d(engine->fuelComputer->sdAirMassInOneCylinder, config->tcu_pcAirmassBins, *pcts);
float duty = 0.01f * interpolate2d(engine->fuelComputer.sdAirMassInOneCylinder, config->tcu_pcAirmassBins, *pcts);
pcPwm.setSimplePwmDutyCycle(duty);
}

View File

@ -16,7 +16,7 @@ TEST(misc, testIgnitionPlanning) {
EngineTestHelper eth(FORD_ESCORT_GT);
engine->periodicFastCallback();
assertEqualsM("testIgnitionPlanning_AFR", 13.5, engine->fuelComputer->targetAFR);
assertEqualsM("testIgnitionPlanning_AFR", 13.5, engine->fuelComputer.targetAFR);
ASSERT_EQ(IM_BATCH, engineConfiguration->injectionMode);
}
@ -33,7 +33,7 @@ TEST(misc, testEngineMath) {
ASSERT_NEAR( 50, getOneDegreeTimeMs(600) * 180, EPS4D) << "600 RPM";
ASSERT_EQ( 5, getOneDegreeTimeMs(6000) * 180) << "6000 RPM";
IFuelComputer *fuelComputer = engine->fuelComputer;
auto fuelComputer = &engine->fuelComputer;
Sensor::setMockValue(SensorType::Clt, 300);
Sensor::setMockValue(SensorType::Iat, 350);