From 49f8daae14445a3f4b0d3ddcea3bf0d08f25cbf8 Mon Sep 17 00:00:00 2001 From: David Holdeman Date: Sat, 23 Apr 2022 06:34:39 -0500 Subject: [PATCH] More untested transmission features (#4093) * use ISS for gearbox ratio, add gauge for TC ratio * measure shift time * add shift time gauge, todo notes for pc * do conversion in the right direction * switch to Timer and seconds * try fixing build * try fixing build again * try defines, remove include * use shift pcs * add 3-2 pct curve * control 3-2 solenoid * move 3-2 to persistent config * fix param --- .../boards/hellen/cypress/efifeatures.h | 2 + firmware/config/boards/kinetis/efifeatures.h | 4 ++ firmware/config/boards/skeleton/efifeatures.h | 4 ++ firmware/config/stm32f4ems/efifeatures.h | 4 ++ firmware/console/binary/output_channels.txt | 9 ++- firmware/controllers/algo/engine.h | 3 + firmware/controllers/algo/gear_detector.cpp | 7 ++- firmware/controllers/buttonshift.cpp | 2 + firmware/controllers/buttonshift.h | 2 + firmware/controllers/engine_controller.cpp | 5 ++ firmware/controllers/gear_controller.cpp | 2 + firmware/controllers/gear_controller.h | 2 + firmware/controllers/simple_tcu.cpp | 5 +- firmware/controllers/simple_tcu.h | 2 + firmware/controllers/tc_4l6x.cpp | 57 ++++++++++++++++--- firmware/controllers/tc_4l6x.h | 5 ++ firmware/controllers/tcu.cpp | 21 ++++++- firmware/controllers/tcu.h | 9 +++ firmware/integration/rusefi_config.txt | 4 ++ firmware/tunerstudio/rusefi.input | 15 ++++- 20 files changed, 150 insertions(+), 14 deletions(-) diff --git a/firmware/config/boards/hellen/cypress/efifeatures.h b/firmware/config/boards/hellen/cypress/efifeatures.h index 1506197819..785cd10a45 100644 --- a/firmware/config/boards/hellen/cypress/efifeatures.h +++ b/firmware/config/boards/hellen/cypress/efifeatures.h @@ -176,6 +176,8 @@ #define EFI_VEHICLE_SPEED FALSE +#define EFI_TCU FALSE + #define EFI_ENGINE_EMULATOR TRUE #define EFI_EMULATE_POSITION_SENSORS TRUE diff --git a/firmware/config/boards/kinetis/efifeatures.h b/firmware/config/boards/kinetis/efifeatures.h index 6591bca1d3..2760881158 100644 --- a/firmware/config/boards/kinetis/efifeatures.h +++ b/firmware/config/boards/kinetis/efifeatures.h @@ -161,6 +161,10 @@ #define EFI_VEHICLE_SPEED FALSE #endif +#ifndef EFI_TCU +#define EFI_TCU FALSE +#endif + #ifndef EFI_ENGINE_EMULATOR #define EFI_ENGINE_EMULATOR FALSE #endif diff --git a/firmware/config/boards/skeleton/efifeatures.h b/firmware/config/boards/skeleton/efifeatures.h index 53c97d27b5..be9c1bb7f1 100644 --- a/firmware/config/boards/skeleton/efifeatures.h +++ b/firmware/config/boards/skeleton/efifeatures.h @@ -170,6 +170,10 @@ #define EFI_VEHICLE_SPEED TRUE #endif +#ifndef EFI_TCU +#define EFI_TCU TRUE +#endif + #ifndef EFI_ENGINE_EMULATOR #define EFI_ENGINE_EMULATOR TRUE #endif diff --git a/firmware/config/stm32f4ems/efifeatures.h b/firmware/config/stm32f4ems/efifeatures.h index 3ac42bbeaa..59eee79a92 100644 --- a/firmware/config/stm32f4ems/efifeatures.h +++ b/firmware/config/stm32f4ems/efifeatures.h @@ -243,6 +243,10 @@ #define EFI_VEHICLE_SPEED TRUE #endif +#ifndef EFI_TCU +#define EFI_TCU TRUE +#endif + #ifndef EFI_ENGINE_EMULATOR #define EFI_ENGINE_EMULATOR TRUE #endif diff --git a/firmware/console/binary/output_channels.txt b/firmware/console/binary/output_channels.txt index fce34b311e..06c8fd62c1 100644 --- a/firmware/console/binary/output_channels.txt +++ b/firmware/console/binary/output_channels.txt @@ -280,7 +280,6 @@ uint16_t rpmAcceleration;dRPM;"RPM/s",1, 0, 0, 5, 0 uint8_t tpsAccelFrom;;"%", 1, 0, 0, 100, 0 uint8_t tpsAccelTo;;"%", 1, 0, 0, 100, 0 -! we have some unused bytes to allow compatible TS changes float autoscale calibrationValue2;;"", 1, 0, 0, 0, 0 bit isMainRelayOn; bit isUsbConnected;Original reason for this is to check if USB is connected from Lua @@ -288,7 +287,13 @@ uint16_t rpmAcceleration;dRPM;"RPM/s",1, 0, 0, 5, 0 int luaInvocationCounter;;"count",1, 0, 0, 0, 0 int luaLastCycleDuration;;"nt",1, 0, 0, 0, 0 uint8_t testBenchIter;;"count",1, 0, 0, 0, 0 - uint8_t[15 iterate] unusedInTheMiddle;;"",1, 0, 0, 0, 0 +uint8_t unusedWat + + uint16_t autoscale tcRatio;@@GAUGE_NAME_TC_RATIO@@;"value",{1/@@PACK_MULT_PERCENT@@}, 0, 0, 0, 0 + float lastShiftTime;"S" + +! we have some unused bytes to allow compatible TS changes + uint8_t[8 iterate] unusedInTheMiddle;;"",1, 0, 0, 0, 0 int16_t autoscale auxLinear1;@@GAUGE_NAME_AUX_LINEAR_1@@;"", 0.01, 0, 0, 0, 0 int16_t autoscale auxLinear2;@@GAUGE_NAME_AUX_LINEAR_2@@;"", 0.01, 0, 0, 0, 0 diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index a88cf193ce..22e576d957 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -205,7 +205,10 @@ public: cyclic_buffer triggerErrorDetection; +#if EFI_TCU GearControllerBase *gearController; +#endif + #if EFI_LAUNCH_CONTROL LaunchControlBase launchController; SoftSparkLimiter softSparkLimiter; diff --git a/firmware/controllers/algo/gear_detector.cpp b/firmware/controllers/algo/gear_detector.cpp index 244bde89fb..179f144139 100644 --- a/firmware/controllers/algo/gear_detector.cpp +++ b/firmware/controllers/algo/gear_detector.cpp @@ -85,7 +85,12 @@ float GearDetector::computeGearboxRatio() const { return 0; } - auto engineRpm = Sensor::getOrZero(SensorType::Rpm); + float engineRpm; + if (Sensor::hasSensor(SensorType::InputShaftSpeed)) { + engineRpm = Sensor::getOrZero(SensorType::InputShaftSpeed); + } else { + engineRpm = Sensor::getOrZero(SensorType::Rpm); + } // Convert to wheel RPM // km rev 1 hr diff --git a/firmware/controllers/buttonshift.cpp b/firmware/controllers/buttonshift.cpp index 515cf428c0..e8d0c42e3f 100644 --- a/firmware/controllers/buttonshift.cpp +++ b/firmware/controllers/buttonshift.cpp @@ -10,6 +10,7 @@ #include "buttonshift.h" +#if EFI_TCU ButtonShiftController buttonShiftController; ButtonShiftController::ButtonShiftController() : @@ -83,3 +84,4 @@ void ButtonShiftController::update() { ButtonShiftController* getButtonShiftController() { return &buttonShiftController; } +#endif // EFI_TCU diff --git a/firmware/controllers/buttonshift.h b/firmware/controllers/buttonshift.h index 888f9bc5f6..8d6caafc46 100644 --- a/firmware/controllers/buttonshift.h +++ b/firmware/controllers/buttonshift.h @@ -11,6 +11,7 @@ #include "globalaccess.h" #include "debounce.h" +#if EFI_TCU class ButtonShiftController: public GearControllerBase { public: ButtonShiftController(); @@ -26,3 +27,4 @@ private: }; ButtonShiftController* getButtonShiftController(); +#endif // EFI_TCU diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index f1a39f6b85..1f3b343b1a 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -224,6 +224,7 @@ static void doPeriodicSlowCallback() { engine->periodicSlowCallback(); #endif /* if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT */ +#if EFI_TCU if (engineConfiguration->tcuEnabled && engineConfiguration->gearControllerMode != GearControllerMode::None) { if (engine->gearController == NULL) { initGearController(); @@ -232,6 +233,8 @@ static void doPeriodicSlowCallback() { } engine->gearController->update(); } +#endif + } void initPeriodicEvents() { @@ -514,7 +517,9 @@ void commonInitEngineController() { startIdleThread(); #endif /* EFI_IDLE_CONTROL */ +#if EFI_TCU initGearController(); +#endif initButtonDebounce(); initStartStopButton(); diff --git a/firmware/controllers/gear_controller.cpp b/firmware/controllers/gear_controller.cpp index ada05bd2c3..771ca725af 100644 --- a/firmware/controllers/gear_controller.cpp +++ b/firmware/controllers/gear_controller.cpp @@ -2,6 +2,7 @@ #include "gear_controller.h" +#if EFI_TCU void GearControllerBase::init() { initTransmissionController(); } @@ -60,3 +61,4 @@ void initGearController() { } engine->gearController->init(); } +#endif // EFI_TCU diff --git a/firmware/controllers/gear_controller.h b/firmware/controllers/gear_controller.h index 6d2604eb5a..ad1ed50a76 100644 --- a/firmware/controllers/gear_controller.h +++ b/firmware/controllers/gear_controller.h @@ -8,6 +8,7 @@ #include "simple_tcu.h" #include "tc_4l6x.h" +#if EFI_TCU class GearControllerBase { public: virtual void update(); @@ -26,3 +27,4 @@ private: }; void initGearController(); +#endif // EFI_TCU diff --git a/firmware/controllers/simple_tcu.cpp b/firmware/controllers/simple_tcu.cpp index 62957613c2..ec65a6d101 100644 --- a/firmware/controllers/simple_tcu.cpp +++ b/firmware/controllers/simple_tcu.cpp @@ -2,6 +2,7 @@ #include "simple_tcu.h" +#if EFI_TCU SimpleTransmissionController simpleTransmissionController; void SimpleTransmissionController::init() { @@ -17,7 +18,6 @@ void SimpleTransmissionController::update(gear_e gear) { #endif } setCurrentGear(gear); - postState(); #if EFI_TUNER_STUDIO if (engineConfiguration->debugMode == DBG_TCU) { @@ -28,8 +28,11 @@ void SimpleTransmissionController::update(gear_e gear) { engine->outputChannels.debugIntField5 = config->tcuSolenoidTable[static_cast(gear) + 1][4]; } #endif + + TransmissionControllerBase::update(gear); } SimpleTransmissionController* getSimpleTransmissionController() { return &simpleTransmissionController; } +#endif // EFI_TCU diff --git a/firmware/controllers/simple_tcu.h b/firmware/controllers/simple_tcu.h index 712835a648..47ae126121 100644 --- a/firmware/controllers/simple_tcu.h +++ b/firmware/controllers/simple_tcu.h @@ -4,6 +4,7 @@ #include "tcu.h" +#if EFI_TCU class SimpleTransmissionController: public TransmissionControllerBase { public: void update(gear_e); @@ -14,3 +15,4 @@ public: }; SimpleTransmissionController* getSimpleTransmissionController(); +#endif // EFI_TCU diff --git a/firmware/controllers/tc_4l6x.cpp b/firmware/controllers/tc_4l6x.cpp index b487dd091e..9be6d27432 100644 --- a/firmware/controllers/tc_4l6x.cpp +++ b/firmware/controllers/tc_4l6x.cpp @@ -2,6 +2,7 @@ #include "tc_4l6x.h" +#if EFI_TCU Gm4l6xTransmissionController gm4l6xTransmissionController; static SimplePwm tccPwm("TCC Control"); static SimplePwm pcPwm("Pressure Control"); @@ -39,7 +40,7 @@ void Gm4l6xTransmissionController::update(gear_e gear) { setCurrentGear(gear); setTccState(); setPcState(gear); - postState(); + set32State(gear); #if EFI_TUNER_STUDIO if (engineConfiguration->debugMode == DBG_TCU) { @@ -50,6 +51,14 @@ void Gm4l6xTransmissionController::update(gear_e gear) { engine->outputChannels.debugIntField5 = config->tcuSolenoidTable[static_cast(gear) + 1][4]; } #endif + + TransmissionControllerBase::update(gear); + + float time = isShiftCompleted(); + if (time != 0) { + engine->outputChannels.lastShiftTime = time; + isShifting = false; + } } gear_e Gm4l6xTransmissionController::setCurrentGear(gear_e gear) { @@ -63,6 +72,7 @@ gear_e Gm4l6xTransmissionController::setCurrentGear(gear_e gear) { enginePins.tcuSolenoids[i].setValue(config->tcuSolenoidTable[static_cast(gear) + 1][i]); #endif } + measureShiftTime(gear); return getCurrentGear(); } @@ -86,9 +96,11 @@ void Gm4l6xTransmissionController::setTccState() { } void Gm4l6xTransmissionController::setPcState(gear_e gear) { - if (gear != getCurrentGear()) { - } uint8_t (*pcts)[sizeof(config->tcu_pcAirmassBins)/sizeof(config->tcu_pcAirmassBins[0])]; + if (gear != getCurrentGear()) { + shiftingFrom = getCurrentGear(); + isShifting = true; + } switch (getCurrentGear()) { case REVERSE: pcts = &config->tcu_pcValsR; @@ -97,22 +109,53 @@ void Gm4l6xTransmissionController::setPcState(gear_e gear) { pcts = &config->tcu_pcValsN; break; case GEAR_1: - pcts = &config->tcu_pcValsR; + if (isShifting && shiftingFrom == GEAR_2) { + pcts = &config->tcu_pcVals21; + } else { + pcts = &config->tcu_pcVals1; + } break; case GEAR_2: - pcts = &config->tcu_pcValsR; + if (isShifting && shiftingFrom == GEAR_1) { + pcts = &config->tcu_pcVals12; + } else if (isShifting && shiftingFrom == GEAR_3) { + pcts = &config->tcu_pcVals32; + } else { + pcts = &config->tcu_pcVals2; + } break; case GEAR_3: - pcts = &config->tcu_pcValsR; + if (isShifting && shiftingFrom == GEAR_2) { + pcts = &config->tcu_pcVals23; + } else if (isShifting && shiftingFrom == GEAR_4) { + pcts = &config->tcu_pcVals43; + } else { + pcts = &config->tcu_pcVals3; + } break; case GEAR_4: - pcts = &config->tcu_pcValsR; + pcts = &config->tcu_pcVals4; break; } int pct = interpolate2d(engine->engineState.sd.airMassInOneCylinder, config->tcu_pcAirmassBins, *pcts); pcPwm.setSimplePwmDutyCycle(pct*0.01); } +void Gm4l6xTransmissionController::set32State(gear_e gear) { + if (isShifting && shiftingFrom == GEAR_3 && gear == GEAR_2) { + auto vss = Sensor::get(SensorType::VehicleSpeed); + if (!vss.Valid) { + return; + } + uint8_t (*pcts)[sizeof(config->tcu_32SpeedBins)/sizeof(config->tcu_32SpeedBins[0])]; + int pct = interpolate2d(vss.Value, config->tcu_32SpeedBins, config->tcu_32Vals); + shift32Pwm.setSimplePwmDutyCycle(pct*0.01); + } else { + shift32Pwm.setSimplePwmDutyCycle(0); + } +} + Gm4l6xTransmissionController* getGm4l6xTransmissionController() { return &gm4l6xTransmissionController; } +#endif // EFI_TCU diff --git a/firmware/controllers/tc_4l6x.h b/firmware/controllers/tc_4l6x.h index fe7734caa7..dbf1dfef2f 100644 --- a/firmware/controllers/tc_4l6x.h +++ b/firmware/controllers/tc_4l6x.h @@ -2,6 +2,7 @@ #include "tcu.h" +#if EFI_TCU class Gm4l6xTransmissionController: public TransmissionControllerBase { public: void update(gear_e); @@ -13,6 +14,10 @@ private: gear_e setCurrentGear(gear_e gear); void setTccState(); void setPcState(gear_e gear); + void set32State(gear_e gear); + bool isShifting = false; + gear_e shiftingFrom; }; Gm4l6xTransmissionController* getGm4l6xTransmissionController(); +#endif // EFI_TCU diff --git a/firmware/controllers/tcu.cpp b/firmware/controllers/tcu.cpp index 2d660c89fc..6d7efce021 100644 --- a/firmware/controllers/tcu.cpp +++ b/firmware/controllers/tcu.cpp @@ -9,13 +9,14 @@ #include "pch.h" #include "tcu.h" +#include "engine.h" +#if EFI_TCU void TransmissionControllerBase::init() { } void TransmissionControllerBase::update(gear_e gear) { - setCurrentGear(gear); - postState(); + postState(); } gear_e TransmissionControllerBase::setCurrentGear(gear_e gear) { @@ -32,3 +33,19 @@ void TransmissionControllerBase::postState() { engine->outputChannels.tcuCurrentGear = getCurrentGear(); #endif } + +void TransmissionControllerBase::measureShiftTime(gear_e gear) { + m_shiftTime = true; + m_shiftTimer.reset(); + m_shiftTimeGear = gear; +} + +float TransmissionControllerBase::isShiftCompleted() { + if (m_shiftTime && m_shiftTimeGear == engine->module()->getCurrentGear()) { + m_shiftTime = false; + return m_shiftTimer.getElapsedSeconds(); + } else { + return 0; + } +} +#endif // EFI_TCU diff --git a/firmware/controllers/tcu.h b/firmware/controllers/tcu.h index efc49cba4a..c7538847fe 100644 --- a/firmware/controllers/tcu.h +++ b/firmware/controllers/tcu.h @@ -12,8 +12,14 @@ #include "persistent_configuration.h" #include "engine_configuration_generated_structures.h" #include "globalaccess.h" +#include "timer.h" +#if EFI_TCU class TransmissionControllerBase { +private: + Timer m_shiftTimer; + bool m_shiftTime; + gear_e m_shiftTimeGear; public: virtual void update(gear_e); virtual void init(); @@ -25,4 +31,7 @@ protected: gear_e currentGear = NEUTRAL; virtual gear_e setCurrentGear(gear_e); void postState(); + void measureShiftTime(gear_e); + float isShiftCompleted(); }; +#endif // EFI_TCU diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index e37d86f9a2..141a851aaa 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -1728,6 +1728,9 @@ uint8_t[8] tcu_tccTpsBins;;"TPS", 1, 0, 0, 255, 0 uint8_t[8] tcu_tccLockSpeed;;"MPH", 1, 0, 0, 255, 0 uint8_t[8] tcu_tccUnlockSpeed;;"MPH", 1, 0, 0, 255, 0 +uint8_t[8] tcu_32SpeedBins;;"KPH", 1, 0, 0, 255, 0 +uint8_t[8] tcu_32Vals;;"%", 1, 0, 0, 255, 0 + end_struct ! Pedal Position Sensor @@ -1752,6 +1755,7 @@ end_struct #define GAUGE_NAME_DESIRED_GEAR "Desired Gear" #define GAUGE_NAME_CURRENT_GEAR "Current Gear" #define GAUGE_NAME_ISS "Input Shaft Speed" +#define GAUGE_NAME_TC_RATIO "Torque Converter Ratio" #define GAUGE_NAME_TIMING_ADVANCE "timing" #define GAUGE_NAME_VVS "Vehicle Speed" diff --git a/firmware/tunerstudio/rusefi.input b/firmware/tunerstudio/rusefi.input index 0cef7768ad..0dcac8823b 100644 --- a/firmware/tunerstudio/rusefi.input +++ b/firmware/tunerstudio/rusefi.input @@ -684,6 +684,13 @@ curve = pcPerShiftCurve, "Transmission Line Pressure Control - Shift" lineLabel = "3->2%" lineLabel = "4->3%" +curve = 32Curve, "3-2 Shift Solenoid Percent by Speed" + columnLabel = "Speed", "%" + xAxis = 0, 200, 20 + yAxis = 0, 100, 10 + xBins = tcu_32SpeedBins, vehicleSpeedKph + yBins = tcu_32Vals + [TableEditor] ; table_id, map3d_id, "title", page @@ -1214,7 +1221,9 @@ gaugeCategory = Transmission currentGearGauge = tcuCurrentGear, @@GAUGE_NAME_CURRENT_GEAR@@, "gear", -1, 10, -1, -1, 10, 10, 0, 0 detectedGearGauge = detectedGear, @@GAUGE_NAME_DETECTED_GEAR@@, "gear", 0, @@GEARS_COUNT@@, 0, 0, @@GEARS_COUNT@@, @@GEARS_COUNT@@, 0, 0 speedToRpmRatioGauge = speedToRpmRatio, @@GAUGE_NAME_GEAR_RATIO@@, "", 0, 100, 0, 0, 100, 100, 4, 4 - ISSGauge = ISSValue, @@GAUGE_NAME_ISS@@, "RPM", 0, {rpmHardLimit + 2000}, 200, {cranking_rpm}, {rpmHardLimit - 500}, {rpmHardLimit}, 0, 0 + ISSGauge = ISSValue, @@GAUGE_NAME_ISS@@, "RPM", 0, {rpmHardLimit + 2000}, 200, {cranking_rpm}, {rpmHardLimit - 500}, {rpmHardLimit}, 0, 0 + tcRatioGauge = tcRatio, @@GAUGE_NAME_TC_RATIO@@, "", 0, 100, 0, 0, 100, 100, 4, 4 + shiftTimeGauge = lastShiftTime, "Last Shift Time", "S", 0, 2, 0, 0, 2, 2, 4, 4 gaugeCategory = Knock knock1Gauge = knock1, "Knock Cyl 1", "dBv", -60, 10, -60, -60, 10, 10, 0, 0 @@ -1549,6 +1558,7 @@ menuDialog = main subMenu = tccCurves, "TCC Lock/Unlock Speed" subMenu = pcPerGearDialog, "Line Pressure Per Gear" subMenu = pcPerShiftDialog, "Line Pressure Per Shift" + subMenu = 32Dialog, "3-2 Shift Solenoid Percent by Speed" menu = "&Sensors" # Base analog input settings @@ -3512,6 +3522,9 @@ dialog = tcuControls, "Transmission Settings" dialog = pcPerShiftDialog, "Line Pressure Per Shift" panel = pcPerShiftCurve + dialog = 32Dialog, "3-2 Shift Solenoid Percent by Speed" + panel = 32Curve + ;Boost Open Loop dialog = boostDialog, ""