Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions NERODevelopment/content/EfficiencyScreen.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Item {
property int timerValue: efficiencyController.currentTime
property int lastRunTime: efficiencyController.lastTime
property int fastestRunTime: efficiencyController.fastestTime
property int powerDrawPercent: efficiencyController.powerDrawPercent
property int xMargin: width / 20
property int yMargin: height / 20
property int verticalSpacing: height / 40
Expand Down Expand Up @@ -158,6 +159,18 @@ Item {
unitFontSize: efficiency.valueFontSize / 1.5
}

BatteryValueComponent {
id: powerDraw
title: "PWR DRAW"
batteryValue: efficiency.powerDrawPercent
Layout.fillWidth: true
Layout.fillHeight: true
radius: efficiency.borderRadii
valueFontSize: efficiency.valueFontSize
labelFontSize: efficiency.labelFontSize
unitFontSize: efficiency.valueFontSize / 1.5
}

TorqueValueComponent {
id: torqueValue
torqueValue: efficiency.torqueLimit
Expand Down
13 changes: 13 additions & 0 deletions NERODevelopment/content/SpeedMode.qml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Item {
property int maxDraw: speedController.maxCurrent
property int dcl: speedController.currentDischarge
property double regen: speedController.regen
property int powerDrawPercent: speedController.powerDrawPercent

property int xMargin: width / 20
property int yMargin: height / 20
Expand Down Expand Up @@ -121,6 +122,18 @@ Item {
valueFontSize: speedMode.valueFontSize
labelFontSize: speedMode.labelFontSize
}

BatteryValueComponent {
title: "PWR DRAW"
batteryValue: speedMode.powerDrawPercent
Layout.fillHeight: true
Layout.fillWidth: true
Layout.preferredHeight: 1
radius: speedMode.borderRadii
valueFontSize: speedMode.valueFontSize
labelFontSize: speedMode.labelFontSize
unitFontSize: speedMode.valueFontSize / 1.5
}
}

ColumnLayout {
Expand Down
34 changes: 34 additions & 0 deletions NERODevelopment/src/controllers/efficiencycontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,26 @@ void EfficiencyController::setSpeed(int speed) {
}
}

int EfficiencyController::powerDrawPercent() const {
return m_powerDrawPercent;
}
void EfficiencyController::setPowerDrawPercent(int percent) {
if (percent != m_powerDrawPercent) {
m_powerDrawPercent = percent;
emit powerDrawPercentChanged(percent);
}
}

int EfficiencyController::maxDCCurrentTarget() const {
return m_maxDCCurrentTarget;
}
void EfficiencyController::setMaxDCCurrentTarget(int target) {
if (target != m_maxDCCurrentTarget) {
m_maxDCCurrentTarget = target;
emit maxDCCurrentTargetChanged(target);
}
}

void EfficiencyController::currentDataDidChange() {
std::optional<float> torque = m_model->getTorquePower();
std::optional<float> regen = m_model->getRegenPower();
Expand All @@ -80,6 +100,8 @@ void EfficiencyController::currentDataDidChange() {
std::optional<float> packTemp = m_model->getPackTemp();
std::optional<float> lowVoltageSoc = m_model->getLowVoltageStateOfCharge();
std::optional<float> speed = m_model->getMph();
std::optional<float> dcCurrent = m_model->getDCCurrent();
std::optional<float> maxDCTarget = m_model->getMaxDCCurrentTarget();

if (torque) {
setCurrentMaxTorque(*torque);
Expand All @@ -102,6 +124,18 @@ void EfficiencyController::currentDataDidChange() {
if (speed) {
setSpeed(*speed);
}
if (maxDCTarget) {
setMaxDCCurrentTarget(static_cast<int>(std::round(std::abs(*maxDCTarget))));
}
if (dcCurrent && maxDCTarget && std::abs(*maxDCTarget) > 0) {
int percent = static_cast<int>(
std::round(std::abs(*dcCurrent) / std::abs(*maxDCTarget) * 100.0f));
if (percent > 100)
percent = 100;
if (percent < 0)
percent = 0;
setPowerDrawPercent(percent);
}
}

int EfficiencyController::currentTime() const { return m_currentTime; }
Expand Down
12 changes: 12 additions & 0 deletions NERODevelopment/src/controllers/efficiencycontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class EfficiencyController : public ButtonController {
fastestTimeChanged)
Q_PROPERTY(
int lastTime READ lastTime WRITE setLastTime NOTIFY lastTimeChanged)
Q_PROPERTY(int powerDrawPercent READ powerDrawPercent WRITE
setPowerDrawPercent NOTIFY powerDrawPercentChanged FINAL)
Q_PROPERTY(int maxDCCurrentTarget READ maxDCCurrentTarget WRITE
setMaxDCCurrentTarget NOTIFY maxDCCurrentTargetChanged FINAL)

public:
explicit EfficiencyController(Model *model, QObject *parent = nullptr);
Expand All @@ -46,6 +50,8 @@ class EfficiencyController : public ButtonController {
int currentTime() const;
int fastestTime() const;
int lastTime() const;
int powerDrawPercent() const;
int maxDCCurrentTarget() const;

signals:
void currentMaxTorqueChanged(int);
Expand All @@ -58,6 +64,8 @@ class EfficiencyController : public ButtonController {
void currentTimeChanged(int);
void fastestTimeChanged(int);
void lastTimeChanged(int);
void powerDrawPercentChanged(int);
void maxDCCurrentTargetChanged(int);

public slots:
void setCurrentMaxTorque(int);
Expand All @@ -71,6 +79,8 @@ public slots:
void setCurrentTime(int);
void setFastestTime(int);
void setLastTime(int);
void setPowerDrawPercent(int);
void setMaxDCCurrentTarget(int);

void enterButtonPressed() override;
void updateCurrentTime();
Expand All @@ -86,6 +96,8 @@ public slots:
int m_currentTime = 0;
int m_fastestTime = 0;
int m_lastTime = 0;
int m_powerDrawPercent = 0;
int m_maxDCCurrentTarget = 0;
bool m_timerRunning = false;
QElapsedTimer m_timer;
QTimer *m_updateTimer;
Expand Down
32 changes: 32 additions & 0 deletions NERODevelopment/src/controllers/speedcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,22 @@ void SpeedController::setMaxCurrentDischarge(float maxCurrentDischarge) {
}
}

int SpeedController::powerDrawPercent() const { return m_powerDrawPercent; }
void SpeedController::setPowerDrawPercent(int percent) {
if (percent != m_powerDrawPercent) {
m_powerDrawPercent = percent;
emit powerDrawPercentChanged(percent);
}
}

int SpeedController::maxDCCurrentTarget() const { return m_maxDCCurrentTarget; }
void SpeedController::setMaxDCCurrentTarget(int target) {
if (target != m_maxDCCurrentTarget) {
m_maxDCCurrentTarget = target;
emit maxDCCurrentTargetChanged(target);
}
}

void SpeedController::enterButtonPressed() {
if (m_timerRunning) {
m_timerRunning = false;
Expand Down Expand Up @@ -154,4 +170,20 @@ void SpeedController::update() {
setMaxCurrent(m_model->getMaxDraw());
setCurrentDischarge(*m_model->getDcl());
setRegen(*m_model->getRegenPower());

std::optional<float> dcCurrent = m_model->getDCCurrent();
std::optional<float> maxDCTarget = m_model->getMaxDCCurrentTarget();

if (maxDCTarget) {
setMaxDCCurrentTarget(static_cast<int>(std::round(std::abs(*maxDCTarget))));
}
if (dcCurrent && maxDCTarget && std::abs(*maxDCTarget) > 0) {
int percent = static_cast<int>(
std::round(std::abs(*dcCurrent) / std::abs(*maxDCTarget) * 100.0f));
if (percent > 100)
percent = 100;
if (percent < 0)
percent = 0;
setPowerDrawPercent(percent);
}
}
12 changes: 12 additions & 0 deletions NERODevelopment/src/controllers/speedcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class SpeedController : public ButtonController {
setCurrentDischarge NOTIFY currentDischargeChanged)
Q_PROPERTY(float maxCurrentDischarge READ maxCurrentDischarge WRITE
setMaxCurrentDischarge NOTIFY maxCurrentDischargeChanged)
Q_PROPERTY(int powerDrawPercent READ powerDrawPercent WRITE
setPowerDrawPercent NOTIFY powerDrawPercentChanged)
Q_PROPERTY(int maxDCCurrentTarget READ maxDCCurrentTarget WRITE
setMaxDCCurrentTarget NOTIFY maxDCCurrentTargetChanged)

public:
explicit SpeedController(Model *model, QObject *parent = nullptr);
Expand All @@ -53,6 +57,8 @@ class SpeedController : public ButtonController {
float currentDischarge() const;
float maxCurrentDischarge() const;
float regen() const;
int powerDrawPercent() const;
int maxDCCurrentTarget() const;

signals:
void tractionControlChanged(bool);
Expand All @@ -69,6 +75,8 @@ class SpeedController : public ButtonController {
void currentDischargeChanged(float);
void maxCurrentDischargeChanged(float);
void regenChanged(float);
void powerDrawPercentChanged(int);
void maxDCCurrentTargetChanged(int);

public slots:
void setTractionControl(bool);
Expand All @@ -85,6 +93,8 @@ public slots:
void setCurrentDischarge(float);
void setMaxCurrentDischarge(float);
void setRegen(float);
void setPowerDrawPercent(int);
void setMaxDCCurrentTarget(int);

void enterButtonPressed() override;
void updateCurrentTime();
Expand All @@ -106,6 +116,8 @@ public slots:
float m_currentDischarge = 0;
float m_maxCurrentDischarge = 0;
float m_regen = 0;
int m_powerDrawPercent = 0;
int m_maxDCCurrentTarget = 0;

bool m_timerRunning = false;
QElapsedTimer m_timer;
Expand Down
2 changes: 2 additions & 0 deletions NERODevelopment/src/models/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class Model : public QObject {
virtual std::optional<float> getMotorTemp() = 0;
virtual std::optional<float> getStateOfCharge() = 0;
virtual std::optional<float> getCurrent() = 0;
virtual std::optional<float> getDCCurrent() = 0;
virtual std::optional<float> getMaxDCCurrentTarget() = 0;
virtual std::optional<float> getBalancingCells() = 0;
virtual std::optional<float> getPackVoltage() = 0;
virtual std::optional<float> getMaxCellTemp() = 0;
Expand Down
10 changes: 10 additions & 0 deletions NERODevelopment/src/models/raspberry_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ void RaspberryModel::connectToMQTT() {
MOTORTEMP,
STATEOFCHARGE,
CURRENT,
DCCURRENT,
MAXDCCURRENTTARGET,
BALANCINGCELLS,
PACKVOLTAGE,
MAXCELLTEMP,
Expand Down Expand Up @@ -176,6 +178,14 @@ std::optional<float> RaspberryModel::getCurrent() {
return this->getById(CURRENT);
}

std::optional<float> RaspberryModel::getDCCurrent() {
return this->getById(DCCURRENT);
}

std::optional<float> RaspberryModel::getMaxDCCurrentTarget() {
return this->getById(MAXDCCURRENTTARGET);
}

std::optional<float> RaspberryModel::getMaxCellVoltage() {
std::optional<float> voltage = this->getById(MAXCELLVOLTAGE);
return voltage ? std::optional<float>(std::round(*voltage * 1000))
Expand Down
2 changes: 2 additions & 0 deletions NERODevelopment/src/models/raspberry_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class RaspberryModel : public Model {
std::optional<float> getMotorTemp() override;
std::optional<float> getStateOfCharge() override;
std::optional<float> getCurrent() override;
std::optional<float> getDCCurrent() override;
std::optional<float> getMaxDCCurrentTarget() override;
std::optional<float> getBalancingCells() override;
std::optional<float> getPackVoltage() override;
std::optional<float> getMaxCellTemp() override;
Expand Down
2 changes: 2 additions & 0 deletions NERODevelopment/src/utils/data_type_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#define MOTORTEMP "DTI/Temps/Motor_Temperature"
#define STATEOFCHARGE "BMS/Pack/SOC"
#define CURRENT "DTI/Power/AC_Current"
#define DCCURRENT "DTI/Power/DC_Current"
#define MAXDCCURRENTTARGET "BMS/Commands/Max_DC_Current_Target"
#define BALANCINGCELLS "balancingcells"
#define PACKVOLTAGE "BMS/Pack/Voltage"
#define MAXCELLTEMP "BMS/Cells/Temp_High_Value"
Expand Down