2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* @file test_accel_enrichment.cpp
|
|
|
|
*
|
2019-10-16 13:46:34 -07:00
|
|
|
* @date Apr 29, 2014
|
2015-07-10 06:01:56 -07:00
|
|
|
* Author: Dmitry Sidin
|
2018-07-28 09:42:37 -07:00
|
|
|
* Author: Andrey Belomutskiy, (c) 2012-2018
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
|
|
|
|
2018-09-16 19:39:46 -07:00
|
|
|
#include "global.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
#include "engine_configuration.h"
|
2019-01-27 21:44:30 -08:00
|
|
|
#include "accel_enrichment.h"
|
2016-03-09 20:02:39 -08:00
|
|
|
#include "engine_test_helper.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-10-16 13:46:34 -07:00
|
|
|
TEST(fuel, testTpsAccelEnrichment) {
|
2018-12-25 14:26:36 -08:00
|
|
|
printf("====================================================================================== testAccelEnrichment\r\n");
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-01-19 17:42:29 -08:00
|
|
|
WITH_ENGINE_TEST_HELPER(FORD_ASPIRE_1996);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2017-05-15 20:28:49 -07:00
|
|
|
engine->rpmCalculator.setRpmValue(600 PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2016-03-09 20:02:39 -08:00
|
|
|
|
|
|
|
engine->tpsAccelEnrichment.setLength(4);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2017-05-15 20:28:49 -07:00
|
|
|
engine->tpsAccelEnrichment.onNewValue(0 PASS_ENGINE_PARAMETER_SUFFIX);
|
2019-01-14 15:38:20 -08:00
|
|
|
ASSERT_EQ( 0, engine->tpsAccelEnrichment.getMaxDelta(PASS_ENGINE_PARAMETER_SIGNATURE)) << "maxDelta";
|
2017-05-15 20:28:49 -07:00
|
|
|
engine->tpsAccelEnrichment.onNewValue(10 PASS_ENGINE_PARAMETER_SUFFIX);
|
2019-04-20 14:34:23 -07:00
|
|
|
ASSERT_EQ( 10, engine->tpsAccelEnrichment.getMaxDelta(PASS_ENGINE_PARAMETER_SIGNATURE)) << "maxDelta#1";
|
2017-05-15 20:28:49 -07:00
|
|
|
engine->tpsAccelEnrichment.onNewValue(30 PASS_ENGINE_PARAMETER_SUFFIX);
|
2019-04-20 14:34:23 -07:00
|
|
|
ASSERT_EQ( 20, engine->tpsAccelEnrichment.getMaxDelta(PASS_ENGINE_PARAMETER_SIGNATURE)) << "maxDelta#2";
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2017-05-15 20:28:49 -07:00
|
|
|
engine->tpsAccelEnrichment.onNewValue(0 PASS_ENGINE_PARAMETER_SUFFIX);
|
2019-04-20 14:34:23 -07:00
|
|
|
ASSERT_EQ( 20, engine->tpsAccelEnrichment.getMaxDelta(PASS_ENGINE_PARAMETER_SIGNATURE)) << "maxDelta#3";
|
2017-05-15 20:28:49 -07:00
|
|
|
engine->tpsAccelEnrichment.onNewValue(0 PASS_ENGINE_PARAMETER_SUFFIX);
|
2019-04-20 14:34:23 -07:00
|
|
|
ASSERT_EQ( 20, engine->tpsAccelEnrichment.getMaxDelta(PASS_ENGINE_PARAMETER_SIGNATURE)) << "maxDelta#4";
|
2017-05-15 20:28:49 -07:00
|
|
|
engine->tpsAccelEnrichment.onNewValue(0 PASS_ENGINE_PARAMETER_SUFFIX);
|
2019-01-14 15:38:20 -08:00
|
|
|
ASSERT_EQ( 0, engine->tpsAccelEnrichment.getMaxDelta(PASS_ENGINE_PARAMETER_SIGNATURE)) << "maxDelta#5";
|
2017-05-15 20:28:49 -07:00
|
|
|
engine->tpsAccelEnrichment.onNewValue(0 PASS_ENGINE_PARAMETER_SUFFIX);
|
2019-01-14 15:38:20 -08:00
|
|
|
ASSERT_EQ( 0, engine->tpsAccelEnrichment.getMaxDelta(PASS_ENGINE_PARAMETER_SIGNATURE)) << "maxDelta";
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
2019-03-28 19:47:20 -07:00
|
|
|
|
|
|
|
static void doFractionalTpsIteration(int period, int divisor, int numCycles, std::vector<floatms_t> &tpsEnrich DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|
|
|
// every cycle
|
|
|
|
engineConfiguration->tpsAccelFractionPeriod = period;
|
|
|
|
// split into 2 portions
|
|
|
|
engineConfiguration->tpsAccelFractionDivisor = divisor;
|
|
|
|
|
2019-07-13 05:19:00 -07:00
|
|
|
engine->tpsAccelEnrichment.resetAE();
|
2019-03-28 19:47:20 -07:00
|
|
|
engine->tpsAccelEnrichment.onNewValue(0 PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
for (int i = 0; i < numCycles; i++) {
|
|
|
|
engine->tpsAccelEnrichment.onNewValue(10 PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
engine->tpsAccelEnrichment.onEngineCycleTps(PASS_ENGINE_PARAMETER_SIGNATURE);
|
|
|
|
tpsEnrich[i] = engine->tpsAccelEnrichment.getTpsEnrichment(PASS_ENGINE_PARAMETER_SIGNATURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(big, testAccelEnrichmentFractionalTps) {
|
|
|
|
printf("====================================================================================== testAccelEnrichmentFractionalTps\r\n");
|
|
|
|
|
|
|
|
WITH_ENGINE_TEST_HELPER(FORD_ASPIRE_1996);
|
|
|
|
|
|
|
|
// setup
|
|
|
|
engineConfiguration->tpsAccelEnrichmentThreshold = 5;
|
|
|
|
|
|
|
|
// fill tps2tps map (todo: there should be a better way?)
|
|
|
|
static const float tpsTpsConst = 1.0f;
|
|
|
|
for (int loadIndex = 0; loadIndex < TPS_TPS_ACCEL_TABLE; loadIndex++) {
|
|
|
|
for (int rpmIndex = 0; rpmIndex < TPS_TPS_ACCEL_TABLE; rpmIndex++) {
|
|
|
|
config->tpsTpsAccelTable[loadIndex][rpmIndex] = tpsTpsConst;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Logging logger;
|
|
|
|
initAccelEnrichment(&logger PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
|
|
|
|
engine->rpmCalculator.setRpmValue(600 PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
|
|
|
|
|
|
|
|
engine->tpsAccelEnrichment.setLength(2);
|
|
|
|
|
|
|
|
|
|
|
|
const int numCycles = 4;
|
|
|
|
std::vector<floatms_t> tpsEnrich(numCycles);
|
|
|
|
|
|
|
|
// first, test the default behavior without fractional division
|
|
|
|
doFractionalTpsIteration(1, 1, numCycles, tpsEnrich PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
// the portion for the first cycle is full-enriched and there's no enrichment for next cycles
|
|
|
|
EXPECT_THAT(tpsEnrich, testing::ElementsAre(1.0f, 0.0f, 0.0f, 0.0f)) << "fractionalTps#1";
|
|
|
|
|
|
|
|
// divide into 2 each cycle
|
|
|
|
doFractionalTpsIteration(1, 2, numCycles, tpsEnrich PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
// we have half-portion for the first cycle, then 1/4-th and 1/8th and so on...
|
|
|
|
EXPECT_THAT(tpsEnrich, testing::ElementsAre(0.5f, 0.25f, 0.125f, 0.0625f)) << "fractionalTps#2";
|
|
|
|
|
|
|
|
// split every portion into 3 sub-portions (so the whole enrichment takes longer)
|
|
|
|
doFractionalTpsIteration(3, 1, numCycles, tpsEnrich PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
// we have 1/3rd-portion for the first three cycles
|
|
|
|
const float th = (1.0f / 3.0f);
|
|
|
|
EXPECT_THAT(tpsEnrich, testing::ElementsAre(testing::FloatEq(th), testing::FloatEq(th), testing::FloatEq(th), 0.0f)) << "fractionalTps#3";
|
|
|
|
|
|
|
|
// split every divided portion into 2 sub-portions (so the whole enrichment takes longer)
|
|
|
|
doFractionalTpsIteration(2, 2, numCycles, tpsEnrich PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
// we have half-portion for the first two cycles, and 1/4-th portion for the next 2 cycles, and so on...
|
|
|
|
EXPECT_THAT(tpsEnrich, testing::ElementsAre(0.25f, 0.25f, 0.125f, 0.125f)) << "fractionalTps#4";
|
|
|
|
|
|
|
|
}
|