2015-07-10 06:01:56 -07:00
|
|
|
/*
|
|
|
|
* @file test_idle_controller.cpp
|
|
|
|
*
|
|
|
|
* @date Oct 17, 2013
|
2019-08-08 18:27:57 -07:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2019
|
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"
|
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
|
|
|
|
2019-09-18 18:48:46 -07:00
|
|
|
#define Q(x) #x
|
|
|
|
#define QUOTE(x) Q(x)
|
|
|
|
|
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
|
|
|
|
|
|
|
// todo finish this unit test!
|
|
|
|
engineConfiguration->useFSIO12ForIdleOffset = true;
|
2019-09-19 05:05:23 -07:00
|
|
|
setFsioExpression(QUOTE(MAGIC_OFFSET_FOR_IDLE_OFFSET), "ac_on_switch cfg_idleRpmPid_offset cfg_idleRpmPid2_offset if" PASS_ENGINE_PARAMETER_SUFFIX);
|
2019-09-12 04:31:13 -07:00
|
|
|
|
|
|
|
engineConfiguration->useFSIO13ForIdleMinValue = true;
|
2019-09-19 05:05:23 -07:00
|
|
|
setFsioExpression(QUOTE(MAGIC_OFFSET_FOR_IDLE_MIN_VALUE), "ac_on_switch cfg_idleRpmPid_minValue cfg_idleRpmPid2_minValue if" PASS_ENGINE_PARAMETER_SUFFIX);
|
2019-09-18 18:48:46 -07:00
|
|
|
|
|
|
|
eth.engine.periodicSlowCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2019-09-19 21:34:42 -07:00
|
|
|
|
|
|
|
ASSERT_EQ(1, hasAcToggle(PASS_ENGINE_PARAMETER_SIGNATURE));
|
|
|
|
// ASSERT_EQ(0, getAcToggle(PASS_ENGINE_PARAMETER_SIGNATURE));
|
|
|
|
|
|
|
|
// setMockVoltage(engineConfiguration->acSwitchAdc, 5 PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
// ASSERT_EQ(1, getAcToggle(PASS_ENGINE_PARAMETER_SIGNATURE));
|
|
|
|
|
|
|
|
// timeNowUs = MS2US(700);
|
|
|
|
|
2019-09-19 21:46:35 -07:00
|
|
|
idleControllerInstance.PeriodicTask();
|
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) {
|
|
|
|
print("******************************************* testTimingPidController\r\n");
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
// setup target rpm curve (we need only 1 value when CLT sensor is disabled)
|
|
|
|
const int idleRpmTarget = 700;
|
|
|
|
engineConfiguration->cltIdleRpm[0] = idleRpmTarget;
|
|
|
|
|
|
|
|
// setup other settings
|
|
|
|
engineConfiguration->idleTimingPid = pidS;
|
|
|
|
eth.engine.fsioState.fsioTimingAdjustment = 0;
|
|
|
|
eth.engine.fsioState.fsioIdleTargetRPMAdjustment = 0;
|
|
|
|
eth.engine.engineState.cltTimingCorrection = 0;
|
|
|
|
|
|
|
|
// configure TPS
|
|
|
|
engineConfiguration->tpsMin = 0;
|
|
|
|
engineConfiguration->tpsMax = 100;
|
|
|
|
engineConfiguration->bc.idlePidDeactivationTpsThreshold = 10;
|
2019-05-27 12:56:12 -07:00
|
|
|
setMockTpsAdc(0 PASS_ENGINE_PARAMETER_SUFFIX);
|
2019-03-22 19:55:51 -07:00
|
|
|
|
|
|
|
// disable temperature sensors
|
|
|
|
eth.engine.sensors.clt = NAN;
|
|
|
|
eth.engine.sensors.iat = NAN;
|
|
|
|
|
|
|
|
// all corrections disabled, should be 0
|
|
|
|
engineConfiguration->bc.useIdleTimingPidControl = false;
|
|
|
|
angle_t corr = getAdvanceCorrections(idleRpmTarget PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
ASSERT_EQ(0, corr) << "getAdvanceCorrections#1";
|
|
|
|
|
|
|
|
// basic IDLE PID correction test
|
|
|
|
engineConfiguration->bc.useIdleTimingPidControl = true;
|
|
|
|
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):
|
2019-05-27 12:56:12 -07:00
|
|
|
setMockTpsAdc(engineConfiguration->bc.idlePidDeactivationTpsThreshold + 1 PASS_ENGINE_PARAMETER_SUFFIX);
|
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
|
2019-05-27 12:56:12 -07:00
|
|
|
setMockTpsAdc(engineConfiguration->bc.idlePidDeactivationTpsThreshold / 2 PASS_ENGINE_PARAMETER_SUFFIX);
|
2019-03-22 19:55:51 -07:00
|
|
|
corr = getAdvanceCorrections(baseTestRpm PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
ASSERT_FLOAT_EQ(-5.0f, corr) << "getAdvanceCorrections#7";
|
|
|
|
|
|
|
|
}
|
2019-09-22 04:58:03 -07:00
|
|
|
|
2019-09-22 14:58:27 -07:00
|
|
|
// not great that we are reusing shared instance. todo: move EtbController to Engine?
|
|
|
|
extern EtbController etbController;
|
2019-09-22 04:58:03 -07:00
|
|
|
|
|
|
|
TEST(idle, testTargetTpsIsFloatBug945) {
|
|
|
|
|
|
|
|
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
|
|
|
|
|
2019-09-22 14:58:27 -07:00
|
|
|
setMockThrottlePedalSensorVoltage(3 PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
etbController.PeriodicTask();
|
|
|
|
ASSERT_NEAR(50, engine->engineState.targetFromTable, EPS4D);
|
|
|
|
|
|
|
|
setMockThrottlePedalSensorVoltage(3.05 PASS_ENGINE_PARAMETER_SUFFIX);
|
2019-09-22 15:15:00 -07:00
|
|
|
ASSERT_NEAR(50.8302, getPedalPosition(PASS_ENGINE_PARAMETER_SIGNATURE), EPS4D);
|
2019-09-22 14:58:27 -07:00
|
|
|
etbController.PeriodicTask();
|
2019-09-22 15:15:00 -07:00
|
|
|
ASSERT_NEAR(50.8302, engine->engineState.targetFromTable, EPS4D);
|
2019-09-22 14:58:27 -07:00
|
|
|
|
|
|
|
setMockThrottlePedalSensorVoltage(3.1 PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
etbController.PeriodicTask();
|
2019-09-22 15:15:00 -07:00
|
|
|
ASSERT_NEAR(51.6605, engine->engineState.targetFromTable, EPS4D);
|
2019-09-22 04:58:03 -07:00
|
|
|
|
|
|
|
}
|