From 939575a730010c2825238297a3db0c090fd7c7ef Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 9 Dec 2024 19:58:39 -0800 Subject: [PATCH] etb live data --- firmware/controllers/actuators/dc_motors.txt | 4 +-- .../actuators/electronic_throttle.cpp | 30 ++++++++++------ .../actuators/electronic_throttle.txt | 35 ++++++++++--------- firmware/tunerstudio/tunerstudio.template.ini | 22 ++++++------ 4 files changed, 52 insertions(+), 39 deletions(-) diff --git a/firmware/controllers/actuators/dc_motors.txt b/firmware/controllers/actuators/dc_motors.txt index 52659611b5..54c9a0196a 100644 --- a/firmware/controllers/actuators/dc_motors.txt +++ b/firmware/controllers/actuators/dc_motors.txt @@ -1,8 +1,8 @@ ! units,scale,offset,min,max,digits struct_no_prefix dc_motors_s - float dcOutput0;"DC: output0";"per", 1, 0, 0, 10, 2 - uint8_t isEnabled0_int;"DC: en0";"per", 1, 0, 0, 10, 2 + float dcOutput0;"DC: output0";"%", 1, 0, 0, 10, 2 + uint8_t isEnabled0_int;"DC: en0";"%", 1, 0, 0, 10, 2 bit isEnabled0 end_struct \ No newline at end of file diff --git a/firmware/controllers/actuators/electronic_throttle.cpp b/firmware/controllers/actuators/electronic_throttle.cpp index 8e5b08be86..32f33a03c6 100644 --- a/firmware/controllers/actuators/electronic_throttle.cpp +++ b/firmware/controllers/actuators/electronic_throttle.cpp @@ -268,7 +268,8 @@ expected EtbController::getSetpointEtb() { float sanitizedPedal = clampF(0, pedalPosition.value_or(0), 100); float rpm = Sensor::getOrZero(SensorType::Rpm); - etbCurrentTarget = m_pedalMap->getValue(rpm, sanitizedPedal); + float baseTarget = m_pedalMap->getValue(rpm, sanitizedPedal); + m_baseTarget = baseTarget; percent_t etbIdlePosition = clampF(0, m_idlePosition, 100); percent_t etbIdleAddition = PERCENT_DIV * engineConfiguration->etbIdleThrottleRange * etbIdlePosition; @@ -277,9 +278,10 @@ expected EtbController::getSetpointEtb() { // [0, 100] -> [idle, 100] // 0% target from table -> idle position as target // 100% target from table -> 100% target position - idlePosition = interpolateClamped(0, etbIdleAddition, 100, 100, etbCurrentTarget); + percent_t targetPosition = interpolateClamped(0, etbIdleAddition, 100, 100, baseTarget); - percent_t targetPosition = idlePosition + getLuaAdjustment(); + // Adjust up/down by Lua adjustment + targetPosition += getLuaAdjustment(); #if EFI_ANTILAG_SYSTEM if (engine->antilagController.isAntilagCondition) { @@ -289,7 +291,8 @@ expected EtbController::getSetpointEtb() { // Apply any adjustment that this throttle alone needs // Clamped to +-10 to prevent anything too wild - trim = clampF(-10, getThrottleTrim(rpm, targetPosition), 10); + float trim = clampF(-10, getThrottleTrim(rpm, targetPosition), 10); + m_trim = trim; targetPosition += trim; // Clamp before rev limiter to avoid ineffective rev limit due to crazy out of range position target @@ -305,7 +308,9 @@ expected EtbController::getSetpointEtb() { targetPosition = interpolateClamped(etbRpmLimit, targetPosition, fullyLimitedRpm, 0, rpm); // rev limit active if the position was changed by rev limiter - etbRevLimitActive = std::abs(targetPosition - targetPositionBefore) > 0.1f; + revLimitActive = std::abs(targetPosition - targetPositionBefore) > 0.1f; + } else { + revLimitActive = false; } float minPosition = engineConfiguration->etbMinimumPosition; @@ -316,7 +321,7 @@ expected EtbController::getSetpointEtb() { maxPosition = std::min(maxPosition, 100.0f); targetPosition = clampF(minPosition, targetPosition, maxPosition); - etbCurrentAdjustedTarget = targetPosition; + m_adjustedTarget = targetPosition; return targetPosition; } @@ -346,13 +351,15 @@ percent_t EtbController2::getThrottleTrim(float rpm, percent_t targetPosition) c expected EtbController::getOpenLoop(percent_t target) { // Don't apply open loop for wastegate/idle valve, only real ETB + float feedForward = 0; + if (m_function != DC_Wastegate) { - etbFeedForward = interpolate2d(target, config->etbBiasBins, config->etbBiasValues); - } else { - etbFeedForward = 0; + feedForward = interpolate2d(target, config->etbBiasBins, config->etbBiasValues); } - return etbFeedForward; + m_feedForward = feedForward; + + return feedForward; } expected EtbController::getClosedLoopAutotune(percent_t target, percent_t actualThrottlePosition) { @@ -466,6 +473,7 @@ expected EtbController::getClosedLoop(percent_t target, percent_t obs checkJam(target, observation); // Normal case - use PID to compute closed loop part + m_error = target - observation; return m_pid.getOutput(target, observation, etbPeriodSeconds); } } @@ -484,9 +492,11 @@ void EtbController::setOutput(expected outputValue) { && !engineConfiguration->pauseEtbControl)) { m_motor->enable(); m_motor->set(ETB_PERCENT_TO_DUTY(outputValue.Value)); + m_outputDuty = outputValue.Value; } else { // Otherwise disable the motor. m_motor->disable("setOutput"); + m_outputDuty = 0; } } diff --git a/firmware/controllers/actuators/electronic_throttle.txt b/firmware/controllers/actuators/electronic_throttle.txt index 50c5a0d033..a4855ed747 100644 --- a/firmware/controllers/actuators/electronic_throttle.txt +++ b/firmware/controllers/actuators/electronic_throttle.txt @@ -1,28 +1,31 @@ ! units,scale,offset,min,max,digits struct_no_prefix electronic_throttle_s - float idlePosition;"ETB: idlePosition";"per", 1, 0, 0, 10, 2 - float trim;"ETB: trim" - float luaAdjustment;"ETB: luaAdjustment";"per", 1, 0, 0, 3, 2 + float m_wastegatePosition;"DC: wastegatePosition";"%", 1, 0, 0, 3, 2 - float m_wastegatePosition;"DC: wastegatePosition";"per", 1, 0, 0, 3, 2 + ! Targeting + int16_t autoscale m_baseTarget;Base target;"%", 0.01, 0, -100, 100, 2 + int16_t autoscale m_trim;"Trim";"%", 0.01, 0, -100, 100, 2 + float luaAdjustment;"Lua adjustment";"%", 1, 0, -20, 20, 1 + int16_t autoscale m_adjustedTarget;Adjusted target;"%", 0.01, 0, -100, 100, 2 + ! Open loop + int16_t autoscale m_feedForward;Feed forward;"%", 0.01, 0, -100, 100, 2 - custom percent_t 4 scalar, F32, @OFFSET@, "", 1, 0, 0, 100, 2 + ! Closed loop + int16_t autoscale m_error;Error;"%", 0.01, 0, -100, 100, 2 - percent_t etbFeedForward - float etbIntegralError;;"", 1, 0, -10000, 10000, 3 - float etbCurrentTarget;;"%", 1, 0, -10000, 10000, 3 - float etbCurrentAdjustedTarget;;"%", 1, 0, -10000, 10000, 3 + ! Output + uint8_t autoscale m_outputDuty;Duty cycle;"%", 0.5, 0, 0, 100, 1 - bit etbRevLimitActive - bit jamDetected + ! Error detection and status + bit revLimitActive;Rev limit active + bit jamDetected;Jam detected - uint16_t etbTpsErrorCounter;"ETB TPS error counter";"count", 1, 0, 0,3, 0 - uint16_t etbPpsErrorCounter;"ETB pedal error counter";"count", 1, 0, 0,3, 0 + uint16_t etbTpsErrorCounter;"TPS error counter";"count", 1, 0, 0,3, 0 + uint16_t etbPpsErrorCounter;"Pedal error counter";"count", 1, 0, 0,3, 0 - int8_t etbErrorCode - - uint16_t autoscale jamTimer;ETB jam timer;"sec", 0.01, 0, 0, 100, 2 + uint16_t autoscale jamTimer;Jam timer;"sec", 0.01, 0, 0, 100, 2 + int8_t etbErrorCode;Error code end_struct diff --git a/firmware/tunerstudio/tunerstudio.template.ini b/firmware/tunerstudio/tunerstudio.template.ini index facd4f67fe..04ac3392d6 100644 --- a/firmware/tunerstudio/tunerstudio.template.ini +++ b/firmware/tunerstudio/tunerstudio.template.ini @@ -1263,13 +1263,12 @@ gaugeCategory = "Boost Control" boostStatus_resetCounterGauge = boostStatus_resetCounter,"Boost PID resetCounter", "", -10000.0,10000.0, -10000.0,10000.0, -10000.0,10000.0, 0,0 gaugeCategory = "ETB more" - idlePositionGauge = idlePosition,"ETB: idlePosition", "per", 0.0,10.0, 0.0,10.0, 0.0,10.0, 2,2 - luaAdjustmentGauge = luaAdjustment,"ETB: luaAdjustment", "per", 0.0,3.0, 0.0,3.0, 0.0,3.0, 2,2 - m_wastegatePositionGauge = m_wastegatePosition,"DC: wastegatePosition", "per", 0.0,3.0, 0.0,3.0, 0.0,3.0, 2,2 - etbTpsErrorCounterGauge = etbTpsErrorCounter,"ETB TPS error counter", "count", 0.0,3.0, 0.0,3.0, 0.0,3.0, 0,0 - etbPpsErrorCounterGauge = etbPpsErrorCounter,"ETB pedal error counter", "count", 0.0,3.0, 0.0,3.0, 0.0,3.0, 0,0 - dcOutput0Gauge = dcOutput0,"DC: output0", "per", 0.0,10.0, 0.0,10.0, 0.0,10.0, 2,2 - isEnabled0_intGauge = isEnabled0_int,"DC: en0", "per", 0.0,10.0, 0.0,10.0, 0.0,10.0, 2,2 + luaAdjustmentGauge = ETB_1_luaAdjustment,"ETB: luaAdjustment", "%", 0.0,3.0, 0.0,3.0, 0.0,3.0, 2,2 + m_wastegatePositionGauge = ETB_1_m_wastegatePosition,"DC: wastegatePosition", "%", 0.0,3.0, 0.0,3.0, 0.0,3.0, 2,2 + etbTpsErrorCounterGauge = ETB_1_etbTpsErrorCounter,"ETB TPS error counter", "count", 0.0,3.0, 0.0,3.0, 0.0,3.0, 0,0 + etbPpsErrorCounterGauge = ETB_1_etbPpsErrorCounter,"ETB pedal error counter", "count", 0.0,3.0, 0.0,3.0, 0.0,3.0, 0,0 + dcOutput0Gauge = dcOutput0,"DC: output0", "%", 0.0,10.0, 0.0,10.0, 0.0,10.0, 2,2 + isEnabled0_intGauge = isEnabled0_int,"DC: en0", "%", 0.0,10.0, 0.0,10.0, 0.0,10.0, 2,2 value0Gauge = value0,"ETB: SENT value0", "value", 0.0,3.0, 0.0,3.0, 0.0,3.0, 0,0 value1Gauge = value1,"ETB: SENT value1", "value", 0.0,3.0, 0.0,3.0, 0.0,3.0, 0,0 errorRateGauge = errorRate,"ETB: SENT error rate", "ratio", 0.0,3.0, 0.0,3.0, 0.0,3.0, 2,2 @@ -1489,9 +1488,9 @@ gaugeCategory = Throttle Body (incl. ETB) TPSGauge = TPSValue, "Throttle position", "%", 0, 100, 0, 0, 100, 100, 1, 1 TPS2Gauge = TPS2Value, "Throttle position #2", "%", 0, 100, 0, 0, 100, 100, 1, 1 - etbTargetGauge = etbTarget, @@GAUGE_NAME_ETB_TARGET@@, "%", 0, 100, 0, 0, 100, 100, 1, 1 - etbErrorGauge = etbStatus_error, @@GAUGE_NAME_ETB_ERROR@@, "%", -20, 20, -10, -5, 5, 10, 2, 0 - etbDutyCycleGauge = etb1DutyCycle, @@GAUGE_NAME_ETB_DUTY@@, "%", -100, 100, -75, -50, 50, 75, 0, 0 + etbTargetGauge = ETB_1_m_adjustedTarget, @@GAUGE_NAME_ETB_TARGET@@, "%", 0, 100, 0, 0, 100, 100, 1, 1 + etbErrorGauge = ETB_1_m_error, @@GAUGE_NAME_ETB_ERROR@@, "%", -20, 20, -10, -5, 5, 10, 2, 0 + etbDutyCycleGauge = ETB_1_m_outputDuty, @@GAUGE_NAME_ETB_DUTY@@, "%", -100, 100, -75, -50, 50, 75, 0, 0 gaugeCategory = Sensors - Raw rawTps1PrimaryGauge = rawTps1Primary, "Raw TPS 1 Primary", "V", 0, 5, 0, 0, 5, 5, 3, 0 @@ -1617,7 +1616,8 @@ gaugeCategory = GPPWM Outputs indicator = { isTriggerError}, "Trigger OK", "Trigger ERR", white, black, red, black indicator = { fuelCutReason != 0 }, "Injection OK", { Fuel cut: bitStringValue(fuelIgnCutCodeList, fuelCutReason)}, white, black, yellow, black indicator = { sparkCutReason != 0 }, "Ignition OK", { Ign cut: bitStringValue(fuelIgnCutCodeList, sparkCutReason)}, white, black, yellow, black - indicator = { etbErrorCode != 0 }, "ETB OK", { ETB: bitStringValue(etbCutCodeList, etbErrorCode)}, white, black, yellow, black + indicator = { ETB_1_etbErrorCode != 0 }, "ETB 1 OK", { ETB 1: bitStringValue(etbCutCodeList, ETB_1_etbErrorCode)}, white, black, yellow, black + indicator = { ETB_2_etbErrorCode != 0 }, "ETB 2 OK", { ETB 2: bitStringValue(etbCutCodeList, ETB_2_etbErrorCode)}, white, black, yellow, black ; this is required so that the "config error" feature works in TS ; DO NOT CHANGE THIS LINE - TS is looking for an indicator with particular text/styling