make the vss fliter parameter work again (#4056)

* vss has adjustable filter

* tooltip and validate

* s
This commit is contained in:
Matthew Kennedy 2022-04-09 06:00:19 -07:00 committed by GitHub
parent 7aedc7d029
commit e57a1b4f08
9 changed files with 42 additions and 31 deletions

View File

@ -13,16 +13,20 @@ static void freqSensorExtiCallback(void* arg, efitick_t nowNt) {
reinterpret_cast<FrequencySensor*>(arg)->onEdge(nowNt);
}
void FrequencySensor::initIfValid(brain_pin_e pin, SensorConverter &converter) {
void FrequencySensor::initIfValid(brain_pin_e pin, SensorConverter &converter, float filterParameter) {
if (!isBrainPinValid(pin)) {
return;
}
setFunction(converter);
init(pin);
Register();
}
void FrequencySensor::init(brain_pin_e pin) {
// Filter parameter less than 0.5 impossible, must always average over at least two events
if (filterParameter < 0.5f) {
filterParameter = 0.5f;
}
m_filter.configureLowpass(1, filterParameter);
setFunction(converter);
m_pin = pin;
#if EFI_PROD_CODE
@ -31,6 +35,8 @@ void FrequencySensor::init(brain_pin_e pin) {
PAL_EVENT_MODE_FALLING_EDGE,
freqSensorExtiCallback, reinterpret_cast<void*>(this));
#endif // EFI_PROD_CODE
Register();
}
void FrequencySensor::deInit() {

View File

@ -4,14 +4,11 @@
class FrequencySensor : public FunctionalSensor {
public:
FrequencySensor(SensorType type, efitick_t timeoutPeriod, float filterParameter)
FrequencySensor(SensorType type, efitick_t timeoutPeriod)
: FunctionalSensor(type, timeoutPeriod)
{
m_filter.configureLowpass(1, filterParameter);
}
{ }
void init(brain_pin_e pin);
void initIfValid(brain_pin_e pin, SensorConverter &converter);
void initIfValid(brain_pin_e pin, SensorConverter &converter, float filterParameter);
void deInit();
void onEdge(efitick_t nowNt);

View File

@ -7,8 +7,8 @@
#include "init.h"
#include "frequency_sensor.h"
static FrequencySensor auxSpeed1(SensorType::AuxSpeed1, MS2NT(500), 0.05f);
static FrequencySensor auxSpeed2(SensorType::AuxSpeed2, MS2NT(500), 0.05f);
static FrequencySensor auxSpeed1(SensorType::AuxSpeed1, MS2NT(500));
static FrequencySensor auxSpeed2(SensorType::AuxSpeed2, MS2NT(500));
static class : public SensorConverter {
public:
@ -23,8 +23,8 @@ public:
void initAuxSpeedSensors() {
auxSpeed1.initIfValid(engineConfiguration->auxSpeedSensorInputPin[0], converter);
auxSpeed2.initIfValid(engineConfiguration->auxSpeedSensorInputPin[1], converter);
auxSpeed1.initIfValid(engineConfiguration->auxSpeedSensorInputPin[0], converter, 0.05f);
auxSpeed2.initIfValid(engineConfiguration->auxSpeedSensorInputPin[1], converter, 0.05f);
}
void deinitAuxSpeedSensors() {

View File

@ -4,14 +4,14 @@
#include "frequency_sensor.h"
#include "flex_sensor.h"
// 0.01 means filter bandwidth of ~1hz with ~100hz sensor
static FrequencySensor flexSensor(SensorType::FuelEthanolPercent, MS2NT(500), 0.01f);
static FrequencySensor flexSensor(SensorType::FuelEthanolPercent, MS2NT(500));
static FlexConverter converter;
// https://rusefi.com/forum/viewtopic.php?p=37452&sid=829804c90d5b2e1fecd1b900cf1b1811#p37452
void initFlexSensor() {
flexSensor.initIfValid(engineConfiguration->flexSensorPin, converter);
// 0.01 means filter bandwidth of ~1hz with ~100hz sensor
flexSensor.initIfValid(engineConfiguration->flexSensorPin, converter, 0.01f);
}
void deInitFlexSensor() {

View File

@ -4,13 +4,13 @@
#include "frequency_sensor.h"
#include "turbocharger_speed_converter.h"
// Filter parameter of 0.01 filters over roughly 100 teeth
static FrequencySensor turbochargerSpeedSensor(SensorType::TurbochargerSpeed, MS2NT(500), 0.01f);
static FrequencySensor turbochargerSpeedSensor(SensorType::TurbochargerSpeed, MS2NT(500));
static TurbochargerSpeedConverter turbochargerSpeedConverter;
void initTurbochargerSpeedSensor() {
turbochargerSpeedSensor.initIfValid(engineConfiguration->turboSpeedSensorInputPin, turbochargerSpeedConverter);
// Filter parameter of 0.01 filters over roughly 100 teeth
turbochargerSpeedSensor.initIfValid(engineConfiguration->turboSpeedSensorInputPin, turbochargerSpeedConverter, 0.01f);
}
void deinitTurbochargerSpeedSensor() {

View File

@ -5,11 +5,19 @@
#include "vehicle_speed_converter.h"
// 0.05 filter parameter means averaging over ~20 sensor teeth
static FrequencySensor vehicleSpeedSensor(SensorType::VehicleSpeed, MS2NT(500), 0.05f);
static FrequencySensor vehicleSpeedSensor(SensorType::VehicleSpeed, MS2NT(500));
static VehicleSpeedConverter vehicleSpeedConverter;
void initVehicleSpeedSensor() {
vehicleSpeedSensor.initIfValid(engineConfiguration->vehicleSpeedSensorInputPin, vehicleSpeedConverter);
int parameter = engineConfiguration->vssFilterReciprocal;
if (parameter <= 0 || parameter > 200) {
parameter = 2;
}
float filterParameter = 1.0f / parameter;
vehicleSpeedSensor.initIfValid(engineConfiguration->vehicleSpeedSensorInputPin, vehicleSpeedConverter, filterParameter);
}
void deInitVehicleSpeedSensor() {

View File

@ -651,7 +651,8 @@ uint8_t knockRetardAggression;+Ignition timing to remove when a knock event occu
uint8_t knockRetardReapplyRate;+After a knock event, reapply timing at this rate.;"deg/s", 0.1, 0, 0, 10, 1
uint8_t knockRetardMaximum;+Maximum amount of knock retard.;"deg", 1, 0, 0, 30, 0
uint8_t unusedDtectionThreshold;;"", 1, 0, 0, 240, 0
uint8_t vssFilterReciprocal;Set this so your vehicle speed signal is responsive, but not noisy. Larger value give smoother but slower response.;"", 1, 0, 2, 200, 0
uint16_t autoscale vssGearRatio;Number of turns of your vehicle speed sensor per turn of the wheels. For example if your sensor is on the transmission output, enter your axle/differential ratio. If you are using a hub-mounted sensor, enter a value of 1.0.; "ratio", 0.001, 0, 0, 60, 3
uint8_t vssToothCount;Number of pulses output per revolution of the shaft where your VSS is mounted. For example, GM applications of the T56 output 17 pulses per revolution of the transmission output shaft.;"count", 1, 0, 1, 100, 0
brain_pin_e l9779_cs;
@ -1595,7 +1596,7 @@ uint16_t[FUEL_RPM_COUNT] injPhaseRpmBins;;"RPM", 1, 0, 0, 18000, 0
uint8_t[TCU_SOLENOID_COUNT x TCU_GEAR_COUNT] tcuSolenoidTable;;"onoff", 1, 0, 0, 1, 0
float vssFilterReciprocal;+Good example: number of tooth on wheel, For Can 10 is a good number.;"Hz", 1, 0, 2, 20, 2
float unused17440;;"", 1, 0, 0, 0, 0
uint16_t[FUEL_RPM_COUNT x FUEL_LOAD_COUNT] mapEstimateTable;;"kPa", {1/@@PACK_MULT_MAP_ESTIMATE@@}, 0, 0, 100, 2
uint16_t[FUEL_LOAD_COUNT] autoscale mapEstimateTpsBins;;"% TPS", {1/@@TPS_2_BYTE_PACKING_MULT@@}, 0, 0, 100, 1

View File

@ -3105,8 +3105,8 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00"
panel = startStopDialog
dialog = speedSensorAnalog, "Speed sensor"
field = "Input pin", vehicleSpeedSensorInputPin
field = "Filter Reciprocal", vssFilterReciprocal, { vehicleSpeedSensorInputPin != @@ADC_CHANNEL_NONE@@ }
field = "Input pin", vehicleSpeedSensorInputPin
field = "Filter parameter", vssFilterReciprocal, { vehicleSpeedSensorInputPin != @@ADC_CHANNEL_NONE@@ }
;
; We prefer quantities that users can actually measure or inspect without math, so we have

View File

@ -15,15 +15,14 @@ static IdentityFunction identityFunc;
class FrequencySensorTest : public ::testing::Test {
public:
FrequencySensorTest()
: dut(SensorType::FuelEthanolPercent, MS2NT(50), 0.5f)
: dut(SensorType::FuelEthanolPercent, MS2NT(50))
{
}
void SetUp() override {
// If somehow prodcode will be unwrapped for test it MAYBE! will fire with error.
// At least we must init FlexSensor somehow
dut.init(GPIO_INVALID);
dut.setFunction(identityFunc);
dut.initIfValid(GPIOA_0, identityFunc, 0.5f);
}
/*