wideband/firmware/lambda_conversion.cpp

94 lines
2.2 KiB
C++
Raw Normal View History

2020-11-28 03:04:04 -08:00
#include "lambda_conversion.h"
2020-11-01 01:17:13 -08:00
#include "sampling.h"
#include "port.h"
2020-11-01 01:17:13 -08:00
static float GetPhiLsu49(float pumpCurrent)
2020-11-01 01:17:13 -08:00
{
2020-12-12 00:29:48 -08:00
// Maximum lambda ~2
if (pumpCurrent > 1.11f)
{
return 0.5f;
}
2020-12-13 14:49:58 -08:00
// Minimum lambda ~0.5
if (pumpCurrent < -3.5f)
2020-12-12 00:29:48 -08:00
{
2020-12-13 14:49:58 -08:00
return 1 / 0.5f;
2020-12-12 00:29:48 -08:00
}
2020-11-01 01:17:13 -08:00
// This estimation is accurate within 0.5% from 0.8 to 1.0, and 0.01% from 1 to 1.2 lambda when compared to the lookup table in the Bosch datasheet
2020-11-01 01:26:02 -08:00
// This error is less than half of the claimed accuracy of the sensor itself
2020-11-02 01:28:30 -08:00
float gain = pumpCurrent < 0 ? -0.28299f : -0.44817f;
2020-11-01 01:17:13 -08:00
return gain * pumpCurrent + 0.99559f;
}
static float GetPhiLsu42(float pumpCurrent)
{
// Maximum lambda ~2
if (pumpCurrent > 1.19f)
{
return 0.5f;
}
// Minimum lambda ~0.7
if (pumpCurrent < -1.85f)
{
return 1 / 0.7f;
}
// This estimation is accurate within 0.5% from 0.8 to 1.0, and 0.01% from 1 to 1.2 lambda when compared to the lookup table in the Bosch datasheet
// This error is less than half of the claimed accuracy of the sensor itself
float gain = pumpCurrent < 0 ? -0.23505f : -0.41441f;
return gain * pumpCurrent + 0.99153f;
}
2023-11-13 15:02:13 -08:00
static float GetPhiLsuAdv(float pumpCurrent)
{
2023-11-13 15:02:13 -08:00
// Maximum lambda 2.434
if (pumpCurrent > 0.759f)
{
return 1 / 2.434f;
}
// Minimum lambda is 0.65
if (pumpCurrent < -1.108)
{
return 1 / 0.65f;
}
if (pumpCurrent < 0)
{
// rich
// Accurate with 0.005 lambda from 0.65-1
return (0.0379 * pumpCurrent - 0.4496) * pumpCurrent + 0.9902;
}
else
{
// lean
return (0.1059 * pumpCurrent - 0.8368) * pumpCurrent + 0.9859;
}
}
static float GetPhi(float pumpCurrent) {
switch (GetSensorType()) {
case SensorType::LSU49:
return GetPhiLsu49(pumpCurrent);
case SensorType::LSU42:
return GetPhiLsu42(pumpCurrent);
case SensorType::LSUADV:
return GetPhiLsuAdv(pumpCurrent);
}
return 1;
}
float GetLambda(int ch)
2020-11-01 01:17:13 -08:00
{
float pumpCurrent = GetSampler(ch).GetPumpNominalCurrent();
2020-11-01 01:17:13 -08:00
// Lambda is reciprocal of phi
return 1 / GetPhi(pumpCurrent);
}