2021-07-25 22:05:17 -07:00
|
|
|
#include "pch.h"
|
2020-07-23 01:23:57 -07:00
|
|
|
#include "maf_airmass.h"
|
|
|
|
#include "maf.h"
|
|
|
|
|
2021-06-30 21:05:42 -07:00
|
|
|
AirmassResult MafAirmass::getAirmass(int rpm) {
|
2021-10-16 18:23:32 -07:00
|
|
|
float maf = Sensor::getOrZero(SensorType::Maf);
|
2020-07-24 11:44:54 -07:00
|
|
|
return getAirmassImpl(maf, rpm);
|
2020-07-23 01:23:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function block now works to create a standardised load from the cylinder filling as well as tune fuel via VE table.
|
|
|
|
* @return total duration of fuel injection per engine cycle, in milliseconds
|
|
|
|
*/
|
|
|
|
AirmassResult MafAirmass::getAirmassImpl(float massAirFlow, int rpm) const {
|
|
|
|
// If the engine is stopped, MAF is meaningless
|
|
|
|
if (rpm == 0) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
// kg/hr -> g/s
|
|
|
|
float gramPerSecond = massAirFlow * 1000 / 3600;
|
|
|
|
|
|
|
|
// 1/min -> 1/s
|
|
|
|
float revsPerSecond = rpm / 60.0f;
|
|
|
|
float airPerRevolution = gramPerSecond / revsPerSecond;
|
|
|
|
|
2021-12-26 09:33:32 -08:00
|
|
|
// Now we have to divide among cylinders - on a 4 stroke, half of the cylinders happen every revolution
|
|
|
|
// This math is floating point to work properly on engines with odd cylinder count
|
2021-11-17 00:54:21 -08:00
|
|
|
float halfCylCount = engineConfiguration->specs.cylindersCount / 2.0f;
|
2020-07-23 01:23:57 -07:00
|
|
|
|
|
|
|
float cylinderAirmass = airPerRevolution / halfCylCount;
|
|
|
|
|
2021-12-26 09:33:32 -08:00
|
|
|
//Create % load for fuel table using relative naturally aspirated cylinder filling
|
2021-11-17 00:54:21 -08:00
|
|
|
float airChargeLoad = 100 * cylinderAirmass / engine->standardAirCharge;
|
2020-07-23 01:23:57 -07:00
|
|
|
|
|
|
|
//Correct air mass by VE table
|
2020-09-06 16:06:32 -07:00
|
|
|
float correctedAirmass = cylinderAirmass * getVe(rpm, airChargeLoad);
|
2020-07-23 01:23:57 -07:00
|
|
|
|
|
|
|
return {
|
|
|
|
correctedAirmass,
|
|
|
|
airChargeLoad, // AFR/VE/ignition table Y axis
|
|
|
|
};
|
|
|
|
}
|