mirror of https://github.com/rusefi/rusefi-1.git
Implement flex sensor (#2189)
* config & ui * stub sensor * stub init * output channel, gauge, SD log * linky linky * fix * add sensor & init * clamp * update comment * filter the resultant signal * changelog Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
parent
f804aaf60f
commit
20a967edf1
|
@ -30,6 +30,7 @@ All notable user-facing or behavior-altering changes will be documented in this
|
|||
### Breaking Changes
|
||||
|
||||
### Added
|
||||
- Basic fueling-only flex fuel implementation. Automatic adjustment of stoichiometric ratio based on ethanol content, compatible with the common GM/Continental 50-150hz flex fuel sensor 🎉 🎉 🎉
|
||||
|
||||
### Fixed
|
||||
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
#include "engine.h"
|
||||
#include "digital_input_exti.h"
|
||||
#include "flex_sensor.h"
|
||||
|
||||
EXTERN_ENGINE;
|
||||
|
||||
static void flexExtiCallback(void* arg) {
|
||||
auto inst = reinterpret_cast<FlexFuelSensor*>(arg);
|
||||
inst->onEdge(getTimeNowNt());
|
||||
}
|
||||
|
||||
void FlexFuelSensor::init(brain_pin_e pin) {
|
||||
#if EFI_PROD_CODE
|
||||
// todo: refactor https://github.com/rusefi/rusefi/issues/2123
|
||||
efiExtiEnablePin("flex", pin,
|
||||
PAL_EVENT_MODE_FALLING_EDGE,
|
||||
flexExtiCallback, reinterpret_cast<void*>(this));
|
||||
#endif // EFI_PROD_CODE
|
||||
|
||||
// Update rate is 50-150hz, so this actually filters at 0.5-1.5hz -3db depending on E%, which is ok
|
||||
m_filter.configureLowpass(100, 1);
|
||||
}
|
||||
|
||||
FlexFuelSensor::FlexFuelSensor()
|
||||
// this long timeout is ok, ethanol content isn't going to change quickly
|
||||
: StoredValueSensor(SensorType::FuelEthanolPercent, MS2NT(500))
|
||||
{
|
||||
}
|
||||
|
||||
void FlexFuelSensor::onEdge(efitick_t nowNt) {
|
||||
float frequency = 1 / m_edgeTimer.getElapsedSecondsAndReset(nowNt);
|
||||
|
||||
// Sensor should only report 50-150hz, significantly outside that range indicates a problem
|
||||
// it changes to 200hz+ to indicate methanol "contamination"
|
||||
if (frequency > 45 && frequency < 155) {
|
||||
float flexPct = clampF(0, frequency - 50, 100);
|
||||
|
||||
setValidValue(m_filter.filter(flexPct), nowNt);
|
||||
}
|
||||
|
||||
// no explicit invalidation, we can tolerate a somewhat dodgy connection
|
||||
// so long as we get a valid interval every now and then
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
#include "stored_value_sensor.h"
|
||||
#include "timer.h"
|
||||
#include "rusefi_hw_enums.h"
|
||||
#include "biquad.h"
|
||||
|
||||
class FlexFuelSensor : public StoredValueSensor {
|
||||
public:
|
||||
FlexFuelSensor();
|
||||
|
||||
void init(brain_pin_e pin);
|
||||
|
||||
void onEdge(efitick_t nowNt);
|
||||
|
||||
void showInfo(Logging* /*logger*/, const char* /*sensorName*/) const override { }
|
||||
|
||||
private:
|
||||
Timer m_edgeTimer;
|
||||
|
||||
Biquad m_filter;
|
||||
};
|
|
@ -14,6 +14,7 @@ CONTROLLERS_SENSORS_SRC_CPP = $(PROJECT_DIR)/controllers/sensors/thermistors.cp
|
|||
$(PROJECT_DIR)/controllers/sensors/functional_sensor.cpp \
|
||||
$(PROJECT_DIR)/controllers/sensors/redundant_sensor.cpp \
|
||||
$(PROJECT_DIR)/controllers/sensors/AemXSeriesLambda.cpp \
|
||||
$(PROJECT_DIR)/cotnrollers/sensors/flex_sensor.cpp \
|
||||
$(PROJECT_DIR)/controllers/sensors/software_knock.cpp \
|
||||
$(PROJECT_DIR)/controllers/sensors/converters/linear_func.cpp \
|
||||
$(PROJECT_DIR)/controllers/sensors/converters/resistance_func.cpp \
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
#include "init.h"
|
||||
#include "engine.h"
|
||||
#include "flex_sensor.h"
|
||||
|
||||
EXTERN_ENGINE;
|
||||
|
||||
static FlexFuelSensor flexSensor;
|
||||
|
||||
// https://rusefi.com/forum/viewtopic.php?p=37452&sid=829804c90d5b2e1fecd1b900cf1b1811#p37452
|
||||
|
||||
void initFlexSensor(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
|
||||
|
@ -13,5 +16,6 @@ void initFlexSensor(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
|
|||
return;
|
||||
}
|
||||
|
||||
// TODO: init sensor
|
||||
flexSensor.init(pin);
|
||||
flexSensor.Register();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue