2020-10-31 16:59:35 -07:00
|
|
|
#include "pump_control.h"
|
|
|
|
#include "wideband_config.h"
|
|
|
|
#include "heater_control.h"
|
|
|
|
#include "sampling.h"
|
|
|
|
#include "pump_dac.h"
|
|
|
|
#include "pid.h"
|
|
|
|
|
|
|
|
#include "ch.h"
|
|
|
|
|
2020-11-02 23:05:35 -08:00
|
|
|
// Bosch CJ125 is somewhere VERY ROUGHLY like 200-400A/(v*s) integrator gain
|
2021-01-30 16:08:16 -08:00
|
|
|
static Pid pumpPid(50.0f, 10000.0f, 10, 2);
|
2020-10-31 16:59:35 -07:00
|
|
|
|
|
|
|
static THD_WORKING_AREA(waPumpThread, 256);
|
|
|
|
static void PumpThread(void*)
|
|
|
|
{
|
|
|
|
while(true)
|
|
|
|
{
|
|
|
|
// Only actuate pump when running closed loop!
|
|
|
|
if (IsRunningClosedLoop())
|
|
|
|
{
|
|
|
|
float nernstVoltage = GetNernstDc();
|
|
|
|
|
|
|
|
float result = pumpPid.GetOutput(NERNST_TARGET, nernstVoltage);
|
|
|
|
|
|
|
|
// result is in mA
|
2020-10-31 18:44:09 -07:00
|
|
|
SetPumpCurrentTarget(result * 1000);
|
2020-10-31 16:59:35 -07:00
|
|
|
}
|
2020-10-31 17:12:34 -07:00
|
|
|
|
|
|
|
// Run at 500hz
|
|
|
|
chThdSleepMilliseconds(2);
|
2020-10-31 16:59:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StartPumpControl()
|
|
|
|
{
|
|
|
|
chThdCreateStatic(waPumpThread, sizeof(waPumpThread), NORMALPRIO + 4, PumpThread, nullptr);
|
|
|
|
}
|