fix vss/iss filter parameter validation (#4114)

* fix filter parameter validation

* use values that don't get clipped
This commit is contained in:
Matthew Kennedy 2022-04-27 19:29:51 -07:00 committed by GitHub
parent f773e4a10b
commit c3fb211d6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 10 deletions

View File

@ -18,9 +18,10 @@ void FrequencySensor::initIfValid(brain_pin_e pin, SensorConverter &converter, f
return; return;
} }
// Filter parameter less than 0.5 impossible, must always average over at least two events // Filter parameter greater than or equal to 0.5 impossible as it causes filter instability, clamp
if (filterParameter < 0.5f) { // far under that value.
filterParameter = 0.5f; if (filterParameter > 0.35f) {
filterParameter = 0.35f;
} }
m_filter.configureLowpass(1, filterParameter); m_filter.configureLowpass(1, filterParameter);

View File

@ -10,8 +10,8 @@ static InputShaftSpeedConverter inputSpeedConverter;
void initInputShaftSpeedSensor() { void initInputShaftSpeedSensor() {
int parameter = engineConfiguration->issFilterReciprocal; int parameter = engineConfiguration->issFilterReciprocal;
if (parameter <= 0 || parameter > 200) { if (parameter < 3 || parameter > 200) {
parameter = 2; parameter = 3;
} }
float filterParameter = 1.0f / parameter; float filterParameter = 1.0f / parameter;

View File

@ -11,8 +11,8 @@ static VehicleSpeedConverter vehicleSpeedConverter;
void initVehicleSpeedSensor() { void initVehicleSpeedSensor() {
int parameter = engineConfiguration->vssFilterReciprocal; int parameter = engineConfiguration->vssFilterReciprocal;
if (parameter <= 0 || parameter > 200) { if (parameter < 3 || parameter > 200) {
parameter = 2; parameter = 3;
} }
float filterParameter = 1.0f / parameter; float filterParameter = 1.0f / parameter;

View File

@ -30,7 +30,7 @@ static float getNorm(float K, float Q) {
} }
void Biquad::configureBandpass(float samplingFrequency, float centerFrequency, float Q) { void Biquad::configureBandpass(float samplingFrequency, float centerFrequency, float Q) {
efiAssertVoid(OBD_PCM_Processor_Fault, samplingFrequency >= 2 * centerFrequency, "Invalid biquad parameters"); efiAssertVoid(OBD_PCM_Processor_Fault, samplingFrequency >= 2.5f * centerFrequency, "Invalid biquad parameters");
float K = getK(samplingFrequency, centerFrequency); float K = getK(samplingFrequency, centerFrequency);
float norm = getNorm(K, Q); float norm = getNorm(K, Q);
@ -43,7 +43,7 @@ void Biquad::configureBandpass(float samplingFrequency, float centerFrequency, f
} }
void Biquad::configureLowpass(float samplingFrequency, float cutoffFrequency, float Q) { void Biquad::configureLowpass(float samplingFrequency, float cutoffFrequency, float Q) {
efiAssertVoid(OBD_PCM_Processor_Fault, samplingFrequency >= 2 * cutoffFrequency, "Invalid biquad parameters"); efiAssertVoid(OBD_PCM_Processor_Fault, samplingFrequency >= 2.5f * cutoffFrequency, "Invalid biquad parameters");
float K = getK(samplingFrequency, cutoffFrequency); float K = getK(samplingFrequency, cutoffFrequency);
float norm = getNorm(K, Q); float norm = getNorm(K, Q);

View File

@ -22,7 +22,7 @@ public:
void SetUp() override { void SetUp() override {
// If somehow prodcode will be unwrapped for test it MAYBE! will fire with error. // If somehow prodcode will be unwrapped for test it MAYBE! will fire with error.
// At least we must init FlexSensor somehow // At least we must init FlexSensor somehow
dut.initIfValid(GPIOA_0, identityFunc, 0.5f); dut.initIfValid(GPIOA_0, identityFunc, 0.1f);
} }
/* /*