Cleanups
This commit is contained in:
@ -1,40 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <fmt/core.h>
|
||||
#include <cpptypesafeenum.h>
|
||||
|
||||
// local includes
|
||||
#include "globals.h"
|
||||
#include "cpputils.h"
|
||||
|
||||
#define BATTERY_CELLTYPE_22P 0
|
||||
#define BATTERY_CELLTYPE_HG2 1
|
||||
#define BATTERY_CELLTYPE_MH1 2
|
||||
#define BATTERY_CELLTYPE_VTC5 3
|
||||
#define BatteryCellTypeValues(x) \
|
||||
x(_22P) \
|
||||
x(HG2) \
|
||||
x(MH1) \
|
||||
x(VTC5)
|
||||
DECLARE_TYPESAFE_ENUM(BatteryCellType, : uint8_t, BatteryCellTypeValues)
|
||||
|
||||
float battery_percentage = 42.0;
|
||||
namespace {
|
||||
float battery_percentage = 42.f;
|
||||
|
||||
std::string getBatteryPercentageString() {
|
||||
std::string getBatteryPercentageString()
|
||||
{
|
||||
std::string output = fmt::format("Battery: {:.1f}%", battery_percentage);
|
||||
return output;
|
||||
}
|
||||
|
||||
std::string getBatteryCellTypeString() {
|
||||
std::string output = "";
|
||||
switch (settings.battery.cellType) {
|
||||
case BATTERY_CELLTYPE_22P:
|
||||
output = "Cells: 22P";
|
||||
break;
|
||||
case BATTERY_CELLTYPE_HG2:
|
||||
output = "Cells: HG2";
|
||||
break;
|
||||
case BATTERY_CELLTYPE_MH1:
|
||||
output = "Cells: MH1";
|
||||
break;
|
||||
case BATTERY_CELLTYPE_VTC5:
|
||||
output = "Cells: VTC5";
|
||||
break;
|
||||
default:
|
||||
output = "Unkown cell type";
|
||||
break;
|
||||
}
|
||||
|
||||
return output;
|
||||
std::string getBatteryCellTypeString()
|
||||
{
|
||||
return fmt::format("Cells: {}", toString(BatteryCellType(settings.battery.cellType)));
|
||||
}
|
||||
} // namespace
|
||||
|
@ -81,11 +81,11 @@ void handleBle()
|
||||
{
|
||||
auto arr = doc.createNestedArray("v");
|
||||
if (controllers.front.feedbackValid)
|
||||
arr.add(fixBatVoltage(controllers.front.feedback.batVoltage));
|
||||
arr.add(controllers.front.getCalibratedVoltage());
|
||||
else
|
||||
arr.add(nullptr);
|
||||
if (controllers.back.feedbackValid)
|
||||
arr.add(fixBatVoltage(controllers.back.feedback.batVoltage));
|
||||
arr.add(controllers.back.getCalibratedVoltage());
|
||||
else
|
||||
arr.add(nullptr);
|
||||
}
|
||||
|
@ -22,11 +22,6 @@
|
||||
#include CAN_PLUGIN
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
float fixFrontBatVoltage(int16_t value);
|
||||
float fixBackBatVoltage(int16_t value);
|
||||
}
|
||||
|
||||
namespace can {
|
||||
|
||||
namespace {
|
||||
@ -257,7 +252,6 @@ bool tryParseCanInput()
|
||||
|
||||
front.lastCanFeedback = espchrono::millis_clock::now();
|
||||
front.feedbackValid = true;
|
||||
front.calibrated.batVoltage = fixFrontBatVoltage(front.feedback.batVoltage);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@ -270,7 +264,6 @@ bool tryParseCanInput()
|
||||
{
|
||||
back.lastCanFeedback = espchrono::millis_clock::now();
|
||||
back.feedbackValid = true;
|
||||
back.calibrated.batVoltage = fixBackBatVoltage(back.feedback.batVoltage);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -109,7 +109,7 @@ void cloudCollect()
|
||||
}
|
||||
|
||||
cloudBuffer += fmt::format(",[{:.02f},{:.02f}",
|
||||
fixBatVoltage(controller.feedback.batVoltage),
|
||||
controller.getCalibratedVoltage(),
|
||||
fixBoardTemp(controller.feedback.boardTemp));
|
||||
|
||||
constexpr const auto addMotor = [](const bobbycar::protocol::serial::MotorState &command,
|
||||
|
@ -56,8 +56,26 @@ struct Controller {
|
||||
#ifdef FEATURE_SERIAL
|
||||
FeedbackParser parser{serial, feedbackValid, feedback};
|
||||
#endif
|
||||
struct Calibrated {
|
||||
float batVoltage;
|
||||
} calibrated;
|
||||
|
||||
float getCalibratedVoltage() const
|
||||
{
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
// float fixFrontBatVoltage(int16_t value)
|
||||
// {
|
||||
// float frontVoltage = value;
|
||||
// if (settings.battery.applyCalibration)
|
||||
// frontVoltage = ((frontVoltage - float(settings.battery.front30VoltCalibration)) * (20.f / (float(settings.battery.front50VoltCalibration) - float(settings.battery.front30VoltCalibration))) + 30.f);
|
||||
// return frontVoltage;
|
||||
// }
|
||||
|
||||
// float fixBackBatVoltage(int16_t value)
|
||||
// {
|
||||
// float backVoltage = value;
|
||||
// if (settings.battery.applyCalibration)
|
||||
// backVoltage = ((backVoltage - float(settings.battery.back30VoltCalibration)) * (20.f / (float(settings.battery.back50VoltCalibration) - float(settings.battery.back30VoltCalibration))) + 30.f);
|
||||
// return backVoltage;
|
||||
// }
|
||||
};
|
||||
}
|
||||
|
@ -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", fixBatVoltage(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 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; } };
|
||||
|
@ -52,11 +52,11 @@ namespace {
|
||||
}
|
||||
};
|
||||
|
||||
class BatteryVoltageCalibrationFront30VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("30V Front: {:.2f}V", fixBatVoltage(settings.battery.front30VoltCalibration)); } };
|
||||
class BatteryVoltageCalibrationBack30VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("30V Back: {:.2f}V", fixBatVoltage(settings.battery.back30VoltCalibration)); } };
|
||||
class BatteryVoltageCalibrationFront50VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("50V Front: {:.2f}V", fixBatVoltage(settings.battery.front50VoltCalibration)); } };
|
||||
class BatteryVoltageCalibrationBack50VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("50V Back: {:.2f}V", fixBatVoltage(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}", fixFrontBatVoltage(controllers.front.feedback.batVoltage), fixFrontBatVoltage(controllers.back.feedback.batVoltage)); else return "Not activated"; } };
|
||||
class BatteryVoltageCalibrationFront30VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("30V Front: {}", settings.battery.front30VoltCalibration); } };
|
||||
class BatteryVoltageCalibrationBack30VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("30V Back: {}", settings.battery.back30VoltCalibration); } };
|
||||
class BatteryVoltageCalibrationFront50VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("50V Front: {}", settings.battery.front50VoltCalibration); } };
|
||||
class BatteryVoltageCalibrationBack50VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("50V Back: {}", 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"; } };
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
@ -74,8 +74,8 @@ void MetersDisplay::redraw()
|
||||
tft.setTextFont(2);
|
||||
m_sumCurrentLabel.redraw(std::to_string(sumCurrent) + 'A');
|
||||
|
||||
meters[0].redraw(fixBatVoltage(controllers.front.feedback.batVoltage), 35, 50);
|
||||
meters[1].redraw(fixBatVoltage(controllers.back.feedback.batVoltage), 35, 50);
|
||||
meters[0].redraw(controllers.front.getCalibratedVoltage(), 35, 50);
|
||||
meters[1].redraw(controllers.back.getCalibratedVoltage(), 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);
|
||||
|
@ -297,14 +297,7 @@ void StatusDisplay::BoardStatus::redraw(const Controller &controller)
|
||||
|
||||
if (controller.feedbackValid)
|
||||
{
|
||||
if (settings.battery.applyCalibration)
|
||||
{
|
||||
m_labelVoltage.redraw(fmt::format("{:.2f}V", controller.calibrated.batVoltage));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_labelVoltage.redraw(fmt::format("{:.2f}V", fixBatVoltage(controller.feedback.batVoltage)));
|
||||
}
|
||||
m_labelVoltage.redraw(fmt::format("{:.2f}V", controller.getCalibratedVoltage()));
|
||||
m_labelTemperature.redraw(fmt::format("{:.2f}C", fixBoardTemp(controller.feedback.boardTemp)));
|
||||
m_leftMotor.redraw(controller.feedback.left);
|
||||
m_rightMotor.redraw(controller.feedback.right);
|
||||
|
@ -262,7 +262,7 @@ constexpr Settings::Battery defaultBattery {
|
||||
.back30VoltCalibration = 30,
|
||||
.front50VoltCalibration = 50,
|
||||
.back50VoltCalibration = 50,
|
||||
.applyCalibration = false
|
||||
.applyCalibration = true
|
||||
};
|
||||
|
||||
constexpr Settings defaultSettings {
|
||||
|
@ -30,13 +30,13 @@ void pushStats()
|
||||
statistics::sumCurrent.push_back(sumCurrent);
|
||||
if (controllers.front.feedbackValid)
|
||||
{
|
||||
statistics::frontVoltage.push_back(fixBatVoltage(controllers.front.feedback.batVoltage));
|
||||
statistics::frontVoltage.push_back(controllers.front.getCalibratedVoltage());
|
||||
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(fixBatVoltage(controllers.back.feedback.batVoltage));
|
||||
statistics::backVoltage.push_back(controllers.back.getCalibratedVoltage());
|
||||
statistics::backLeftCurrent.push_back(fixCurrent(controllers.back.feedback.left.dcLink));
|
||||
statistics::backRightCurrent.push_back(fixCurrent(controllers.back.feedback.right.dcLink));
|
||||
}
|
||||
|
21
main/utils.h
21
main/utils.h
@ -59,27 +59,6 @@ float fixCurrent(int16_t value)
|
||||
return -value/50.;
|
||||
}
|
||||
|
||||
float fixBatVoltage(int16_t value)
|
||||
{
|
||||
return value/100.;
|
||||
}
|
||||
|
||||
float fixFrontBatVoltage(int16_t value)
|
||||
{
|
||||
float frontVoltage = fixBatVoltage(value);
|
||||
if (!settings.battery.applyCalibration) return frontVoltage;
|
||||
frontVoltage = ((frontVoltage - fixBatVoltage(settings.battery.front30VoltCalibration)) * (20.f / (fixBatVoltage(settings.battery.front50VoltCalibration) - fixBatVoltage(settings.battery.front30VoltCalibration))) + 30.f);
|
||||
return frontVoltage;
|
||||
}
|
||||
|
||||
float fixBackBatVoltage(int16_t value)
|
||||
{
|
||||
float backVoltage = fixBatVoltage(value);
|
||||
if (!settings.battery.applyCalibration) return backVoltage;
|
||||
backVoltage = ((backVoltage - fixBatVoltage(settings.battery.back30VoltCalibration)) * (20.f / (fixBatVoltage(settings.battery.back50VoltCalibration) - fixBatVoltage(settings.battery.back30VoltCalibration))) + 30.f);
|
||||
return backVoltage;
|
||||
}
|
||||
|
||||
float fixBoardTemp(int16_t value)
|
||||
{
|
||||
return value/10.;
|
||||
|
Reference in New Issue
Block a user