Skip to content

Commit

Permalink
etb live data
Browse files Browse the repository at this point in the history
  • Loading branch information
mck1117 committed Dec 10, 2024
1 parent 20624db commit 939575a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 39 deletions.
4 changes: 2 additions & 2 deletions firmware/controllers/actuators/dc_motors.txt
Original file line number Diff line number Diff line change
@@ -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
30 changes: 20 additions & 10 deletions firmware/controllers/actuators/electronic_throttle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ expected<percent_t> 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;
Expand All @@ -277,9 +278,10 @@ expected<percent_t> 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) {
Expand All @@ -289,7 +291,8 @@ expected<percent_t> 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
Expand All @@ -305,7 +308,9 @@ expected<percent_t> 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;
Expand All @@ -316,7 +321,7 @@ expected<percent_t> EtbController::getSetpointEtb() {
maxPosition = std::min(maxPosition, 100.0f);

targetPosition = clampF(minPosition, targetPosition, maxPosition);
etbCurrentAdjustedTarget = targetPosition;
m_adjustedTarget = targetPosition;

return targetPosition;
}
Expand Down Expand Up @@ -346,13 +351,15 @@ percent_t EtbController2::getThrottleTrim(float rpm, percent_t targetPosition) c

expected<percent_t> 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<percent_t> EtbController::getClosedLoopAutotune(percent_t target, percent_t actualThrottlePosition) {
Expand Down Expand Up @@ -466,6 +473,7 @@ expected<percent_t> 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);
}
}
Expand All @@ -484,9 +492,11 @@ void EtbController::setOutput(expected<percent_t> 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;
}
}

Expand Down
35 changes: 19 additions & 16 deletions firmware/controllers/actuators/electronic_throttle.txt
Original file line number Diff line number Diff line change
@@ -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
22 changes: 11 additions & 11 deletions firmware/tunerstudio/tunerstudio.template.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 939575a

Please sign in to comment.