vss and flex are filtered (#3839)
* vss and flex are filtered * turbo * freq sensor test
This commit is contained in:
parent
9de9517262
commit
d65652d7bc
|
@ -39,5 +39,7 @@ void FrequencySensor::deInit() {
|
|||
void FrequencySensor::onEdge(efitick_t nowNt) {
|
||||
float frequency = 1 / m_edgeTimer.getElapsedSecondsAndReset(nowNt);
|
||||
|
||||
frequency = m_filter.filter(frequency);
|
||||
|
||||
postRawValue(frequency, nowNt);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
#include "functional_sensor.h"
|
||||
#include "timer.h"
|
||||
#include "biquad.h"
|
||||
|
||||
class FrequencySensor : public FunctionalSensor {
|
||||
public:
|
||||
FrequencySensor(SensorType type, efitick_t timeoutPeriod)
|
||||
: FunctionalSensor(type, timeoutPeriod) { }
|
||||
FrequencySensor(SensorType type, efitick_t timeoutPeriod, float filterParameter)
|
||||
: FunctionalSensor(type, timeoutPeriod)
|
||||
{
|
||||
m_filter.configureLowpass(1, filterParameter);
|
||||
}
|
||||
|
||||
void init(brain_pin_e pin);
|
||||
void deInit();
|
||||
|
@ -14,4 +18,6 @@ public:
|
|||
private:
|
||||
Timer m_edgeTimer;
|
||||
brain_pin_e m_pin = GPIO_UNASSIGNED;
|
||||
|
||||
Biquad m_filter;
|
||||
};
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
#include "frequency_sensor.h"
|
||||
#include "flex_sensor.h"
|
||||
|
||||
static FrequencySensor flexSensor(SensorType::FuelEthanolPercent, MS2NT(500));
|
||||
// 0.01 means filter bandwidth of ~1hz with ~100hz sensor
|
||||
static FrequencySensor flexSensor(SensorType::FuelEthanolPercent, MS2NT(500), 0.01f);
|
||||
static FlexConverter converter;
|
||||
|
||||
// https://rusefi.com/forum/viewtopic.php?p=37452&sid=829804c90d5b2e1fecd1b900cf1b1811#p37452
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
#include "frequency_sensor.h"
|
||||
#include "turbocharger_speed_converter.h"
|
||||
|
||||
static FrequencySensor turbochargerSpeedSensor(SensorType::TurbochargerSpeed, MS2NT(500));
|
||||
// Filter parameter of 0.01 filters over roughly 100 teeth
|
||||
static FrequencySensor turbochargerSpeedSensor(SensorType::TurbochargerSpeed, MS2NT(500), 0.01f);
|
||||
static TurbochargerSpeedConverter turbochargerSpeedConverter;
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
#include "frequency_sensor.h"
|
||||
#include "vehicle_speed_converter.h"
|
||||
|
||||
static FrequencySensor vehicleSpeedSensor(SensorType::VehicleSpeed, MS2NT(500));
|
||||
// 0.05 filter parameter means averaging over ~20 sensor teeth
|
||||
static FrequencySensor vehicleSpeedSensor(SensorType::VehicleSpeed, MS2NT(500), 0.05f);
|
||||
static VehicleSpeedConverter vehicleSpeedConverter;
|
||||
|
||||
void initVehicleSpeedSensor() {
|
||||
|
|
|
@ -15,7 +15,7 @@ static IdentityFunction identityFunc;
|
|||
class FrequencySensorTest : public ::testing::Test {
|
||||
public:
|
||||
FrequencySensorTest()
|
||||
: dut(SensorType::FuelEthanolPercent, MS2NT(50))
|
||||
: dut(SensorType::FuelEthanolPercent, MS2NT(50), 0.5f)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ public:
|
|||
* (as Sensor works by falling edge)
|
||||
*/
|
||||
void generatePwm(EngineTestHelper ð, float freqHz) {
|
||||
constexpr auto periods = 50;
|
||||
constexpr auto periods = 1000;
|
||||
auto period = (1 / freqHz);
|
||||
|
||||
std::cout << "PERIOD: " << period << std::endl;
|
||||
|
@ -65,6 +65,6 @@ TEST_F(FrequencySensorTest, testValidWithPwm) {
|
|||
{
|
||||
auto s = Sensor::get(SensorType::FuelEthanolPercent);
|
||||
EXPECT_TRUE(s.Valid);
|
||||
EXPECT_FLOAT_EQ(s.Value, 10);
|
||||
EXPECT_NEAR(s.Value, 10, 1e-3);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue