Files
bobbycar-boardcomputer-firm…/main/controller.cpp
T

33 lines
941 B
C++
Raw Normal View History

2021-11-01 20:44:57 +01:00
#include "controller.h"
2021-11-02 01:43:58 +01:00
// local includes
#include "globals.h"
2021-11-01 20:44:57 +01:00
Controller::Controller(
#ifdef FEATURE_SERIAL
HardwareSerial &serial,
#endif
bool &enableLeft, bool &enableRight, bool &invertLeft, bool &invertRight,
2022-01-03 01:31:48 +01:00
espconfig::ConfigWrapper<int16_t> &voltageCalib30V, espconfig::ConfigWrapper<int16_t> &voltageCalib50V
2021-11-01 20:44:57 +01:00
) :
#ifdef FEATURE_SERIAL
serial{serial},
#endif
enableLeft{enableLeft}, enableRight{enableRight}, invertLeft{invertLeft}, invertRight{invertRight},
voltageCalib30V{voltageCalib30V}, voltageCalib50V{voltageCalib50V}
{
}
2021-11-02 01:43:58 +01:00
float Controller::getCalibratedVoltage() const
2021-11-01 20:44:57 +01:00
{
float voltage = feedback.batVoltage;
2022-01-03 01:31:48 +01:00
if (configs.battery.applyCalibration.value)
2021-11-01 20:44:57 +01:00
{
2022-01-03 01:31:48 +01:00
voltage = ((voltage - float(voltageCalib30V.value)) * (20.f / (float(voltageCalib50V.value) - float(voltageCalib30V.value))) + 30.f);
2021-11-01 20:44:57 +01:00
}
else
{
voltage = voltage / 100.;
}
return voltage;
}