rusefi-1/unit_tests/test_fuel_map.cpp

202 lines
7.6 KiB
C++
Raw Normal View History

2014-08-29 07:52:33 -07:00
/**
* @file test_fuel_map.cpp
*
* Created on: Nov 6, 2013
* Author: Andrey Belomutskiy, (c) 2012-2013
*/
#include "test_fuel_map.h"
#include "main.h"
#include "engine_configuration.h"
#include "fuel_math.h"
#include "trigger_structure.h"
#include "allsensors.h"
#include "engine_math.h"
#include "OutputSignalList.h"
#include "ec2.h"
#include "trigger_decoder.h"
#include "engine_test_helper.h"
2014-09-27 12:03:45 -07:00
#include "efiGpio.h"
2014-08-29 07:52:33 -07:00
extern float testMafValue;
void testFuelMap(void) {
printf("*************************************************** testFuelMap\r\n");
2014-10-02 11:03:28 -07:00
EngineTestHelper eth(FORD_ASPIRE_1996);
2014-08-29 07:52:33 -07:00
for (int k = 0; k < FUEL_LOAD_COUNT; k++) {
for (int r = 0; r < FUEL_RPM_COUNT; r++) {
2014-10-02 11:03:28 -07:00
eth.engine.engineConfiguration->fuelTable[k][r] = k * 200 + r;
2014-08-29 07:52:33 -07:00
}
}
2014-10-02 11:03:28 -07:00
for (int i = 0; i < FUEL_LOAD_COUNT; i++)
eth.engine.engineConfiguration->fuelLoadBins[i] = i;
for (int i = 0; i < FUEL_RPM_COUNT; i++)
eth.engine.engineConfiguration->fuelRpmBins[i] = i;
2014-08-29 07:52:33 -07:00
2014-10-02 11:03:28 -07:00
assertEqualsM("base fuel table", 1005, getBaseTableFuel(eth.engine.engineConfiguration, 5, 5));
2014-08-29 07:52:33 -07:00
2014-10-02 11:03:28 -07:00
printf("*************************************************** initThermistors\r\n");
2014-08-29 07:52:33 -07:00
2014-11-07 22:05:46 -08:00
Engine *engine = &eth.engine;
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
initThermistors(engine);
2014-08-29 07:52:33 -07:00
2014-10-02 11:03:28 -07:00
printf("*** getInjectorLag\r\n");
2014-11-07 22:05:46 -08:00
assertEquals(1.0, getInjectorLag(12 PASS_ENGINE_PARAMETER));
2014-08-29 07:52:33 -07:00
2014-10-02 11:03:28 -07:00
eth.engine.engineConfiguration->injectorLag = 0.5;
2014-08-29 07:52:33 -07:00
for (int i = 0; i < VBAT_INJECTOR_CURVE_SIZE; i++) {
2014-10-02 11:03:28 -07:00
eth.engine.engineConfiguration->battInjectorLagCorrBins[i] = i;
eth.engine.engineConfiguration->battInjectorLagCorr[i] = 2 * i;
2014-08-29 07:52:33 -07:00
}
// because all the correction tables are zero
2014-10-02 11:03:28 -07:00
printf("*************************************************** getRunningFuel 1\r\n");
2014-11-24 18:03:34 -08:00
float baseFuel = getBaseTableFuel(eth.engine.engineConfiguration, 5, getEngineLoadT(PASS_ENGINE_PARAMETER_F));
2014-11-29 21:03:06 -08:00
assertEqualsM("base fuel", 5.05, getRunningFuel(baseFuel, 5 PASS_ENGINE_PARAMETER));
2014-08-29 07:52:33 -07:00
printf("*************************************************** setting IAT table\r\n");
for (int i = 0; i < IAT_CURVE_SIZE; i++) {
2014-10-02 11:03:28 -07:00
eth.engine.engineConfiguration->iatFuelCorrBins[i] = i;
eth.engine.engineConfiguration->iatFuelCorr[i] = 2 * i;
2014-08-29 07:52:33 -07:00
}
2014-10-02 11:03:28 -07:00
eth.engine.engineConfiguration->iatFuelCorr[0] = 2;
2014-08-29 07:52:33 -07:00
printf("*************************************************** setting CLT table\r\n");
for (int i = 0; i < CLT_CURVE_SIZE; i++) {
2014-10-02 11:03:28 -07:00
eth.engine.engineConfiguration->cltFuelCorrBins[i] = i;
eth.engine.engineConfiguration->cltFuelCorr[i] = 1;
2014-08-29 07:52:33 -07:00
}
2014-10-02 11:03:28 -07:00
eth.engine.engineConfiguration->injectorLag = 0;
2014-08-29 07:52:33 -07:00
2014-10-31 12:03:00 -07:00
assertEquals(NAN, getIntakeAirTemperature(&eth.engine));
2014-11-07 22:05:46 -08:00
float iatCorrection = getIatCorrection(-KELV PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertEqualsM("IAT", 2, iatCorrection);
2014-11-07 22:05:46 -08:00
float cltCorrection = getCltCorrection(getCoolantTemperature(&eth.engine) PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertEqualsM("CLT", 1, cltCorrection);
2014-11-07 22:05:46 -08:00
float injectorLag = getInjectorLag(getVBatt(engineConfiguration) PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertEquals(0, injectorLag);
testMafValue = 5;
// 1005 * 2 for IAT correction
2014-10-02 11:03:28 -07:00
printf("*************************************************** getRunningFuel 2\r\n");
2014-11-24 18:03:34 -08:00
baseFuel = getBaseTableFuel(eth.engine.engineConfiguration, 5, getEngineLoadT(PASS_ENGINE_PARAMETER_F));
2014-11-07 22:05:46 -08:00
assertEqualsM("v1", 30150, getRunningFuel(baseFuel, 5 PASS_ENGINE_PARAMETER));
2014-08-29 07:52:33 -07:00
testMafValue = 0;
2014-11-03 07:04:35 -08:00
engineConfiguration->crankingSettings.baseCrankingFuel = 4;
2014-08-29 07:52:33 -07:00
printf("*************************************************** getStartingFuel\r\n");
// NAN in case we have issues with the CLT sensor
2014-11-03 10:03:03 -08:00
assertEqualsM("getStartingFuel nan", 4, getCrankingFuel3(engineConfiguration, NAN, 0));
assertEqualsM("getStartingFuel#1", 23.7333, getCrankingFuel3(engineConfiguration, 0, 4));
assertEqualsM("getStartingFuel#2", 18.0419, getCrankingFuel3(engineConfiguration, 8, 15));
assertEqualsM("getStartingFuel#3", 11.2000, getCrankingFuel3(engineConfiguration, 70, 0));
assertEqualsM("getStartingFuel#3", 5.6000, getCrankingFuel3(engineConfiguration, 70, 50));
2014-08-29 07:52:33 -07:00
}
2014-10-02 11:03:28 -07:00
extern engine_configuration_s *engineConfiguration;
extern engine_configuration2_s *engineConfiguration2;
2014-08-29 07:52:33 -07:00
static void confgiureFordAspireTriggerShape(trigger_shape_s * s) {
s->reset(FOUR_STROKE_CAM_SENSOR);
s->addEvent(53.747, T_SECONDARY, TV_HIGH);
s->addEvent(121.90, T_SECONDARY, TV_LOW);
s->addEvent(232.76, T_SECONDARY, TV_HIGH);
s->addEvent(300.54, T_SECONDARY, TV_LOW);
s->addEvent(360, T_PRIMARY, TV_HIGH);
s->addEvent(409.8412, T_SECONDARY, TV_HIGH);
s->addEvent(478.6505, T_SECONDARY, TV_LOW);
s->addEvent(588.045, T_SECONDARY, TV_HIGH);
s->addEvent(657.03, T_SECONDARY, TV_LOW);
s->addEvent(720, T_PRIMARY, TV_LOW);
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()));
assertEqualsM("expecting 0", 0, s->wave.waveIndertionAngle(23.747 / 720.0, s->getSize()));
assertEqualsM("expecting 1", 1, s->wave.waveIndertionAngle(63.747 / 720.0, s->getSize()));
}
static ActuatorEventList ae;
void testAngleResolver(void) {
printf("*************************************************** testAngleResolver\r\n");
2014-11-11 14:03:38 -08:00
EngineTestHelper eth(FORD_ASPIRE_1996);
Engine *engine = &eth.engine;
engine_configuration_s *engineConfiguration = eth.engine.engineConfiguration;
2014-11-07 21:07:22 -08:00
2014-08-29 07:52:33 -07:00
engineConfiguration->globalTriggerAngleOffset = 175;
2014-11-24 13:03:32 -08:00
assertTrue(engine->engineConfiguration2!=NULL);
trigger_shape_s * ts = &engine->triggerShape;
2014-08-29 07:52:33 -07:00
confgiureFordAspireTriggerShape(ts);
2014-11-24 13:03:32 -08:00
ts->calculateTriggerSynchPoint(engineConfiguration, engine);
2014-08-29 07:52:33 -07:00
2014-11-24 13:03:32 -08:00
assertEqualsM("index 2", 228.0450, ts->eventAngles[3]); // this angle is relation to synch point
2014-08-29 07:52:33 -07:00
assertEqualsM("time 2", 0.3233, ts->wave.getSwitchTime(2));
2014-11-24 13:03:32 -08:00
assertEqualsM("index 5", 413.7470, ts->eventAngles[6]);
2014-08-29 07:52:33 -07:00
assertEqualsM("time 5", 0.5692, ts->wave.getSwitchTime(5));
2014-11-24 13:03:32 -08:00
assertEquals(4, ts->getTriggerShapeSynchPointIndex());
2014-08-29 07:52:33 -07:00
assertEqualsM("shape size", 10, ts->getSize());
OutputSignalList list;
ae.resetEventList();
printf("*************************************************** testAngleResolver 0\r\n");
2014-11-25 09:05:03 -08:00
findTriggerPosition(&ae.getNextActuatorEvent()->position, 53 - 175 PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertEqualsM("size", 1, ae.size);
2014-11-24 13:03:32 -08:00
assertEquals(1, ae.events[0].position.eventIndex);
assertEquals(3.1588, ae.events[0].position.angleOffset);
2014-08-29 07:52:33 -07:00
printf("*************************************************** testAngleResolver 2\r\n");
ae.resetEventList();
2014-11-25 09:05:03 -08:00
findTriggerPosition(&ae.getNextActuatorEvent()->position, 51 + 180 - 175 PASS_ENGINE_PARAMETER);
2014-11-25 18:03:18 -08:00
assertEquals(2, ae.events[0].position.eventIndex);
assertEquals(112.3495, ae.events[0].position.angleOffset);
2014-08-29 07:52:33 -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));
}