diff --git a/firmware/controllers/actuators/idle_thread.cpp b/firmware/controllers/actuators/idle_thread.cpp index 7707f8ea03..db641acdec 100644 --- a/firmware/controllers/actuators/idle_thread.cpp +++ b/firmware/controllers/actuators/idle_thread.cpp @@ -57,7 +57,14 @@ IIdleController::Phase IdleController::determinePhase(float rpm, float targetRpm float maximumIdleRpm = targetRpm + engineConfiguration->idlePidRpmUpperLimit; looksLikeCoasting = rpm > maximumIdleRpm; looksLikeCrankToIdle = crankingTaperFraction < 1; - if (looksLikeCoasting && !looksLikeCrankToIdle) { + + // if car is gear, disable closed loop idle + // this applies to cars like NA/NB miatas where the clutch up switch only returns true if also in gear + bool transmissionInGear = engineConfiguration->disableIdleClutchUp + && isBrainPinValid(engineConfiguration->clutchUpPin) + && engine->engineState.clutchUpState; + + if ( (looksLikeCoasting || transmissionInGear) && !looksLikeCrankToIdle) { return Phase::Coasting; } diff --git a/firmware/controllers/actuators/idle_thread_io.cpp b/firmware/controllers/actuators/idle_thread_io.cpp index 6145526fb2..7bf8dd9c3d 100644 --- a/firmware/controllers/actuators/idle_thread_io.cpp +++ b/firmware/controllers/actuators/idle_thread_io.cpp @@ -58,10 +58,9 @@ percent_t getIdlePosition() { void startPedalPins() { #if EFI_PROD_CODE - // this is neutral/no gear switch input. on Miata it's wired both to clutch pedal and neutral in gearbox - // this switch is not used yet startInputPinIfValid("clutch down switch", engineConfiguration->clutchDownPin, engineConfiguration->clutchDownPinMode); + // this is neutral/no gear switch input. on Miata it's wired both to clutch pedal and neutral in gearbox startInputPinIfValid("clutch up switch", engineConfiguration->clutchUpPin, engineConfiguration->clutchUpPinMode); startInputPinIfValid("throttle pedal up switch", engineConfiguration->throttlePedalUpPin, engineConfiguration->throttlePedalUpPinMode); diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index be67de6293..0e745292e7 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -988,6 +988,7 @@ bit useSeparateAdvanceForCranking,"Table","Fixed (auto taper)";In Constant mode, bit useAdvanceCorrectionsForCranking;This enables the various ignition corrections during cranking (IAT, CLT, FSIO and PID idle).\nYou probably don't need this. bit flexCranking;Enable a second cranking table to use for E100 flex fuel, interpolating between the two based on flex fuel sensor. bit useIacPidMultTable;This flag allows to use a special 'PID Multiplier' table (0.0-1.0) to compensate for nonlinear nature of IAC-RPM controller +bit disableIdleClutchUp;Disable closed loop idle if ClutchUp is true. Only works for vehicles where the signal is only present when in gear, like NA/NB miatas. This helps prevent integral saturation while coasting at low RPM bit isBoostControlEnabled bit launchSmoothRetard;Interpolates the Ignition Retard from 0 to 100% within the RPM Range bit isPhaseSyncRequiredForIgnition;Some engines are OK running semi-random sequential while other engine require phase synchronization diff --git a/firmware/tunerstudio/tunerstudio.template.ini b/firmware/tunerstudio/tunerstudio.template.ini index eea2508d75..5f25a1326a 100644 --- a/firmware/tunerstudio/tunerstudio.template.ini +++ b/firmware/tunerstudio/tunerstudio.template.ini @@ -3368,6 +3368,7 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@@@ts_command_e_TS_ field = "RPM upper limit", idlePidRpmUpperLimit field = "RPM deadzone", idlePidRpmDeadZone field = "Max vehicle speed", maxIdleVss + field = "Disable Idle in Gear", disableIdleClutchUp, {clutchUpPin != @@ADC_CHANNEL_NONE@@} dialog = idleExtra, "Extra Idle Features" field = "Use idle ignition table", useSeparateAdvanceForIdle diff --git a/unit_tests/tests/test_idle_controller.cpp b/unit_tests/tests/test_idle_controller.cpp index 88a3add6ef..c8a9762639 100644 --- a/unit_tests/tests/test_idle_controller.cpp +++ b/unit_tests/tests/test_idle_controller.cpp @@ -105,6 +105,26 @@ TEST(idle_v2, testDeterminePhase) { // Below TPS but above RPM should be outside the zone EXPECT_EQ(ICP::Coasting, dut.determinePhase(1101, 1000, 0, 0, 10)); EXPECT_EQ(ICP::Coasting, dut.determinePhase(5000, 1000, 0, 0, 10)); + + // enable feature to prevent idle state when coasting in gear + engineConfiguration->disableIdleClutchUp = true; + setMockState(engineConfiguration->clutchUpPin, false); + engineConfiguration->clutchUpPin = Gpio::G2; + engineConfiguration->clutchUpPinMode = PI_PULLDOWN; + engine->updateSwitchInputs(); + + // should be same behaviour as before when clutch is pressed/car in neutral + EXPECT_EQ(ICP::Idling, dut.determinePhase(1099, 1000, 0, 0, 10)); + EXPECT_EQ(ICP::Coasting, dut.determinePhase(1101, 1000, 0, 0, 10)); + EXPECT_EQ(ICP::CrankToIdleTaper, dut.determinePhase(1000, 1000, 0, 0, 0.5f)); + EXPECT_EQ(ICP::Running, dut.determinePhase(1000, 1000, 10, 0, 10)); + + // clutchUp indicates car in gear with clutch not pressed, should recognize as coasting instead of idle now + setMockState(engineConfiguration->clutchUpPin, true); + engine->updateSwitchInputs(); + EXPECT_EQ(ICP::Coasting, dut.determinePhase(1099, 1000, 0, 0, 10)); + EXPECT_EQ(ICP::Coasting, dut.determinePhase(1101, 1000, 0, 0, 10)); + } TEST(idle_v2, crankingOpenLoop) { @@ -528,4 +548,4 @@ TEST(idle_v2, IntegrationClamping) { // Result would be 75 + 75 = 150, but it should clamp to 100 EXPECT_EQ(100, dut.getIdlePosition(950)); -} +} \ No newline at end of file