2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* @file test_fuel_map.cpp
|
|
|
|
*
|
|
|
|
* @date Nov 6, 2013
|
2018-01-20 17:42:19 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2018
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "test_fuel_map.h"
|
2018-09-16 19:39:46 -07:00
|
|
|
#include "global.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
#include "engine_configuration.h"
|
|
|
|
#include "fuel_math.h"
|
|
|
|
#include "trigger_structure.h"
|
|
|
|
#include "allsensors.h"
|
|
|
|
#include "engine_math.h"
|
|
|
|
#include "trigger_decoder.h"
|
|
|
|
#include "engine_test_helper.h"
|
|
|
|
#include "efiGpio.h"
|
|
|
|
#include "advance_map.h"
|
|
|
|
|
|
|
|
extern float testMafValue;
|
|
|
|
|
|
|
|
void testMafFuelMath(void) {
|
|
|
|
printf("*************************************************** testMafFuelMath\r\n");
|
|
|
|
EngineTestHelper eth(FORD_ASPIRE_1996);
|
|
|
|
EXPAND_EngineTestHelper;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void testFuelMap(void) {
|
|
|
|
printf("*************************************************** testFuelMap\r\n");
|
|
|
|
|
|
|
|
printf("Setting up FORD_ASPIRE_1996\r\n");
|
|
|
|
EngineTestHelper eth(FORD_ASPIRE_1996);
|
|
|
|
EXPAND_EngineTestHelper;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2017-04-12 20:25:58 -07:00
|
|
|
assertEqualsM("base fuel table", 1005, getBaseTableFuel(5, 5));
|
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++) {
|
|
|
|
eth.engine.engineConfiguration->injector.battLagCorrBins[i] = i;
|
2016-07-24 20:02:52 -07:00
|
|
|
eth.engine.engineConfiguration->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));
|
|
|
|
assertEqualsM("base fuel", 5.05, getRunningFuel(baseFuel PASS_ENGINE_PARAMETER_SUFFIX));
|
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;
|
2016-02-14 10:02:00 -08:00
|
|
|
eth.engine.config->cltFuelCorr[i] = 100;
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
2016-07-24 20:02:52 -07:00
|
|
|
|
2017-06-11 11:49:23 -07:00
|
|
|
setFlatInjectorLag(0 PASS_ENGINE_PARAMETER_SUFFIX);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2017-05-15 20:28:49 -07:00
|
|
|
assertEquals(NAN, getIntakeAirTemperature(PASS_ENGINE_PARAMETER_SIGNATURE));
|
|
|
|
float iatCorrection = getIatFuelCorrection(-KELV PASS_ENGINE_PARAMETER_SUFFIX);
|
2015-07-10 06:01:56 -07:00
|
|
|
assertEqualsM("IAT", 2, iatCorrection);
|
2017-05-15 20:28:49 -07:00
|
|
|
engine->sensors.clt = getCoolantTemperature(PASS_ENGINE_PARAMETER_SIGNATURE);
|
|
|
|
float cltCorrection = getCltFuelCorrection(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2015-07-10 06:01:56 -07:00
|
|
|
assertEqualsM("CLT", 1, cltCorrection);
|
2017-05-15 20:28:49 -07:00
|
|
|
float injectorLag = getInjectorLag(getVBatt(PASS_ENGINE_PARAMETER_SIGNATURE) PASS_ENGINE_PARAMETER_SUFFIX);
|
2016-07-24 20:02:52 -07:00
|
|
|
assertEqualsM("injectorLag", 0, 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));
|
|
|
|
assertEqualsM("v1", 30150, getRunningFuel(baseFuel PASS_ENGINE_PARAMETER_SUFFIX));
|
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
|
2017-05-15 20:28:49 -07:00
|
|
|
assertEqualsM("getStartingFuel nan", 4, getCrankingFuel3(NAN, 0 PASS_ENGINE_PARAMETER_SUFFIX));
|
|
|
|
assertEqualsM("getStartingFuel#1", 17.8, getCrankingFuel3(0, 4 PASS_ENGINE_PARAMETER_SUFFIX));
|
|
|
|
assertEqualsM("getStartingFuel#2", 8.4480, getCrankingFuel3(8, 15 PASS_ENGINE_PARAMETER_SUFFIX));
|
|
|
|
assertEqualsM("getStartingFuel#3", 6.48, getCrankingFuel3(70, 0 PASS_ENGINE_PARAMETER_SUFFIX));
|
|
|
|
assertEqualsM("getStartingFuel#4", 2.6069, getCrankingFuel3(70, 50 PASS_ENGINE_PARAMETER_SUFFIX));
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-15 20:28:49 -07:00
|
|
|
static void confgiureFordAspireTriggerShape(TriggerShape * s DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
2015-10-29 11:02:52 -07:00
|
|
|
s->initialize(FOUR_STROKE_CAM_SENSOR, true);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2017-05-15 20:28:49 -07:00
|
|
|
s->addEvent2(53.747, T_SECONDARY, TV_RISE PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
s->addEvent2(121.90, T_SECONDARY, TV_FALL PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
s->addEvent2(232.76, T_SECONDARY, TV_RISE PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
s->addEvent2(300.54, T_SECONDARY, TV_FALL PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
s->addEvent2(360, T_PRIMARY, TV_RISE PASS_ENGINE_PARAMETER_SUFFIX);
|
2015-10-31 13:02:10 -07:00
|
|
|
|
2017-05-15 20:28:49 -07:00
|
|
|
s->addEvent2(409.8412, T_SECONDARY, TV_RISE PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
s->addEvent2(478.6505, T_SECONDARY, TV_FALL PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
s->addEvent2(588.045, T_SECONDARY, TV_RISE PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
s->addEvent2(657.03, T_SECONDARY, TV_FALL PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
s->addEvent2(720, T_PRIMARY, TV_FALL PASS_ENGINE_PARAMETER_SUFFIX);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
assertEquals(53.747 / 720, s->wave.getSwitchTime(0));
|
|
|
|
assertEqualsM("@0", 1, s->wave.getChannelState(1, 0));
|
|
|
|
assertEqualsM("@0", 1, s->wave.getChannelState(1, 0));
|
|
|
|
|
|
|
|
assertEqualsM("@1", 0, s->wave.getChannelState(0, 1));
|
|
|
|
assertEqualsM("@1", 0, s->wave.getChannelState(1, 1));
|
|
|
|
|
|
|
|
assertEqualsM("@2", 0, s->wave.getChannelState(0, 2));
|
|
|
|
assertEqualsM("@2", 1, s->wave.getChannelState(1, 2));
|
|
|
|
|
|
|
|
assertEqualsM("@3", 0, s->wave.getChannelState(0, 3));
|
|
|
|
assertEqualsM("@3", 0, s->wave.getChannelState(1, 3));
|
|
|
|
|
|
|
|
assertEqualsM("@4", 1, s->wave.getChannelState(0, 4));
|
|
|
|
assertEqualsM("@5", 1, s->wave.getChannelState(1, 5));
|
|
|
|
assertEqualsM("@8", 0, s->wave.getChannelState(1, 8));
|
|
|
|
assertEquals(121.90 / 720, s->wave.getSwitchTime(1));
|
|
|
|
assertEquals(657.03 / 720, s->wave.getSwitchTime(8));
|
|
|
|
|
|
|
|
assertEqualsM("expecting 0", 0, s->wave.findAngleMatch(53.747 / 720.0, s->getSize()));
|
|
|
|
assertEqualsM("expecting not found", -1, s->wave.findAngleMatch(53 / 720.0, s->getSize()));
|
|
|
|
assertEquals(7, s->wave.findAngleMatch(588.045 / 720.0, s->getSize()));
|
|
|
|
|
2018-04-29 23:22:54 -07:00
|
|
|
assertEqualsM("expecting 0", 0, s->wave.findInsertionAngle(23.747 / 720.0, s->getSize()));
|
|
|
|
assertEqualsM("expecting 1", 1, s->wave.findInsertionAngle(63.747 / 720.0, s->getSize()));
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void testAngleResolver(void) {
|
|
|
|
printf("*************************************************** testAngleResolver\r\n");
|
|
|
|
|
|
|
|
EngineTestHelper eth(FORD_ASPIRE_1996);
|
|
|
|
EXPAND_EngineTestHelper;
|
|
|
|
|
|
|
|
engineConfiguration->globalTriggerAngleOffset = 175;
|
2016-12-18 09:03:48 -08:00
|
|
|
|
2017-03-01 19:18:25 -08:00
|
|
|
TriggerShape * ts = &engine->triggerCentral.triggerShape;
|
2018-12-24 20:23:45 -08:00
|
|
|
ts->initializeTriggerShape(NULL, false 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));
|
|
|
|
|
|
|
|
assertEquals(4, ts->getTriggerShapeSynchPointIndex());
|
|
|
|
|
|
|
|
assertEqualsM("shape size", 10, ts->getSize());
|
|
|
|
|
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");
|
2017-05-15 20:28:49 -07:00
|
|
|
TRIGGER_SHAPE(findTriggerPosition(&injectionStart, -122 PASS_ENGINE_PARAMETER_SUFFIX));
|
2016-11-30 19:06:43 -08:00
|
|
|
assertEqualsM("eventIndex@0", 2, injectionStart.eventIndex);
|
|
|
|
assertEquals(0.24, injectionStart.angleOffset);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
printf("*************************************************** testAngleResolver 0.1\r\n");
|
2017-05-15 20:28:49 -07:00
|
|
|
TRIGGER_SHAPE(findTriggerPosition(&injectionStart, -80 PASS_ENGINE_PARAMETER_SUFFIX));
|
2016-11-30 19:06:43 -08:00
|
|
|
assertEqualsM("eventIndex@0", 2, injectionStart.eventIndex);
|
|
|
|
assertEquals(42.24, injectionStart.angleOffset);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
printf("*************************************************** testAngleResolver 0.2\r\n");
|
2017-05-15 20:28:49 -07:00
|
|
|
TRIGGER_SHAPE(findTriggerPosition(&injectionStart, -54 PASS_ENGINE_PARAMETER_SUFFIX));
|
2016-11-30 19:06:43 -08:00
|
|
|
assertEqualsM("eventIndex@0", 2, injectionStart.eventIndex);
|
|
|
|
assertEquals(68.2400, injectionStart.angleOffset);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
printf("*************************************************** testAngleResolver 0.3\r\n");
|
2017-05-15 20:28:49 -07:00
|
|
|
TRIGGER_SHAPE(findTriggerPosition(&injectionStart, -53 PASS_ENGINE_PARAMETER_SUFFIX));
|
2016-11-30 19:06:43 -08:00
|
|
|
assertEquals(2, injectionStart.eventIndex);
|
|
|
|
assertEquals(69.24, injectionStart.angleOffset);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
printf("*************************************************** testAngleResolver 1\r\n");
|
2017-05-15 20:28:49 -07:00
|
|
|
TRIGGER_SHAPE(findTriggerPosition(&injectionStart, 0 PASS_ENGINE_PARAMETER_SUFFIX));
|
2016-11-30 19:06:43 -08:00
|
|
|
assertEquals(2, injectionStart.eventIndex);
|
|
|
|
assertEquals(122.24, injectionStart.angleOffset);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
printf("*************************************************** testAngleResolver 2\r\n");
|
2017-05-15 20:28:49 -07:00
|
|
|
TRIGGER_SHAPE(findTriggerPosition(&injectionStart, 56 PASS_ENGINE_PARAMETER_SUFFIX));
|
2016-11-30 19:06:43 -08:00
|
|
|
assertEquals(2, injectionStart.eventIndex);
|
|
|
|
assertEquals(178.24, injectionStart.angleOffset);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
TriggerShape t;
|
2017-05-15 20:28:49 -07:00
|
|
|
confgiureFordAspireTriggerShape(&t PASS_ENGINE_PARAMETER_SUFFIX);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void testPinHelper(void) {
|
|
|
|
printf("*************************************************** testPinHelper\r\n");
|
|
|
|
assertEquals(0, getElectricalValue(0, OM_DEFAULT));
|
|
|
|
assertEquals(1, getElectricalValue(1, OM_DEFAULT));
|
|
|
|
|
|
|
|
assertEquals(0, getElectricalValue(1, OM_INVERTED));
|
|
|
|
assertEquals(1, getElectricalValue(0, OM_INVERTED));
|
|
|
|
}
|