2020-05-06 18:00:40 -07:00
|
|
|
#pragma once
|
|
|
|
|
2021-01-10 05:10:49 -08:00
|
|
|
#include "sensor.h"
|
2020-05-06 18:00:40 -07:00
|
|
|
|
|
|
|
class ClosedLoopFuelCellBase {
|
|
|
|
public:
|
|
|
|
// Update the cell's internal state - adjusting fuel up/down as appropriate
|
2021-11-16 01:15:29 -08:00
|
|
|
void update(float lambdaDeadband, bool ignoreErrorMagnitude);
|
2020-05-06 18:00:40 -07:00
|
|
|
|
|
|
|
// Get the current adjustment amount, without altering internal state.
|
|
|
|
float getAdjustment() const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Helpers - virtual for mocking
|
2021-11-16 01:15:29 -08:00
|
|
|
virtual float getLambdaError() const = 0;
|
2020-05-06 18:00:40 -07:00
|
|
|
virtual float getMaxAdjustment() const = 0;
|
|
|
|
virtual float getMinAdjustment() const = 0;
|
|
|
|
virtual float getIntegratorGain() const = 0;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Current fueling adjustment.
|
|
|
|
// 0 = no adjustment.
|
|
|
|
// 0.1 = add 10% fuel.
|
|
|
|
float m_adjustment = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct stft_cell_cfg_s;
|
|
|
|
|
|
|
|
class ClosedLoopFuelCellImpl final : public ClosedLoopFuelCellBase {
|
|
|
|
public:
|
2021-01-10 05:10:49 -08:00
|
|
|
void configure(const stft_cell_cfg_s* configuration, SensorType lambdaSensor) {
|
2020-05-06 18:00:40 -07:00
|
|
|
m_config = configuration;
|
2021-01-10 05:10:49 -08:00
|
|
|
m_lambdaSensor = lambdaSensor;
|
2020-05-06 18:00:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const stft_cell_cfg_s *m_config = nullptr;
|
2021-01-10 05:10:49 -08:00
|
|
|
SensorType m_lambdaSensor = SensorType::Invalid;
|
2020-05-06 18:00:40 -07:00
|
|
|
|
|
|
|
protected:
|
2021-11-16 01:15:29 -08:00
|
|
|
float getLambdaError() const override;
|
2020-05-06 18:00:40 -07:00
|
|
|
float getMaxAdjustment() const override;
|
|
|
|
float getMinAdjustment() const override;
|
|
|
|
float getIntegratorGain() const override;
|
|
|
|
};
|