2015-07-10 06:01:56 -07:00
|
|
|
/*
|
|
|
|
* @file test_idle_controller.cpp
|
|
|
|
*
|
|
|
|
* @date Oct 17, 2013
|
2020-01-07 21:02:40 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "engine_test_helper.h"
|
2019-03-22 19:55:51 -07:00
|
|
|
#include "advance_map.h"
|
|
|
|
#include "tps.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
#include "pid.h"
|
2019-09-12 04:31:13 -07:00
|
|
|
#include "fsio_impl.h"
|
2019-09-19 19:56:54 -07:00
|
|
|
#include "idle_thread.h"
|
2019-09-19 21:34:42 -07:00
|
|
|
#include "allsensors.h"
|
|
|
|
#include "engine_controller.h"
|
2019-09-22 14:58:27 -07:00
|
|
|
#include "electronic_throttle.h"
|
2020-04-03 16:59:08 -07:00
|
|
|
#include "sensor.h"
|
2019-09-19 19:56:54 -07:00
|
|
|
|
|
|
|
extern IdleController idleControllerInstance;
|
2019-09-19 21:34:42 -07:00
|
|
|
extern int timeNowUs;
|
2019-09-12 04:31:13 -07:00
|
|
|
|
|
|
|
TEST(idle, fsioPidParameters) {
|
2019-09-19 21:34:42 -07:00
|
|
|
WITH_ENGINE_TEST_HELPER(MIATA_NA6_MAP);
|
2019-09-12 04:31:13 -07:00
|
|
|
|
2020-07-01 17:45:37 -07:00
|
|
|
engineConfiguration->idleRpmPid.offset = 40;
|
2020-07-07 22:12:08 -07:00
|
|
|
engineConfiguration->acIdleExtraOffset = 10;
|
2020-07-01 17:45:37 -07:00
|
|
|
|
|
|
|
engineConfiguration->idleRpmPid.minValue = 30;
|
2020-07-07 22:12:08 -07:00
|
|
|
engineConfiguration->acIdleExtraMin = 30;
|
2020-07-01 17:45:37 -07:00
|
|
|
|
2019-09-12 04:31:13 -07:00
|
|
|
engineConfiguration->useFSIO12ForIdleOffset = true;
|
2020-07-29 19:48:41 -07:00
|
|
|
applyFsioExpression(QUOTE(MAGIC_OFFSET_FOR_IDLE_OFFSET), "ac_on_switch 0 cfg_acIdleExtraOffset if" PASS_ENGINE_PARAMETER_SUFFIX);
|
2019-09-12 04:31:13 -07:00
|
|
|
|
|
|
|
engineConfiguration->useFSIO13ForIdleMinValue = true;
|
2020-07-29 19:48:41 -07:00
|
|
|
applyFsioExpression(QUOTE(MAGIC_OFFSET_FOR_IDLE_MIN_VALUE), "ac_on_switch 0 cfg_acIdleExtraMin if" PASS_ENGINE_PARAMETER_SUFFIX);
|
2019-09-18 18:48:46 -07:00
|
|
|
|
2020-07-01 17:45:37 -07:00
|
|
|
ASSERT_EQ(1, hasAcToggle(PASS_ENGINE_PARAMETER_SIGNATURE));
|
2020-11-18 19:47:40 -08:00
|
|
|
setMockState(engineConfiguration->acSwitch, true);
|
2020-09-10 19:16:20 -07:00
|
|
|
timeNowUs += MS2US(15);
|
|
|
|
ASSERT_TRUE(getAcToggle(PASS_ENGINE_PARAMETER_SIGNATURE));
|
2020-07-01 17:45:37 -07:00
|
|
|
|
2019-09-18 18:48:46 -07:00
|
|
|
eth.engine.periodicSlowCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2020-07-12 15:25:48 -07:00
|
|
|
ASSERT_EQ(40, getIdlePidOffset(PASS_ENGINE_PARAMETER_SIGNATURE));
|
|
|
|
ASSERT_EQ(30, getIdlePidMinValue(PASS_ENGINE_PARAMETER_SIGNATURE));
|
2019-09-19 21:34:42 -07:00
|
|
|
|
2020-11-18 19:47:40 -08:00
|
|
|
setMockState(engineConfiguration->acSwitch, false);
|
2020-09-10 19:16:20 -07:00
|
|
|
timeNowUs += MS2US(15);
|
|
|
|
ASSERT_FALSE(getAcToggle(PASS_ENGINE_PARAMETER_SIGNATURE));
|
2019-09-19 21:34:42 -07:00
|
|
|
|
2020-07-01 17:45:37 -07:00
|
|
|
eth.engine.periodicSlowCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2020-07-12 15:25:48 -07:00
|
|
|
ASSERT_EQ(50, getIdlePidOffset(PASS_ENGINE_PARAMETER_SIGNATURE));
|
|
|
|
ASSERT_EQ(60, getIdlePidMinValue(PASS_ENGINE_PARAMETER_SIGNATURE));
|
2019-09-19 21:34:42 -07:00
|
|
|
|
|
|
|
|
2020-07-01 17:45:37 -07:00
|
|
|
// todo finish this unit test!
|
|
|
|
// timeNowUs = MS2US(700);
|
2020-11-11 18:47:19 -08:00
|
|
|
idleControllerInstance.update();
|
2019-09-19 21:34:42 -07:00
|
|
|
// ASSERT_EQ(0, engine->acSwitchLastChangeTime);
|
|
|
|
// ASSERT_EQ(1, engine->acSwitchState);
|
2019-09-12 04:31:13 -07:00
|
|
|
}
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-09-29 11:36:41 -07:00
|
|
|
// see also util.pid test
|
2019-03-22 19:55:51 -07:00
|
|
|
TEST(idle, timingPid) {
|
|
|
|
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
|
|
|
|
|
|
|
|
// set PID settings
|
|
|
|
pid_s pidS;
|
|
|
|
pidS.pFactor = 0.1;
|
|
|
|
pidS.iFactor = 0;
|
|
|
|
pidS.dFactor = 0;
|
|
|
|
pidS.offset = 0;
|
|
|
|
pidS.minValue = -20;
|
|
|
|
pidS.maxValue = +20;
|
|
|
|
pidS.periodMs = 1;
|
|
|
|
|
|
|
|
// setup TimingPid settings
|
|
|
|
engineConfiguration->idleTimingPidDeadZone = 10;
|
|
|
|
engineConfiguration->idleTimingPidWorkZone = 100;
|
|
|
|
engineConfiguration->idlePidFalloffDeltaRpm = 30;
|
|
|
|
|
2020-04-15 06:48:17 -07:00
|
|
|
// setup target rpm curve
|
2019-03-22 19:55:51 -07:00
|
|
|
const int idleRpmTarget = 700;
|
2020-04-15 06:48:17 -07:00
|
|
|
setArrayValues<float>(engineConfiguration->cltIdleRpm, idleRpmTarget);
|
2019-03-22 19:55:51 -07:00
|
|
|
|
|
|
|
// setup other settings
|
|
|
|
engineConfiguration->idleTimingPid = pidS;
|
|
|
|
eth.engine.fsioState.fsioTimingAdjustment = 0;
|
|
|
|
eth.engine.fsioState.fsioIdleTargetRPMAdjustment = 0;
|
|
|
|
eth.engine.engineState.cltTimingCorrection = 0;
|
|
|
|
|
|
|
|
// configure TPS
|
2019-12-11 14:48:55 -08:00
|
|
|
engineConfiguration->idlePidDeactivationTpsThreshold = 10;
|
2020-04-03 16:59:08 -07:00
|
|
|
Sensor::setMockValue(SensorType::Tps1, 0);
|
2019-03-22 19:55:51 -07:00
|
|
|
|
|
|
|
// all corrections disabled, should be 0
|
2019-12-11 14:48:55 -08:00
|
|
|
engineConfiguration->useIdleTimingPidControl = false;
|
2019-03-22 19:55:51 -07:00
|
|
|
angle_t corr = getAdvanceCorrections(idleRpmTarget PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
ASSERT_EQ(0, corr) << "getAdvanceCorrections#1";
|
|
|
|
|
|
|
|
// basic IDLE PID correction test
|
2019-12-11 14:48:55 -08:00
|
|
|
engineConfiguration->useIdleTimingPidControl = true;
|
2019-03-22 19:55:51 -07:00
|
|
|
int baseTestRpm = idleRpmTarget + engineConfiguration->idleTimingPidWorkZone;
|
|
|
|
corr = getAdvanceCorrections(baseTestRpm PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
// (delta_rpm=-100) * (p-factor=0.1) = -10 degrees
|
|
|
|
ASSERT_EQ(-10, corr) << "getAdvanceCorrections#2";
|
|
|
|
|
|
|
|
// check if rpm is too close to the target
|
|
|
|
corr = getAdvanceCorrections((idleRpmTarget + engineConfiguration->idleTimingPidDeadZone) PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
ASSERT_EQ(0, corr) << "getAdvanceCorrections#3";
|
|
|
|
|
|
|
|
// check if rpm is too high (just outside the workzone and even falloff) so we disable the PID correction
|
|
|
|
int tooHighRpm = idleRpmTarget + engineConfiguration->idleTimingPidWorkZone + engineConfiguration->idlePidFalloffDeltaRpm;
|
|
|
|
corr = getAdvanceCorrections(tooHighRpm PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
ASSERT_EQ(0, corr) << "getAdvanceCorrections#4";
|
|
|
|
|
|
|
|
// check if rpm is within the falloff zone
|
|
|
|
int falloffRpm = idleRpmTarget + engineConfiguration->idleTimingPidWorkZone + (engineConfiguration->idlePidFalloffDeltaRpm / 2);
|
|
|
|
corr = getAdvanceCorrections(falloffRpm PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
// -(100+30/2) * 0.1 / 2 = -5.75
|
|
|
|
ASSERT_FLOAT_EQ(-5.75f, corr) << "getAdvanceCorrections#5";
|
|
|
|
|
|
|
|
// check if PID correction is disabled in running mode (tps > threshold):
|
2020-04-03 16:59:08 -07:00
|
|
|
Sensor::setMockValue(SensorType::Tps1, engineConfiguration->idlePidDeactivationTpsThreshold + 1);
|
2019-03-22 19:55:51 -07:00
|
|
|
corr = getAdvanceCorrections(idleRpmTarget PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
ASSERT_EQ(0, corr) << "getAdvanceCorrections#6";
|
|
|
|
|
|
|
|
// check if PID correction is interpolated for transient idle-running TPS positions
|
2020-04-03 16:59:08 -07:00
|
|
|
Sensor::setMockValue(SensorType::Tps1, engineConfiguration->idlePidDeactivationTpsThreshold / 2);
|
2019-03-22 19:55:51 -07:00
|
|
|
corr = getAdvanceCorrections(baseTestRpm PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
ASSERT_FLOAT_EQ(-5.0f, corr) << "getAdvanceCorrections#7";
|
|
|
|
|
|
|
|
}
|
2020-12-17 14:46:51 -08:00
|
|
|
|
|
|
|
TEST(idle_v2, testTargetRpm) {
|
|
|
|
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
|
|
|
|
IdleController dut;
|
|
|
|
INJECT_ENGINE_REFERENCE(&dut);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < efi::size(engineConfiguration->cltIdleRpmBins); i++) {
|
|
|
|
CONFIG(cltIdleRpmBins)[i] = i * 10;
|
|
|
|
CONFIG(cltIdleRpm)[i] = i * 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPECT_FLOAT_EQ(100, dut.getTargetRpm(10));
|
|
|
|
EXPECT_FLOAT_EQ(500, dut.getTargetRpm(50));
|
|
|
|
}
|
2020-12-26 05:32:01 -08:00
|
|
|
|
|
|
|
using ICP = IIdleController::Phase;
|
|
|
|
|
|
|
|
TEST(idle_v2, testDeterminePhase) {
|
|
|
|
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
|
|
|
|
IdleController dut;
|
|
|
|
INJECT_ENGINE_REFERENCE(&dut);
|
|
|
|
|
|
|
|
// TPS threshold 5% for easy test
|
|
|
|
CONFIG(idlePidDeactivationTpsThreshold) = 5;
|
|
|
|
// RPM window is 100 RPM above target
|
|
|
|
CONFIG(idlePidRpmUpperLimit) = 100;
|
|
|
|
|
|
|
|
// First test stopped engine
|
|
|
|
engine->rpmCalculator.setRpmValue(0);
|
|
|
|
EXPECT_EQ(ICP::Cranking, dut.determinePhase(0, 1000, unexpected));
|
|
|
|
|
|
|
|
// Now engine is running!
|
|
|
|
// Controller doesn't need this other than for isCranking()
|
|
|
|
engine->rpmCalculator.setRpmValue(1000);
|
|
|
|
|
|
|
|
// Test invalid TPS, but inside the idle window
|
|
|
|
EXPECT_EQ(ICP::Running, dut.determinePhase(1000, 1000, unexpected));
|
|
|
|
|
|
|
|
// Valid TPS should now be inside the zone
|
|
|
|
EXPECT_EQ(ICP::Idling, dut.determinePhase(1000, 1000, 0));
|
|
|
|
|
|
|
|
// Above TPS threshold should be outside the zone
|
|
|
|
EXPECT_EQ(ICP::Running, dut.determinePhase(1000, 1000, 10));
|
|
|
|
|
|
|
|
// Above target, below (target + upperLimit) should be in idle zone
|
|
|
|
EXPECT_EQ(ICP::Idling, dut.determinePhase(1099, 1000, 0));
|
|
|
|
|
|
|
|
// above upper limit and on throttle should be out of idle zone
|
|
|
|
EXPECT_EQ(ICP::Running, dut.determinePhase(1101, 1000, 10));
|
|
|
|
|
|
|
|
// Below TPS but above RPM should be outside the zone
|
|
|
|
EXPECT_EQ(ICP::Coasting, dut.determinePhase(1101, 1000, 0));
|
|
|
|
EXPECT_EQ(ICP::Coasting, dut.determinePhase(5000, 1000, 0));
|
|
|
|
}
|