extract heater class declaration

This commit is contained in:
Matthew Kennedy 2023-11-13 12:55:48 -08:00
parent ffbc6140c3
commit a7b081b882
2 changed files with 61 additions and 52 deletions

View File

@ -7,7 +7,6 @@
#include "fault.h"
#include "pwm.h"
#include "sampling.h"
#include "pid.h"
struct sensorHeaterParams {
float targetTemp;
@ -62,63 +61,27 @@ static const PWMConfig heaterPwmConfig = {
.dier = 0
};
static constexpr int preheatTimeCounter = HEATER_PREHEAT_TIME / HEATER_CONTROL_PERIOD;
static constexpr int batteryStabTimeCounter = HEATER_BATTERY_STAB_TIME / HEATER_CONTROL_PERIOD;
static const struct sensorHeaterParams *heater;
class HeaterController : public IHeaterController
HeaterController::HeaterController(int ch, int pwm_ch)
: ch(ch), pwm_ch(pwm_ch)
{
public:
HeaterController(int ch, int pwm_ch)
: ch(ch), pwm_ch(pwm_ch)
{
}
}
void Update(const ISampler& sampler, HeaterAllow heaterAllowState) override;
bool HeaterController::IsRunningClosedLoop() const
{
return heaterState == HeaterState::ClosedLoop;
}
bool IsRunningClosedLoop() const override
{
return heaterState == HeaterState::ClosedLoop;
}
float HeaterController::GetHeaterEffectiveVoltage() const
{
return heaterVoltage;
}
float GetHeaterEffectiveVoltage() const override
{
return heaterVoltage;
}
HeaterState GetHeaterState() const override
{
return heaterState;
}
protected:
HeaterState GetNextState(HeaterAllow haeterAllowState, float batteryVoltage, float sensorTemp);
float GetVoltageForState(float heaterEsr);
private:
Pid heaterPid =
{
0.3f, // kP
0.3f, // kI
0.01f, // kD
3.0f, // Integrator clamp (volts)
HEATER_CONTROL_PERIOD
};
int timeCounter = preheatTimeCounter;
int batteryStabTime = batteryStabTimeCounter;
float rampVoltage = 0;
float heaterVoltage = 0;
HeaterState heaterState = HeaterState::Preheat;
#ifdef HEATER_MAX_DUTY
int cycle;
#endif
// TODO: private:
public:
const uint8_t ch;
const uint8_t pwm_ch;
};
HeaterState HeaterController::GetHeaterState() const
{
return heaterState;
}
HeaterController heaterControllers[AFR_CHANNELS] =
{

View File

@ -2,7 +2,10 @@
#include <cstdint>
#include "wideband_config.h"
#include "can.h"
#include "pid.h"
enum class HeaterState
{
@ -23,6 +26,49 @@ struct IHeaterController
virtual HeaterState GetHeaterState() const = 0;
};
class HeaterController : public IHeaterController
{
public:
HeaterController(int ch, int pwm_ch);
void Update(const ISampler& sampler, HeaterAllow heaterAllowState) override;
bool IsRunningClosedLoop() const override;
float GetHeaterEffectiveVoltage() const override;
HeaterState GetHeaterState() const override;
protected:
HeaterState GetNextState(HeaterAllow haeterAllowState, float batteryVoltage, float sensorTemp);
float GetVoltageForState(float heaterEsr);
private:
Pid heaterPid =
{
0.3f, // kP
0.3f, // kI
0.01f, // kD
3.0f, // Integrator clamp (volts)
HEATER_CONTROL_PERIOD
};
int timeCounter = preheatTimeCounter;
int batteryStabTime = batteryStabTimeCounter;
float rampVoltage = 0;
float heaterVoltage = 0;
HeaterState heaterState = HeaterState::Preheat;
#ifdef HEATER_MAX_DUTY
int cycle;
#endif
// TODO: private:
public:
const uint8_t ch;
const uint8_t pwm_ch;
static const int preheatTimeCounter = HEATER_PREHEAT_TIME / HEATER_CONTROL_PERIOD;
static const int batteryStabTimeCounter = HEATER_BATTERY_STAB_TIME / HEATER_CONTROL_PERIOD;
};
const IHeaterController& GetHeaterController(int ch);
void StartHeaterControl();