TPS consumers: idle and ignition and obd2 and lcd (#1254)
* advance_map * tests * unneeded * idle * use driver intent instead * and obd and lcd Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
parent
067063e024
commit
9f75c0cea6
|
@ -231,7 +231,7 @@ static bool isOutOfAutomaticIdleCondition(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
/**
|
||||
* @return idle valve position percentage for automatic closed loop mode
|
||||
*/
|
||||
static percent_t automaticIdleController(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
static percent_t automaticIdleController(float tpsPos DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
if (isOutOfAutomaticIdleCondition(PASS_ENGINE_PARAMETER_SIGNATURE)) {
|
||||
// Don't store old I and D terms if PID doesn't work anymore.
|
||||
// Otherwise they will affect the idle position much later, when the throttle is closed.
|
||||
|
@ -287,7 +287,6 @@ static percent_t automaticIdleController(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
}
|
||||
|
||||
// Apply PID Deactivation Threshold as a smooth taper for TPS transients.
|
||||
percent_t tpsPos = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
// if tps==0 then PID just works as usual, or we completely disable it if tps>=threshold
|
||||
newValue = interpolateClamped(0.0f, newValue, CONFIG(idlePidDeactivationTpsThreshold), engine->engineState.idle.baseIdlePosition, tpsPos);
|
||||
|
||||
|
@ -326,7 +325,9 @@ static percent_t automaticIdleController(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
idlePid.iTermMin = engineConfiguration->idlerpmpid_iTermMin;
|
||||
idlePid.iTermMax = engineConfiguration->idlerpmpid_iTermMax;
|
||||
|
||||
engine->engineState.isAutomaticIdle = engineConfiguration->idleMode == IM_AUTO;
|
||||
SensorResult tps = Sensor::get(SensorType::DriverThrottleIntent);
|
||||
|
||||
engine->engineState.isAutomaticIdle = tps.Valid && engineConfiguration->idleMode == IM_AUTO;
|
||||
|
||||
if (engineConfiguration->isVerboseIAC && engine->engineState.isAutomaticIdle) {
|
||||
// todo: print each bit using 'getIdle_state_e' method
|
||||
|
@ -402,19 +403,21 @@ static percent_t automaticIdleController(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
lastCrankingCyclesCounter = engine->rpmCalculator.getRevolutionCounterSinceStart();
|
||||
engine->engineState.idle.baseIdlePosition = iacPosition;
|
||||
} else {
|
||||
if (engineConfiguration->idleMode == IM_MANUAL) {
|
||||
if (!tps.Valid || engineConfiguration->idleMode == IM_MANUAL) {
|
||||
// let's re-apply CLT correction
|
||||
iacPosition = manualIdleController(cltCorrection PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
} else {
|
||||
iacPosition = automaticIdleController(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
iacPosition = automaticIdleController(tps.Value PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
}
|
||||
|
||||
// store 'base' iacPosition without adjustments
|
||||
engine->engineState.idle.baseIdlePosition = iacPosition;
|
||||
|
||||
percent_t tpsPos = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
float additionalAir = (float)engineConfiguration->iacByTpsTaper;
|
||||
iacPosition += interpolateClamped(0.0f, 0.0f, CONFIG(idlePidDeactivationTpsThreshold), additionalAir, tpsPos);
|
||||
|
||||
if (tps.Valid) {
|
||||
iacPosition += interpolateClamped(0.0f, 0.0f, CONFIG(idlePidDeactivationTpsThreshold), additionalAir, tps.Value);
|
||||
}
|
||||
|
||||
// taper transition from cranking to running (uint32_t to float conversion is safe here)
|
||||
if (engineConfiguration->afterCrankingIACtaperDuration > 0)
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include "advance_map.h"
|
||||
#include "interpolation.h"
|
||||
#include "engine_math.h"
|
||||
#include "tps.h"
|
||||
#include "sensor.h"
|
||||
#include "idle_thread.h"
|
||||
#include "allsensors.h"
|
||||
#include "launch_control.h"
|
||||
|
@ -86,8 +86,9 @@ static angle_t getRunningAdvance(int rpm, float engineLoad DECLARE_ENGINE_PARAME
|
|||
|
||||
float advanceAngle;
|
||||
if (CONFIG(useTPSAdvanceTable)) {
|
||||
float tps = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
advanceAngle = advanceTpsMap.getValue((float) rpm, tps);
|
||||
// TODO: what do we do about multi-TPS?
|
||||
float tps = Sensor::get(SensorType::Tps1).value_or(0);
|
||||
advanceAngle = advanceTpsMap.getValue(rpm, tps);
|
||||
} else {
|
||||
advanceAngle = advanceMap.getValue((float) rpm, engineLoad);
|
||||
}
|
||||
|
@ -95,10 +96,13 @@ static angle_t getRunningAdvance(int rpm, float engineLoad DECLARE_ENGINE_PARAME
|
|||
// get advance from the separate table for Idle
|
||||
if (CONFIG(useSeparateAdvanceForIdle)) {
|
||||
float idleAdvance = interpolate2d("idleAdvance", rpm, config->idleAdvanceBins, config->idleAdvance);
|
||||
|
||||
auto [valid, tps] = Sensor::get(SensorType::DriverThrottleIntent);
|
||||
if (valid) {
|
||||
// interpolate between idle table and normal (running) table using TPS threshold
|
||||
float tps = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
advanceAngle = interpolateClamped(0.0f, idleAdvance, CONFIG(idlePidDeactivationTpsThreshold), advanceAngle, tps);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if EFI_LAUNCH_CONTROL
|
||||
|
@ -130,8 +134,11 @@ angle_t getAdvanceCorrections(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
if (CONFIG(useIdleTimingPidControl)) {
|
||||
int targetRpm = getTargetRpmForIdleCorrection(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
int rpmDelta = absI(rpm - targetRpm);
|
||||
float tps = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
if (tps >= CONFIG(idlePidDeactivationTpsThreshold)) {
|
||||
|
||||
auto [valid, tps] = Sensor::get(SensorType::Tps1);
|
||||
|
||||
// If TPS is invalid, or we aren't in the region, so reset state and don't apply PID
|
||||
if (!valid || tps >= CONFIG(idlePidDeactivationTpsThreshold)) {
|
||||
// we are not in the idle mode anymore, so the 'reset' flag will help us when we return to the idle.
|
||||
shouldResetTimingPid = true;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include "vehicle_speed.h"
|
||||
#include "map.h"
|
||||
#include "maf.h"
|
||||
#include "tps.h"
|
||||
#include "sensor.h"
|
||||
#include "engine_math.h"
|
||||
#include "fuel_math.h"
|
||||
#include "thermistors.h"
|
||||
|
@ -167,7 +167,7 @@ static void handleGetDataRequest(const CANRxFrame& rx) {
|
|||
break;
|
||||
case PID_THROTTLE:
|
||||
scheduleMsg(&logger, "Got throttle request");
|
||||
obdSendValue(1, pid, 1, getTPS(PASS_ENGINE_PARAMETER_SIGNATURE) * 2.55f); // (A*100/255)
|
||||
obdSendValue(1, pid, 1, Sensor::get(SensorType::Tps1).value_or(0) * 2.55f); // (A*100/255)
|
||||
break;
|
||||
case PID_FUEL_RATE:
|
||||
scheduleMsg(&logger, "Got fuel rate request");
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include "mmc_card.h"
|
||||
#include "idle_thread.h"
|
||||
#include "fuel_math.h"
|
||||
#include "sensor.h"
|
||||
|
||||
|
||||
EXTERN_ENGINE;
|
||||
|
@ -190,7 +191,7 @@ static void showLine(lcd_line_e line, int screenY) {
|
|||
case LL_TPS:
|
||||
getPinNameByAdcChannel("tps", engineConfiguration->tps1_1AdcChannel, buffer);
|
||||
|
||||
lcdPrintf("Throttle %s %.2f%%", buffer, getTPS());
|
||||
lcdPrintf("Throttle %s %.2f%%", buffer, Sensor::get(SensorType::Tps1).value_or(0));
|
||||
return;
|
||||
case LL_FUEL_CLT_CORRECTION:
|
||||
lcdPrintf("CLT corr %.2f", getCltFuelCorrection(PASS_ENGINE_PARAMETER_SIGNATURE));
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "allsensors.h"
|
||||
#include "engine_controller.h"
|
||||
#include "advance_map.h"
|
||||
#include "sensor.h"
|
||||
|
||||
extern int timeNowUs;
|
||||
extern WarningCodeState unitTestWarningCodeState;
|
||||
|
@ -28,6 +29,7 @@ EngineTestHelperBase::EngineTestHelperBase() {
|
|||
}
|
||||
|
||||
EngineTestHelper::EngineTestHelper(engine_type_e engineType, configuration_callback_t boardCallback) {
|
||||
Sensor::resetRegistry();
|
||||
unitTestWarningCodeState.clear();
|
||||
|
||||
testMafValue = 0;
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "allsensors.h"
|
||||
#include "engine_controller.h"
|
||||
#include "electronic_throttle.h"
|
||||
#include "sensor.h"
|
||||
|
||||
extern IdleController idleControllerInstance;
|
||||
extern int timeNowUs;
|
||||
|
@ -80,10 +81,8 @@ TEST(idle, timingPid) {
|
|||
eth.engine.engineState.cltTimingCorrection = 0;
|
||||
|
||||
// configure TPS
|
||||
engineConfiguration->tpsMin = 0;
|
||||
engineConfiguration->tpsMax = 100;
|
||||
engineConfiguration->idlePidDeactivationTpsThreshold = 10;
|
||||
setMockTpsAdc(0 PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
Sensor::setMockValue(SensorType::Tps1, 0);
|
||||
|
||||
// disable temperature sensors
|
||||
eth.engine.sensors.clt = NAN;
|
||||
|
@ -117,12 +116,12 @@ TEST(idle, timingPid) {
|
|||
ASSERT_FLOAT_EQ(-5.75f, corr) << "getAdvanceCorrections#5";
|
||||
|
||||
// check if PID correction is disabled in running mode (tps > threshold):
|
||||
setMockTpsAdc(engineConfiguration->idlePidDeactivationTpsThreshold + 1 PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
Sensor::setMockValue(SensorType::Tps1, engineConfiguration->idlePidDeactivationTpsThreshold + 1);
|
||||
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
|
||||
setMockTpsAdc(engineConfiguration->idlePidDeactivationTpsThreshold / 2 PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
Sensor::setMockValue(SensorType::Tps1, engineConfiguration->idlePidDeactivationTpsThreshold / 2);
|
||||
corr = getAdvanceCorrections(baseTestRpm PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
ASSERT_FLOAT_EQ(-5.0f, corr) << "getAdvanceCorrections#7";
|
||||
|
||||
|
|
Loading…
Reference in New Issue