ETB expAverage cleanup #489

This commit is contained in:
Matthew Kennedy 2024-09-17 18:49:13 -07:00
parent 05e5456830
commit 3a394dc83a
7 changed files with 3 additions and 79 deletions

View File

@ -206,8 +206,6 @@ bool EtbController::init(dc_function_e function, DcMotor *motor, pid_s *pidParam
void EtbController::reset() {
m_shouldResetPid = true;
m_dutyRocAverage.reset();
m_dutyAverage.reset();
etbTpsErrorCounter = 0;
etbPpsErrorCounter = 0;
}
@ -216,8 +214,7 @@ void EtbController::onConfigurationChange(pid_s* previousConfiguration) {
if (m_motor && !m_pid.isSame(previousConfiguration)) {
m_shouldResetPid = true;
}
m_dutyRocAverage.init(engineConfiguration->etbRocExpAverageLength);
m_dutyAverage.init(engineConfiguration->etbExpAverageLength);
doInitElectronicThrottle();
}
@ -799,9 +796,6 @@ void setBoschVNH2SP30Curve() {
void setDefaultEtbParameters() {
engineConfiguration->etbIdleThrottleRange = 5;
engineConfiguration->etbExpAverageLength = 50;
engineConfiguration->etbRocExpAverageLength = 50;
setLinearCurve(config->pedalToTpsPedalBins, /*from*/0, /*to*/100, 1);
setLinearCurve(config->pedalToTpsRpmBins, /*from*/0, /*to*/8000, 1);

View File

@ -13,7 +13,6 @@
#include "sensor.h"
#include "efi_pid.h"
#include "electronic_throttle_generated.h"
#include "exp_average.h"
/**
* Hard code ETB update speed.
@ -98,9 +97,6 @@ private:
return m_function == DC_Throttle1 || m_function == DC_Throttle2;
}
ExpAverage m_dutyRocAverage;
ExpAverage m_dutyAverage;
Timer m_jamDetectTimer;
// Pedal -> target map

View File

@ -1242,7 +1242,6 @@ tChargeMode_e tChargeMode;
int8_t launchFuelAdderPercent;;"%", 1, 0, 0, 100, 0
uint8_t autoscale etbJamTimeout;Time required to detect a stuck throttle.;"sec", 0.02, 0, 0, 5, 2
uint16_t etbExpAverageLength;By the way ETB PID runs at 500hz, length in 1/500 of second here.
int16_t coastingFuelCutRpmHigh;This sets the RPM above which fuel cut is active.;"rpm", 1, 0, 0, 5000, 0
int16_t coastingFuelCutRpmLow;This sets the RPM below which fuel cut is deactivated, this prevents jerking or issues transitioning to idle;"rpm", 1, 0, 0, 5000, 0
@ -1271,8 +1270,6 @@ float tChargeAirDecrLimit;Maximum allowed rate of decrease allowed for the estim
pid_s idleTimingPid
int16_t etbRocExpAverageLength;By the way ETB PID runs at 500hz, length in 1/500 of second here.
int16_t tpsAccelFractionPeriod;A delay in cycles between fuel-enrich. portions;"cycles", 1, 0, 0, 500, 0
float tpsAccelFractionDivisor;A fraction divisor: 1 or less = entire portion at once, or split into diminishing fractions;"coef", 1, 0, 0, 100, 2

View File

@ -4224,11 +4224,11 @@ dialog = tcuControls, "Transmission Settings"
field = "PWM Frequency", etbFreq
field = "Minimum ETB position", etbMinimumPosition
field = "Maximum ETB position", etbMaximumPosition
field = ""
field = "Jam detection error max", jamDetectThreshold
field = "Jam detection timeout period", etbJamTimeout
commandButton = "Temporarily disable jam detection", cmd_etb_disable_jam_detect
field = "Duty Averaging Length", etbExpAverageLength
field = "Rate of change Averaging Length", etbRocExpAverageLength
; we need the term about stepper idle in here, because there's a bug in TS that you can't have different visibility
; criteria for the same panel when used in multiple places
; todo: report bug to TS?

View File

@ -1,26 +0,0 @@
/**
* @file exp_average.h
*/
#pragma once
class ExpAverage {
public:
float average(float value) {
current = smoothingFactor * value + (1 - smoothingFactor) * current;
return current;
}
void init(int length) {
smoothingFactor = 2 / (length + 1.0);
}
void reset() {
current = 0;
smoothingFactor = 0.5;
}
private:
float current = 0;
float smoothingFactor = 0.5;
};

View File

@ -1,36 +0,0 @@
#include "pch.h"
#include "exp_average.h"
TEST(exp_average, length1) {
ExpAverage ea;
ea.init(1);
ASSERT_NEAR(ea.average(3), 3, EPS2D);
ASSERT_NEAR(ea.average(8), 8, EPS2D);
ASSERT_NEAR(ea.average(3), 3, EPS2D);
ASSERT_NEAR(ea.average(8), 8, EPS2D);
}
TEST(exp_average, length2) {
ExpAverage ea;
ea.init(2);
ASSERT_NEAR(ea.average(3), 2, EPS2D);
ASSERT_NEAR(ea.average(8), 6, EPS2D);
ASSERT_NEAR(ea.average(3), 4, EPS2D);
ASSERT_NEAR(ea.average(8), 6.6666, EPS2D);
}
TEST(exp_average, length12) {
ExpAverage ea;
ea.init(12);
ASSERT_NEAR(ea.average(3), 0.4615, EPS2D);
ASSERT_NEAR(ea.average(8), 1.6213, EPS2D);
ASSERT_NEAR(ea.average(3), 1.8334, EPS2D);
ASSERT_NEAR(ea.average(8), 2.7821, EPS2D);
for (int i = 0; i < 300; i++) {
ea.average(3);
ea.average(8);
}
ASSERT_NEAR(ea.average(3), 5.2916, EPS2D);
}

View File

@ -1,7 +1,6 @@
CPPSRC += $(PROJECT_DIR)/../unit_tests/tests/util/test_buffered_writer.cpp \
$(PROJECT_DIR)/../unit_tests/tests/util/test_exp_average.cpp \
$(PROJECT_DIR)/../unit_tests/tests/util/test_hash.cpp \
INCDIR += $(PROJECT_DIR)/controllers/system