2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* @file test_fuel_map.cpp
|
|
|
|
*
|
|
|
|
* @date Nov 6, 2013
|
2019-01-12 22:53:58 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2019
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "fuel_math.h"
|
|
|
|
#include "trigger_structure.h"
|
|
|
|
#include "allsensors.h"
|
|
|
|
#include "engine_math.h"
|
|
|
|
#include "trigger_decoder.h"
|
|
|
|
#include "engine_test_helper.h"
|
2019-03-29 06:11:13 -07:00
|
|
|
#include "efi_gpio.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
#include "advance_map.h"
|
|
|
|
|
|
|
|
extern float testMafValue;
|
|
|
|
|
2019-01-14 12:31:56 -08:00
|
|
|
TEST(misc, testMafFuelMath) {
|
2018-12-25 14:26:36 -08:00
|
|
|
printf("====================================================================================== testMafFuelMath\r\n");
|
2019-01-19 17:42:29 -08:00
|
|
|
WITH_ENGINE_TEST_HELPER(FORD_ASPIRE_1996);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2016-08-28 13:02:34 -07:00
|
|
|
engineConfiguration->fuelAlgorithm = LM_REAL_MAF;
|
2015-07-10 06:01:56 -07:00
|
|
|
engineConfiguration->injector.flow = 200;
|
|
|
|
|
2016-07-01 15:03:23 -07:00
|
|
|
setAfrMap(config->afrTable, 13);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2017-05-15 20:28:49 -07:00
|
|
|
float fuelMs = getRealMafFuel(300, 6000 PASS_ENGINE_PARAMETER_SUFFIX);
|
2016-07-01 16:01:44 -07:00
|
|
|
assertEqualsM("fuelMs", 26.7099, fuelMs);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2019-01-14 12:31:56 -08:00
|
|
|
TEST(misc, testFuelMap) {
|
2018-12-25 14:26:36 -08:00
|
|
|
printf("====================================================================================== testFuelMap\r\n");
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
printf("Setting up FORD_ASPIRE_1996\r\n");
|
2019-01-19 17:42:29 -08:00
|
|
|
WITH_ENGINE_TEST_HELPER(FORD_ASPIRE_1996);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
printf("Filling fuel map\r\n");
|
|
|
|
for (int k = 0; k < FUEL_LOAD_COUNT; k++) {
|
|
|
|
for (int r = 0; r < FUEL_RPM_COUNT; r++) {
|
|
|
|
eth.engine.config->fuelTable[k][r] = k * 200 + r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int i = 0; i < FUEL_LOAD_COUNT; i++)
|
|
|
|
eth.engine.config->fuelLoadBins[i] = i;
|
|
|
|
for (int i = 0; i < FUEL_RPM_COUNT; i++)
|
|
|
|
eth.engine.config->fuelRpmBins[i] = i;
|
|
|
|
|
2019-01-14 15:38:20 -08:00
|
|
|
ASSERT_EQ( 1005, getBaseTableFuel(5, 5)) << "base fuel table";
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
printf("*************************************************** initThermistors\r\n");
|
|
|
|
|
|
|
|
|
|
|
|
printf("*** getInjectorLag\r\n");
|
2017-03-06 23:24:57 -08:00
|
|
|
// engine->engineState.vb
|
2017-05-15 20:28:49 -07:00
|
|
|
assertEqualsM("lag", 1.04, getInjectorLag(12 PASS_ENGINE_PARAMETER_SUFFIX));
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
for (int i = 0; i < VBAT_INJECTOR_CURVE_SIZE; i++) {
|
2019-01-04 21:11:17 -08:00
|
|
|
eth.engine.engineConfigurationPtr->injector.battLagCorrBins[i] = i;
|
|
|
|
eth.engine.engineConfigurationPtr->injector.battLagCorr[i] = 0.5 + 2 * i;
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2017-05-15 20:28:49 -07:00
|
|
|
eth.engine.updateSlowSensors(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
// because all the correction tables are zero
|
|
|
|
printf("*************************************************** getRunningFuel 1\r\n");
|
2017-05-15 20:28:49 -07:00
|
|
|
eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
|
|
|
|
float baseFuel = getBaseTableFuel(5, getEngineLoadT(PASS_ENGINE_PARAMETER_SIGNATURE));
|
2019-02-28 17:31:48 -08:00
|
|
|
ASSERT_NEAR(5.3679, getRunningFuel(baseFuel PASS_ENGINE_PARAMETER_SUFFIX), EPS4D) << "base fuel";
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
printf("*************************************************** setting IAT table\r\n");
|
|
|
|
for (int i = 0; i < IAT_CURVE_SIZE; i++) {
|
|
|
|
eth.engine.config->iatFuelCorrBins[i] = i;
|
|
|
|
eth.engine.config->iatFuelCorr[i] = 2 * i;
|
|
|
|
}
|
|
|
|
eth.engine.config->iatFuelCorr[0] = 2;
|
|
|
|
|
|
|
|
printf("*************************************************** setting CLT table\r\n");
|
|
|
|
for (int i = 0; i < CLT_CURVE_SIZE; i++) {
|
|
|
|
eth.engine.config->cltFuelCorrBins[i] = i;
|
2019-06-13 06:05:22 -07:00
|
|
|
eth.engine.config->cltFuelCorr[i] = 1;
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
2016-07-24 20:02:52 -07:00
|
|
|
|
2019-01-10 16:25:07 -08:00
|
|
|
setFlatInjectorLag(0 PASS_CONFIG_PARAMETER_SUFFIX);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-10-13 06:59:06 -07:00
|
|
|
ASSERT_FALSE(cisnan(getIntakeAirTemperature()));
|
2017-05-15 20:28:49 -07:00
|
|
|
float iatCorrection = getIatFuelCorrection(-KELV PASS_ENGINE_PARAMETER_SUFFIX);
|
2019-01-14 15:38:20 -08:00
|
|
|
ASSERT_EQ( 2, iatCorrection) << "IAT";
|
2019-10-13 06:59:06 -07:00
|
|
|
ASSERT_FALSE(cisnan(getCoolantTemperature()));
|
2017-05-15 20:28:49 -07:00
|
|
|
float cltCorrection = getCltFuelCorrection(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2019-01-14 15:38:20 -08:00
|
|
|
ASSERT_EQ( 1, cltCorrection) << "CLT";
|
2017-05-15 20:28:49 -07:00
|
|
|
float injectorLag = getInjectorLag(getVBatt(PASS_ENGINE_PARAMETER_SIGNATURE) PASS_ENGINE_PARAMETER_SUFFIX);
|
2019-01-14 15:38:20 -08:00
|
|
|
ASSERT_EQ( 0, injectorLag) << "injectorLag";
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
testMafValue = 5;
|
|
|
|
|
|
|
|
// 1005 * 2 for IAT correction
|
|
|
|
printf("*************************************************** getRunningFuel 2\r\n");
|
2017-05-15 20:28:49 -07:00
|
|
|
eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
|
|
|
|
baseFuel = getBaseTableFuel(5, getEngineLoadT(PASS_ENGINE_PARAMETER_SIGNATURE));
|
2019-01-14 15:38:20 -08:00
|
|
|
ASSERT_EQ( 30150, getRunningFuel(baseFuel PASS_ENGINE_PARAMETER_SUFFIX)) << "v1";
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
testMafValue = 0;
|
|
|
|
|
|
|
|
engineConfiguration->cranking.baseFuel = 4;
|
|
|
|
|
|
|
|
printf("*************************************************** getStartingFuel\r\n");
|
|
|
|
// NAN in case we have issues with the CLT sensor
|
2019-05-04 20:24:19 -07:00
|
|
|
ASSERT_EQ( 6.0, getCrankingFuel3(NAN, 0 PASS_ENGINE_PARAMETER_SUFFIX)) << "getStartingFuel nan";
|
2019-06-13 06:05:22 -07:00
|
|
|
assertEqualsM("getStartingFuel#1", 11.6, getCrankingFuel3(0, 4 PASS_ENGINE_PARAMETER_SUFFIX));
|
|
|
|
assertEqualsM("getStartingFuel#2", 5.82120, getCrankingFuel3(8, 15 PASS_ENGINE_PARAMETER_SUFFIX));
|
|
|
|
assertEqualsM("getStartingFuel#3", 6.000, getCrankingFuel3(70, 0 PASS_ENGINE_PARAMETER_SUFFIX));
|
|
|
|
assertEqualsM("getStartingFuel#4", 2.41379, getCrankingFuel3(70, 50 PASS_ENGINE_PARAMETER_SUFFIX));
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-25 07:35:22 -08:00
|
|
|
static void confgiureFordAspireTriggerShape(TriggerShape * s) {
|
2015-10-29 11:02:52 -07:00
|
|
|
s->initialize(FOUR_STROKE_CAM_SENSOR, true);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2018-12-25 07:35:22 -08:00
|
|
|
s->addEvent720(53.747, T_SECONDARY, TV_RISE);
|
|
|
|
s->addEvent720(121.90, T_SECONDARY, TV_FALL);
|
|
|
|
s->addEvent720(232.76, T_SECONDARY, TV_RISE);
|
|
|
|
s->addEvent720(300.54, T_SECONDARY, TV_FALL);
|
|
|
|
s->addEvent720(360, T_PRIMARY, TV_RISE);
|
2015-10-31 13:02:10 -07:00
|
|
|
|
2018-12-25 07:35:22 -08:00
|
|
|
s->addEvent720(409.8412, T_SECONDARY, TV_RISE);
|
|
|
|
s->addEvent720(478.6505, T_SECONDARY, TV_FALL);
|
|
|
|
s->addEvent720(588.045, T_SECONDARY, TV_RISE);
|
|
|
|
s->addEvent720(657.03, T_SECONDARY, TV_FALL);
|
|
|
|
s->addEvent720(720, T_PRIMARY, TV_FALL);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-01-14 15:20:20 -08:00
|
|
|
ASSERT_FLOAT_EQ(53.747 / 720, s->wave.getSwitchTime(0));
|
2019-01-14 15:38:20 -08:00
|
|
|
ASSERT_EQ( 1, s->wave.getChannelState(1, 0)) << "@0";
|
|
|
|
ASSERT_EQ( 1, s->wave.getChannelState(1, 0)) << "@0";
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-01-14 15:38:20 -08:00
|
|
|
ASSERT_EQ( 0, s->wave.getChannelState(0, 1)) << "@1";
|
|
|
|
ASSERT_EQ( 0, s->wave.getChannelState(1, 1)) << "@1";
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-01-14 15:38:20 -08:00
|
|
|
ASSERT_EQ( 0, s->wave.getChannelState(0, 2)) << "@2";
|
|
|
|
ASSERT_EQ( 1, s->wave.getChannelState(1, 2)) << "@2";
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-01-14 15:38:20 -08:00
|
|
|
ASSERT_EQ( 0, s->wave.getChannelState(0, 3)) << "@3";
|
|
|
|
ASSERT_EQ( 0, s->wave.getChannelState(1, 3)) << "@3";
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-01-14 15:38:20 -08:00
|
|
|
ASSERT_EQ( 1, s->wave.getChannelState(0, 4)) << "@4";
|
|
|
|
ASSERT_EQ( 1, s->wave.getChannelState(1, 5)) << "@5";
|
|
|
|
ASSERT_EQ( 0, s->wave.getChannelState(1, 8)) << "@8";
|
2019-01-14 15:20:20 -08:00
|
|
|
ASSERT_FLOAT_EQ(121.90 / 720, s->wave.getSwitchTime(1));
|
|
|
|
ASSERT_FLOAT_EQ(657.03 / 720, s->wave.getSwitchTime(8));
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-01-14 15:38:20 -08:00
|
|
|
ASSERT_EQ( 0, s->wave.findAngleMatch(53.747 / 720.0, s->getSize())) << "expecting 0";
|
2015-07-10 06:01:56 -07:00
|
|
|
assertEqualsM("expecting not found", -1, s->wave.findAngleMatch(53 / 720.0, s->getSize()));
|
2019-01-14 15:22:31 -08:00
|
|
|
ASSERT_EQ(7, s->wave.findAngleMatch(588.045 / 720.0, s->getSize()));
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-01-14 15:38:20 -08:00
|
|
|
ASSERT_EQ( 0, s->wave.findInsertionAngle(23.747 / 720.0, s->getSize())) << "expecting 0";
|
|
|
|
ASSERT_EQ( 1, s->wave.findInsertionAngle(63.747 / 720.0, s->getSize())) << "expecting 1";
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2019-01-14 12:31:56 -08:00
|
|
|
TEST(misc, testAngleResolver) {
|
2015-07-10 06:01:56 -07:00
|
|
|
printf("*************************************************** testAngleResolver\r\n");
|
|
|
|
|
2019-01-19 17:42:29 -08:00
|
|
|
WITH_ENGINE_TEST_HELPER(FORD_ASPIRE_1996);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
engineConfiguration->globalTriggerAngleOffset = 175;
|
2016-12-18 09:03:48 -08:00
|
|
|
|
2017-03-01 19:18:25 -08:00
|
|
|
TriggerShape * ts = &engine->triggerCentral.triggerShape;
|
2019-08-08 19:33:52 -07:00
|
|
|
engine->eInitializeTriggerShape(NULL PASS_ENGINE_PARAMETER_SUFFIX);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
assertEqualsM("index 2", 52.76, ts->eventAngles[3]); // this angle is relation to synch point
|
|
|
|
assertEqualsM("time 2", 0.3233, ts->wave.getSwitchTime(2));
|
|
|
|
assertEqualsM("index 5", 412.76, ts->eventAngles[6]);
|
|
|
|
assertEqualsM("time 5", 0.5733, ts->wave.getSwitchTime(5));
|
|
|
|
|
2019-01-14 15:00:59 -08:00
|
|
|
ASSERT_EQ(4, ts->getTriggerShapeSynchPointIndex());
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-01-14 15:38:20 -08:00
|
|
|
ASSERT_EQ( 10, ts->getSize()) << "shape size";
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2016-11-30 19:06:43 -08:00
|
|
|
event_trigger_position_s injectionStart;
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
printf("*************************************************** testAngleResolver 0\r\n");
|
2018-12-25 19:47:29 -08:00
|
|
|
TRIGGER_SHAPE(findTriggerPosition(&injectionStart, -122, engineConfiguration->globalTriggerAngleOffset));
|
2019-10-07 21:54:19 -07:00
|
|
|
ASSERT_EQ( 2, injectionStart.triggerEventIndex) << "eventIndex@0";
|
2019-10-07 22:03:57 -07:00
|
|
|
ASSERT_NEAR(0.24, injectionStart.angleOffsetFromTriggerEvent, EPS5D);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
printf("*************************************************** testAngleResolver 0.1\r\n");
|
2018-12-25 19:47:29 -08:00
|
|
|
TRIGGER_SHAPE(findTriggerPosition(&injectionStart, -80, engineConfiguration->globalTriggerAngleOffset));
|
2019-10-07 21:54:19 -07:00
|
|
|
ASSERT_EQ( 2, injectionStart.triggerEventIndex) << "eventIndex@0";
|
2019-10-07 22:03:57 -07:00
|
|
|
ASSERT_FLOAT_EQ(42.24, injectionStart.angleOffsetFromTriggerEvent);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
printf("*************************************************** testAngleResolver 0.2\r\n");
|
2018-12-25 19:47:29 -08:00
|
|
|
TRIGGER_SHAPE(findTriggerPosition(&injectionStart, -54, engineConfiguration->globalTriggerAngleOffset));
|
2019-10-07 21:54:19 -07:00
|
|
|
ASSERT_EQ( 2, injectionStart.triggerEventIndex) << "eventIndex@0";
|
2019-10-07 22:03:57 -07:00
|
|
|
ASSERT_FLOAT_EQ(68.2400, injectionStart.angleOffsetFromTriggerEvent);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
printf("*************************************************** testAngleResolver 0.3\r\n");
|
2018-12-25 19:47:29 -08:00
|
|
|
TRIGGER_SHAPE(findTriggerPosition(&injectionStart, -53, engineConfiguration->globalTriggerAngleOffset));
|
2019-10-07 21:54:19 -07:00
|
|
|
ASSERT_EQ(2, injectionStart.triggerEventIndex);
|
2019-10-07 22:03:57 -07:00
|
|
|
ASSERT_FLOAT_EQ(69.24, injectionStart.angleOffsetFromTriggerEvent);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
printf("*************************************************** testAngleResolver 1\r\n");
|
2018-12-25 19:47:29 -08:00
|
|
|
TRIGGER_SHAPE(findTriggerPosition(&injectionStart, 0, engineConfiguration->globalTriggerAngleOffset));
|
2019-10-07 21:54:19 -07:00
|
|
|
ASSERT_EQ(2, injectionStart.triggerEventIndex);
|
2019-10-07 22:03:57 -07:00
|
|
|
ASSERT_FLOAT_EQ(122.24, injectionStart.angleOffsetFromTriggerEvent);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
printf("*************************************************** testAngleResolver 2\r\n");
|
2018-12-25 19:47:29 -08:00
|
|
|
TRIGGER_SHAPE(findTriggerPosition(&injectionStart, 56, engineConfiguration->globalTriggerAngleOffset));
|
2019-10-07 21:54:19 -07:00
|
|
|
ASSERT_EQ(2, injectionStart.triggerEventIndex);
|
2019-10-07 22:03:57 -07:00
|
|
|
ASSERT_FLOAT_EQ(178.24, injectionStart.angleOffsetFromTriggerEvent);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
TriggerShape t;
|
2018-12-25 07:35:22 -08:00
|
|
|
confgiureFordAspireTriggerShape(&t);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2019-01-14 12:31:56 -08:00
|
|
|
TEST(misc, testPinHelper) {
|
2015-07-10 06:01:56 -07:00
|
|
|
printf("*************************************************** testPinHelper\r\n");
|
2019-01-14 15:00:59 -08:00
|
|
|
ASSERT_EQ(0, getElectricalValue(0, OM_DEFAULT));
|
|
|
|
ASSERT_EQ(1, getElectricalValue(1, OM_DEFAULT));
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-01-14 15:00:59 -08:00
|
|
|
ASSERT_EQ(0, getElectricalValue(1, OM_INVERTED));
|
|
|
|
ASSERT_EQ(1, getElectricalValue(0, OM_INVERTED));
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
2019-05-27 11:55:35 -07:00
|
|
|
|
|
|
|
extern fuel_Map3D_t veMap;
|
|
|
|
|
|
|
|
TEST(fuel, testTpsBasedVeDefect799) {
|
|
|
|
|
|
|
|
WITH_ENGINE_TEST_HELPER(FORD_ASPIRE_1996);
|
|
|
|
|
|
|
|
engineConfiguration->fuelAlgorithm = LM_SPEED_DENSITY;
|
|
|
|
CONFIGB(useTPSBasedVeTable) = true;
|
|
|
|
|
|
|
|
int mapFrom = 100;
|
|
|
|
// set MAP axis range
|
2019-11-22 20:27:24 -08:00
|
|
|
setLinearCurve(config->veLoadBins, mapFrom, mapFrom + FUEL_LOAD_COUNT - 1, 1);
|
2019-05-27 11:55:35 -07:00
|
|
|
|
|
|
|
// RPM does not matter - set table values to match load axis
|
|
|
|
for (int load = 0; load < FUEL_LOAD_COUNT;load++) {
|
|
|
|
for (int rpmIndex = 0;rpmIndex < FUEL_RPM_COUNT;rpmIndex++) {
|
|
|
|
veMap.pointers[load][rpmIndex] = mapFrom + load;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// just validating that we set 3D map as we wanted
|
|
|
|
ASSERT_EQ(107, veMap.getValue(2000, 107));
|
|
|
|
|
|
|
|
// set TPS axis range which does not overlap MAP range for this test
|
2019-11-22 20:27:24 -08:00
|
|
|
setLinearCurve(CONFIG(ignitionTpsBins), 0, 15, 1);
|
2019-05-27 11:55:35 -07:00
|
|
|
|
|
|
|
|
2019-05-27 12:56:12 -07:00
|
|
|
engine->mockMapValue = 107;
|
|
|
|
setMockTpsValue(7 PASS_ENGINE_PARAMETER_SUFFIX);
|
2019-05-27 11:55:35 -07:00
|
|
|
|
|
|
|
engine->engineState.periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2019-05-27 13:12:59 -07:00
|
|
|
// value in the middle of the map as expected
|
|
|
|
ASSERT_EQ(107, engine->engineState.currentRawVE);
|
2019-05-27 11:55:35 -07:00
|
|
|
}
|