First steps for discharge curves, calibration can be deactivated now

This commit is contained in:
CommanderRedYT
2021-10-14 20:32:52 +02:00
parent 5dc794b903
commit 7e7727e180
9 changed files with 45 additions and 16 deletions

View File

@ -16,11 +16,33 @@
DECLARE_TYPESAFE_ENUM(BatteryCellType, : uint8_t, BatteryCellTypeValues)
namespace {
float battery_percentage = 42.f;
float getBatteryPercentage(float batVoltage, BatteryCellType cellType)
{
float percentage = 0;
switch (cellType) {
case BatteryCellType::_22P:
break;
case BatteryCellType::MH1:
break;
case BatteryCellType::HG2:
break;
case BatteryCellType::VTC5:
break;
}
return percentage;
}
std::string getBatteryPercentageString()
{
std::string output = fmt::format("Battery: {:.1f}%", battery_percentage);
float avgVoltage = 0;
for (auto &controller : controllers)
{
avgVoltage += controller.getCalibratedVoltage(settings.battery.applyCalibration);
}
avgVoltage = avgVoltage / controllers.size();
std::string output = fmt::format("Battery: {:.1f}%", getBatteryPercentage(avgVoltage, BatteryCellType(settings.battery.cellType)));
return output;
}

View File

@ -81,11 +81,11 @@ void handleBle()
{
auto arr = doc.createNestedArray("v");
if (controllers.front.feedbackValid)
arr.add(controllers.front.getCalibratedVoltage());
arr.add(controllers.front.getCalibratedVoltage(settings.battery.applyCalibration));
else
arr.add(nullptr);
if (controllers.back.feedbackValid)
arr.add(controllers.back.getCalibratedVoltage());
arr.add(controllers.back.getCalibratedVoltage(settings.battery.applyCalibration));
else
arr.add(nullptr);
}

View File

@ -109,7 +109,7 @@ void cloudCollect()
}
cloudBuffer += fmt::format(",[{:.02f},{:.02f}",
controller.getCalibratedVoltage(),
controller.getCalibratedVoltage(settings.battery.applyCalibration),
fixBoardTemp(controller.feedback.boardTemp));
constexpr const auto addMotor = [](const bobbycar::protocol::serial::MotorState &command,

View File

@ -24,6 +24,7 @@ class HardwareSerial;
#endif
namespace {
struct Controller {
Controller(
#ifdef FEATURE_SERIAL
@ -60,11 +61,17 @@ struct Controller {
FeedbackParser parser{serial, feedbackValid, feedback};
#endif
float getCalibratedVoltage() const
float getCalibratedVoltage(bool applyCalibration) const
{
float voltage = feedback.batVoltage;
//if (settings.battery.applyCalibration)
if (applyCalibration)
{
voltage = ((voltage - float(voltageCalib30V)) * (20.f / (float(voltageCalib50V) - float(voltageCalib30V))) + 30.f);
}
else
{
voltage = voltage / 100.;
}
return voltage;
}
};

View File

@ -48,7 +48,7 @@ public:
using RightCommand = CommandTexts<LeftCommandGetter>;
//struct BatVoltageText : public virtual TextInterface { public: std::string text() const override { std::string line{"batVoltage: "}; if (controller::get().feedbackValid) line += std::to_string(controller::get().feedback.batVoltage); return line; } };
struct BatVoltageFixedText : public virtual TextInterface { public: std::string text() const override { std::string line{"batVoltage: "}; if (controller::get().feedbackValid) line += fmt::format("{:.2f}V", controller::get().getCalibratedVoltage()); return line; } };
struct BatVoltageFixedText : public virtual TextInterface { public: std::string text() const override { std::string line{"batVoltage: "}; if (controller::get().feedbackValid) line += fmt::format("{:.2f}V", controller::get().getCalibratedVoltage(settings.battery.applyCalibration)); return line; } };
//struct BoardTempText : public virtual TextInterface { public: std::string text() const override { std::string line{"boardTemp: "}; if (controller::get().feedbackValid) line += std::to_string(controller::get().feedback.boardTemp); return line; } };
struct BoardTempFixedText : public virtual TextInterface { public: std::string text() const override { std::string line{"boardTemp: "}; if (controller::get().feedbackValid) line += fmt::format("{:.2f}C", fixBoardTemp(controller::get().feedback.boardTemp)); return line; } };
struct TimeoutCntSerialText : public virtual TextInterface { public: std::string text() const override { std::string line{"timeoutCntSerial: "}; if (controller::get().feedbackValid) line += std::to_string(controller::get().feedback.timeoutCntSerial); return line; } };

View File

@ -61,7 +61,7 @@ namespace {
class BatteryVoltageCalibrationBack30VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("30V Back: {}", convertToFloat(settings.battery.back30VoltCalibration)); } };
class BatteryVoltageCalibrationFront50VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("50V Front: {}", convertToFloat(settings.battery.front50VoltCalibration)); } };
class BatteryVoltageCalibrationBack50VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("50V Back: {}", convertToFloat(settings.battery.back50VoltCalibration)); } };
class BatteryVoltageCalibratedText : public virtual TextInterface { public: std::string text() const override { if (settings.battery.applyCalibration) return fmt::format("F{:.2f}V B{:.2f}", controllers.front.getCalibratedVoltage(), controllers.back.getCalibratedVoltage()); else return "Not activated"; } };
class BatteryVoltageCalibratedText : public virtual TextInterface { public: std::string text() const override { if (settings.battery.applyCalibration) return fmt::format("F{:.2f}V B{:.2f}", controllers.front.getCalibratedVoltage(settings.battery.applyCalibration), controllers.back.getCalibratedVoltage(settings.battery.applyCalibration)); else return "Not activated"; } };
}
namespace {

View File

@ -74,8 +74,8 @@ void MetersDisplay::redraw()
tft.setTextFont(2);
m_sumCurrentLabel.redraw(std::to_string(sumCurrent) + 'A');
meters[0].redraw(controllers.front.getCalibratedVoltage(), 35, 50);
meters[1].redraw(controllers.back.getCalibratedVoltage(), 35, 50);
meters[0].redraw(controllers.front.getCalibratedVoltage(settings.battery.applyCalibration), 35, 50);
meters[1].redraw(controllers.back.getCalibratedVoltage(settings.battery.applyCalibration), 35, 50);
meters[2].redraw(fixCurrent(controllers.front.feedback.left.dcLink), -10, 10);
meters[3].redraw(fixCurrent(controllers.front.feedback.right.dcLink), -10, 10);
meters[4].redraw(fixCurrent(controllers.back.feedback.left.dcLink), -10, 10);

View File

@ -97,8 +97,8 @@ private:
Label m_batterypercent{0, 30};
BoardStatus m_frontStatus{42};
BoardStatus m_backStatus{142};
BoardStatus m_frontStatus{45};
BoardStatus m_backStatus{145};
Label m_labelWifiStatus{35, bottomLines[0]}; // 120, 15
Label m_labelLimit0{205, bottomLines[0]}; // 35, 15
@ -297,7 +297,7 @@ void StatusDisplay::BoardStatus::redraw(const Controller &controller)
if (controller.feedbackValid)
{
m_labelVoltage.redraw(fmt::format("{:.2f}V", controller.getCalibratedVoltage()));
m_labelVoltage.redraw(fmt::format("{:.2f}V", controller.getCalibratedVoltage(settings.battery.applyCalibration)));
m_labelTemperature.redraw(fmt::format("{:.2f}C", fixBoardTemp(controller.feedback.boardTemp)));
m_leftMotor.redraw(controller.feedback.left);
m_rightMotor.redraw(controller.feedback.right);

View File

@ -30,13 +30,13 @@ void pushStats()
statistics::sumCurrent.push_back(sumCurrent);
if (controllers.front.feedbackValid)
{
statistics::frontVoltage.push_back(controllers.front.getCalibratedVoltage());
statistics::frontVoltage.push_back(controllers.front.getCalibratedVoltage(settings.battery.applyCalibration));
statistics::frontLeftCurrent.push_back(fixCurrent(controllers.front.feedback.left.dcLink));
statistics::frontRightCurrent.push_back(fixCurrent(controllers.front.feedback.right.dcLink));
}
if (controllers.back.feedbackValid)
{
statistics::backVoltage.push_back(controllers.back.getCalibratedVoltage());
statistics::backVoltage.push_back(controllers.back.getCalibratedVoltage(settings.battery.applyCalibration));
statistics::backLeftCurrent.push_back(fixCurrent(controllers.back.feedback.left.dcLink));
statistics::backRightCurrent.push_back(fixCurrent(controllers.back.feedback.right.dcLink));
}