diff --git a/NERODesign/src/import_qml_components_plugins.h b/NERODesign/src/import_qml_components_plugins.h index 688dad6..d91c9cc 100644 --- a/NERODesign/src/import_qml_components_plugins.h +++ b/NERODesign/src/import_qml_components_plugins.h @@ -16,4 +16,4 @@ Q_IMPORT_QML_PLUGIN(QtQuick_Studio_MultiTextPlugin) Q_IMPORT_QML_PLUGIN(QtQuick_Studio_EventSimulatorPlugin) Q_IMPORT_QML_PLUGIN(QtQuick_Studio_EventSystemPlugin) -#endif +#endif \ No newline at end of file diff --git a/NERODesign/src/import_qml_plugins.h b/NERODesign/src/import_qml_plugins.h index 0c13bb9..e71e570 100644 --- a/NERODesign/src/import_qml_plugins.h +++ b/NERODesign/src/import_qml_plugins.h @@ -6,4 +6,4 @@ #include Q_IMPORT_QML_PLUGIN(contentPlugin) -Q_IMPORT_QML_PLUGIN(NEROPlugin) +Q_IMPORT_QML_PLUGIN(NEROPlugin) \ No newline at end of file diff --git a/NERODevelopment/CMakeLists.txt b/NERODevelopment/CMakeLists.txt index f8581ac..5eaba78 100644 --- a/NERODevelopment/CMakeLists.txt +++ b/NERODevelopment/CMakeLists.txt @@ -111,4 +111,4 @@ install(TARGETS NEROApp BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} -) +) \ No newline at end of file diff --git a/NERODevelopment/content/EfficiencyScreen.qml b/NERODevelopment/content/EfficiencyScreen.qml index c32d1f6..71b5acc 100644 --- a/NERODevelopment/content/EfficiencyScreen.qml +++ b/NERODevelopment/content/EfficiencyScreen.qml @@ -10,6 +10,7 @@ Item { anchors.fill: parent property int torqueLimit: efficiencyController.currentMaxTorque property int numRegen: efficiencyController.currentRegenStrength + property double numRegenPercentage: efficiencyController.currentRegenPercentage property int hvSOC: efficiencyController.stateOfCharge property int lvSOC: efficiencyController.lowVoltageStateOfCharge property int motorTemp: efficiencyController.motorTemp @@ -84,14 +85,14 @@ Item { ThermometerValueComponent { id: regen regen: true - thermometerValue: efficiency.numRegen + thermometerValue: showPercentage ? efficiency.numRegenPercentage : efficiency.numRegen title: "REGEN" Layout.fillWidth: true Layout.fillHeight: true radius: efficiency.borderRadii valueFontSize: efficiency.valueFontSize labelFontSize: efficiency.labelFontSize - unitFontSize: efficiency.labelFontSize / 2 + unitFontSize: efficiency.valueFontSize / 1.5 } } diff --git a/NERODevelopment/content/SpeedMode.qml b/NERODevelopment/content/SpeedMode.qml index 20ddc53..6d8dfbd 100644 --- a/NERODevelopment/content/SpeedMode.qml +++ b/NERODevelopment/content/SpeedMode.qml @@ -19,6 +19,7 @@ Item { property int maxDraw: speedController.maxCurrent property int dcl: speedController.currentDischarge property double regen: speedController.regen + property double regenPercentage: speedController.regenPercentage property int xMargin: width / 20 property int yMargin: height / 20 @@ -89,8 +90,8 @@ Item { spacing: parent.height / 20 ThermometerValueComponent { - thermometerValue: speedMode.regen - title: "Regen" + thermometerValue: showPercentage ? speedMode.regenPercentage : speedMode.regen + title: "REGEN" Layout.fillHeight: true Layout.fillWidth: true Layout.preferredHeight: 1 diff --git a/NERODevelopment/content/ThermometerValueComponent.qml b/NERODevelopment/content/ThermometerValueComponent.qml index 12f7f98..85b60f0 100644 --- a/NERODevelopment/content/ThermometerValueComponent.qml +++ b/NERODevelopment/content/ThermometerValueComponent.qml @@ -34,6 +34,6 @@ Item { valueFontSize: thermometerComponent.valueFontSize labelFontSize: thermometerComponent.labelFontSize unitFontSize: thermometerComponent.unitFontSize - unitAnchorBottom: regen ? true : false + unitAnchorBottom: showPercentage ? false : true } } diff --git a/NERODevelopment/src/controllers/efficiencycontroller.cpp b/NERODevelopment/src/controllers/efficiencycontroller.cpp index b2a6ff2..5d28795 100644 --- a/NERODevelopment/src/controllers/efficiencycontroller.cpp +++ b/NERODevelopment/src/controllers/efficiencycontroller.cpp @@ -2,12 +2,13 @@ EfficiencyController::EfficiencyController(Model *model, QObject *parent) : ButtonController{model, 4, parent}, m_updateTimer(new QTimer(this)), - m_timerRunning(false) { - connect(m_model, &Model::onCurrentDataChange, this, - &EfficiencyController::currentDataDidChange); - connect(m_updateTimer, &QTimer::timeout, this, - &EfficiencyController::updateCurrentTime); - m_updateTimer->setInterval(1); + m_timerRunning(false) { + connect(m_model, &Model::onCurrentDataChange, this, + &EfficiencyController::currentDataDidChange); + connect(m_updateTimer, &QTimer::timeout, this, + &EfficiencyController::updateCurrentTime); + m_updateTimer->setInterval(1); + currentDataDidChange(); } int EfficiencyController::currentMaxTorque() const { @@ -23,10 +24,30 @@ void EfficiencyController::setCurrentMaxTorque(int torque) { int EfficiencyController::currentRegenStrength() const { return m_currentRegenStrength; } + +float EfficiencyController::currentRegenPercentage() const { + if (m_maxRegenCapacity > 0) { + return (abs(m_currentRegenStrength) / abs(m_maxRegenCapacity)) * 100.0f; + } + return 0.0f; +} + +float EfficiencyController::maxRegenCapacity() const { + return m_maxRegenCapacity; +} + +void EfficiencyController::setMaxRegenCapacity(float capacity) { + if (capacity != m_maxRegenCapacity) { + m_maxRegenCapacity = capacity; + emit maxRegenCapacityChanged(capacity); + emit currentRegenPercentageChanged(currentRegenPercentage()); + } +} void EfficiencyController::setCurrentRegenStrength(int strength) { if (strength != m_currentRegenStrength) { m_currentRegenStrength = strength; emit currentRegenStrengthChanged(strength); + emit currentRegenPercentageChanged(currentRegenPercentage()); } } @@ -73,35 +94,39 @@ void EfficiencyController::setSpeed(int speed) { } void EfficiencyController::currentDataDidChange() { - std::optional torque = m_model->getTorquePower(); - std::optional regen = m_model->getRegenPower(); - std::optional soc = m_model->getStateOfCharge(); - std::optional motorTemp = m_model->getMotorTemp(); - std::optional packTemp = m_model->getPackTemp(); - std::optional lowVoltageSoc = m_model->getLowVoltageStateOfCharge(); - std::optional speed = m_model->getMph(); - - if (torque) { - setCurrentMaxTorque(*torque); - } - if (regen) { - setCurrentRegenStrength(*regen); - } - if (soc) { - setStateOfCharge(*soc); - } - if (motorTemp) { - setMotorTemp(*motorTemp); - } - if (packTemp) { - setPackTemp(*packTemp); - } - if (lowVoltageSoc) { - setLowVoltageStateOfCharge(*lowVoltageSoc); - } - if (speed) { - setSpeed(*speed); - } + std::optional torque = m_model->getTorquePower(); + std::optional regen = m_model->getRegenPower(); + std::optional soc = m_model->getStateOfCharge(); + std::optional motorTemp = m_model->getMotorTemp(); + std::optional packTemp = m_model->getPackTemp(); + std::optional lowVoltageSoc = m_model->getLowVoltageStateOfCharge(); + std::optional speed = m_model->getMph(); + std::optional maxRegenCapacity = m_model->getMaxRegenCapacity(); + + if (torque) { + setCurrentMaxTorque(*torque); + } + if (regen) { + setCurrentRegenStrength(*regen); + } + if (soc) { + setStateOfCharge(*soc); + } + if (motorTemp) { + setMotorTemp(*motorTemp); + } + if (packTemp) { + setPackTemp(*packTemp); + } + if (lowVoltageSoc) { + setLowVoltageStateOfCharge(*lowVoltageSoc); + } + if (speed) { + setSpeed(*speed); + } + if (maxRegenCapacity) { + setMaxRegenCapacity(*maxRegenCapacity); + } } int EfficiencyController::currentTime() const { return m_currentTime; } diff --git a/NERODevelopment/src/controllers/efficiencycontroller.h b/NERODevelopment/src/controllers/efficiencycontroller.h index 1b9a9bd..9168d75 100644 --- a/NERODevelopment/src/controllers/efficiencycontroller.h +++ b/NERODevelopment/src/controllers/efficiencycontroller.h @@ -33,6 +33,8 @@ class EfficiencyController : public ButtonController { fastestTimeChanged) Q_PROPERTY( int lastTime READ lastTime WRITE setLastTime NOTIFY lastTimeChanged) + Q_PROPERTY(float currentRegenPercentage READ currentRegenPercentage NOTIFY currentRegenPercentageChanged) + Q_PROPERTY(float maxRegenCapacity READ maxRegenCapacity WRITE setMaxRegenCapacity NOTIFY maxRegenCapacityChanged) public: explicit EfficiencyController(Model *model, QObject *parent = nullptr); @@ -46,6 +48,8 @@ class EfficiencyController : public ButtonController { int currentTime() const; int fastestTime() const; int lastTime() const; + float currentRegenPercentage() const; + float maxRegenCapacity() const; signals: void currentMaxTorqueChanged(int); @@ -58,6 +62,8 @@ class EfficiencyController : public ButtonController { void currentTimeChanged(int); void fastestTimeChanged(int); void lastTimeChanged(int); + void currentRegenPercentageChanged(float); + void maxRegenCapacityChanged(float); public slots: void setCurrentMaxTorque(int); @@ -71,13 +77,15 @@ public slots: void setCurrentTime(int); void setFastestTime(int); void setLastTime(int); + void setMaxRegenCapacity(float); void enterButtonPressed() override; void updateCurrentTime(); -private: + private: int m_currentMaxTorque = 0; // torque percentage [0,100] int m_currentRegenStrength = 0; // regen strength [1,3] + float m_maxRegenCapacity = 10.0f; // Changed from 10.0f to 0 - will be set from model int m_stateOfCharge = 0; // charge percentage [0,100] int m_motorTemp = 0; // Celsius int m_packTemp = 0; // Celsius diff --git a/NERODevelopment/src/controllers/speedcontroller.cpp b/NERODevelopment/src/controllers/speedcontroller.cpp index f822860..069d10e 100644 --- a/NERODevelopment/src/controllers/speedcontroller.cpp +++ b/NERODevelopment/src/controllers/speedcontroller.cpp @@ -4,10 +4,11 @@ SpeedController::SpeedController(Model *model, QObject *parent) : ButtonController{model, 3, parent}, m_updateTimer(new QTimer(this)) { - connect(m_model, &Model::onCurrentDataChange, this, &SpeedController::update); - connect(m_updateTimer, &QTimer::timeout, this, - &SpeedController::updateCurrentTime); - m_updateTimer->setInterval(1); + connect(m_model, &Model::onCurrentDataChange, this, &SpeedController::update); + connect(m_updateTimer, &QTimer::timeout, this, + &SpeedController::updateCurrentTime); + m_updateTimer->setInterval(1); + update(); } bool SpeedController::tractionControl() const { return m_tractionControl; } @@ -23,9 +24,30 @@ void SpeedController::setRegen(float regen) { if (regen != m_regen) { m_regen = regen; emit regenChanged(regen); + emit regenPercentageChanged(regenPercentage()); } } +float SpeedController::regenPercentage() const { + if (m_maxRegenCapacity > 0) { + float result = (abs(m_regen) / abs(m_maxRegenCapacity)) * 100.0f; + return result; + } + return 0.0f; +} + +float SpeedController::maxRegenCapacity() const { + return m_maxRegenCapacity; +} + +void SpeedController::setMaxRegenCapacity(float capacity) { + if (capacity != m_maxRegenCapacity) { + m_maxRegenCapacity = capacity; + emit maxRegenCapacityChanged(capacity); + emit regenPercentageChanged(regenPercentage()); + } +} + float SpeedController::packTemp() const { return m_packTemp; } void SpeedController::setPackTemp(float packTemp) { if (packTemp != m_packTemp) { @@ -144,14 +166,15 @@ void SpeedController::updateCurrentTime() { } void SpeedController::update() { - setTractionControl(*m_model->getTractionControl()); - setPackTemp(*m_model->getPackTemp()); - setMotorTemp(*m_model->getMotorTemp()); - setChargeState(*m_model->getStateOfCharge()); - setCurrentSpeed(*m_model->getMph()); - setMaxSpeed(m_model->getMaxSpeed()); - setCurrent(*m_model->getCurrent()); - setMaxCurrent(m_model->getMaxDraw()); - setCurrentDischarge(*m_model->getDcl()); - setRegen(*m_model->getRegenPower()); + setTractionControl(*m_model->getTractionControl()); + setPackTemp(*m_model->getPackTemp()); + setMotorTemp(*m_model->getMotorTemp()); + setChargeState(*m_model->getStateOfCharge()); + setCurrentSpeed(*m_model->getMph()); + setMaxSpeed(m_model->getMaxSpeed()); + setCurrent(*m_model->getCurrent()); + setMaxCurrent(m_model->getMaxDraw()); + setCurrentDischarge(*m_model->getDcl()); + setRegen(*m_model->getRegenPower()); + setMaxRegenCapacity(*m_model->getMaxRegenCapacity()); } diff --git a/NERODevelopment/src/controllers/speedcontroller.h b/NERODevelopment/src/controllers/speedcontroller.h index f790ee5..b0b7db9 100644 --- a/NERODevelopment/src/controllers/speedcontroller.h +++ b/NERODevelopment/src/controllers/speedcontroller.h @@ -35,6 +35,8 @@ class SpeedController : public ButtonController { setCurrentDischarge NOTIFY currentDischargeChanged) Q_PROPERTY(float maxCurrentDischarge READ maxCurrentDischarge WRITE setMaxCurrentDischarge NOTIFY maxCurrentDischargeChanged) + Q_PROPERTY(float regenPercentage READ regenPercentage NOTIFY regenPercentageChanged) + Q_PROPERTY(float maxRegenCapacity READ maxRegenCapacity WRITE setMaxRegenCapacity NOTIFY maxRegenCapacityChanged) public: explicit SpeedController(Model *model, QObject *parent = nullptr); @@ -53,6 +55,8 @@ class SpeedController : public ButtonController { float currentDischarge() const; float maxCurrentDischarge() const; float regen() const; + float regenPercentage() const; + float maxRegenCapacity() const; signals: void tractionControlChanged(bool); @@ -69,6 +73,8 @@ class SpeedController : public ButtonController { void currentDischargeChanged(float); void maxCurrentDischargeChanged(float); void regenChanged(float); + void regenPercentageChanged(float); + void maxRegenCapacityChanged(float); public slots: void setTractionControl(bool); @@ -85,6 +91,7 @@ public slots: void setCurrentDischarge(float); void setMaxCurrentDischarge(float); void setRegen(float); + void setMaxRegenCapacity(float); void enterButtonPressed() override; void updateCurrentTime(); @@ -106,7 +113,7 @@ public slots: float m_currentDischarge = 0; float m_maxCurrentDischarge = 0; float m_regen = 0; - + float m_maxRegenCapacity = 0; bool m_timerRunning = false; QElapsedTimer m_timer; QTimer *m_updateTimer; diff --git a/NERODevelopment/src/import_qml_components_plugins.h b/NERODevelopment/src/import_qml_components_plugins.h index 688dad6..d91c9cc 100644 --- a/NERODevelopment/src/import_qml_components_plugins.h +++ b/NERODevelopment/src/import_qml_components_plugins.h @@ -16,4 +16,4 @@ Q_IMPORT_QML_PLUGIN(QtQuick_Studio_MultiTextPlugin) Q_IMPORT_QML_PLUGIN(QtQuick_Studio_EventSimulatorPlugin) Q_IMPORT_QML_PLUGIN(QtQuick_Studio_EventSystemPlugin) -#endif +#endif \ No newline at end of file diff --git a/NERODevelopment/src/import_qml_plugins.h b/NERODevelopment/src/import_qml_plugins.h index 0c13bb9..e71e570 100644 --- a/NERODevelopment/src/import_qml_plugins.h +++ b/NERODevelopment/src/import_qml_plugins.h @@ -6,4 +6,4 @@ #include Q_IMPORT_QML_PLUGIN(contentPlugin) -Q_IMPORT_QML_PLUGIN(NEROPlugin) +Q_IMPORT_QML_PLUGIN(NEROPlugin) \ No newline at end of file diff --git a/NERODevelopment/src/main.cpp b/NERODevelopment/src/main.cpp index 4f6903b..2c9e777 100644 --- a/NERODevelopment/src/main.cpp +++ b/NERODevelopment/src/main.cpp @@ -56,4 +56,4 @@ int main(int argc, char *argv[]) { engine.loadFromModule("content", "App"); return app.exec(); -} +} \ No newline at end of file diff --git a/NERODevelopment/src/models/model.h b/NERODevelopment/src/models/model.h index 00ebce4..8dcfdd2 100644 --- a/NERODevelopment/src/models/model.h +++ b/NERODevelopment/src/models/model.h @@ -28,6 +28,7 @@ class Model : public QObject { virtual std::optional getDir() = 0; virtual std::optional getPackTemp() = 0; virtual std::optional getMotorTemp() = 0; + virtual std::optional getMaxRegenCapacity() = 0; virtual std::optional getStateOfCharge() = 0; virtual std::optional getCurrent() = 0; virtual std::optional getBalancingCells() = 0; diff --git a/NERODevelopment/src/models/mqtt_client.cpp b/NERODevelopment/src/models/mqtt_client.cpp index 7a0c182..8b8ff85 100644 --- a/NERODevelopment/src/models/mqtt_client.cpp +++ b/NERODevelopment/src/models/mqtt_client.cpp @@ -109,4 +109,4 @@ void MqttClient::sendMessage(const QString topic, const float value) { serverData.setTimeUs(timeUs); QByteArray data = serverData.serialize(&this->m_serializer); m_client->publish("NERO/" + topic, data); -} +} \ No newline at end of file diff --git a/NERODevelopment/src/models/mqtt_client.h b/NERODevelopment/src/models/mqtt_client.h index 00ef992..24a317b 100644 --- a/NERODevelopment/src/models/mqtt_client.h +++ b/NERODevelopment/src/models/mqtt_client.h @@ -92,4 +92,4 @@ private slots: QProtobufSerializer m_serializer; QList m_topics = {}; }; -#endif // MQTTCLIENT_H +#endif // MQTTCLIENT_H \ No newline at end of file diff --git a/NERODevelopment/src/models/raspberry_model.cpp b/NERODevelopment/src/models/raspberry_model.cpp index 82ed3cb..afe6be7 100644 --- a/NERODevelopment/src/models/raspberry_model.cpp +++ b/NERODevelopment/src/models/raspberry_model.cpp @@ -45,6 +45,7 @@ void RaspberryModel::connectToMQTT() { STATUS, PACKTEMP, MOTORTEMP, + MAXREGENCAPACITY, STATEOFCHARGE, CURRENT, BALANCINGCELLS, @@ -74,7 +75,7 @@ void RaspberryModel::connectToMQTT() { DCL, CCL, GFORCEX, - GFORCEY, + GFORCEY, GFORCEZ, SEGMENTTEMP1, SEGMENTTEMP2, @@ -98,7 +99,7 @@ void RaspberryModel::connectToMQTT() { LASTTIME, CURRENT_TIME, LOWVOLTAGESOC, - + REGENPOWER }; const char *client1_port_str = getenv("CLIENT1_PORT"); @@ -107,7 +108,7 @@ void RaspberryModel::connectToMQTT() { int client1_port = client1_port_str ? atoi(client1_port_str) : 1883; int client2_port = client2_port_str ? atoi(client2_port_str) : 1882; - MqttClient *client_1 = + MqttClient *client_1 = new MqttClient(nullptr, client1_port, client_1_topics, mqttHost); connect(client_1, &MqttClient::emitServerData, this, &RaspberryModel::receiveServerData); @@ -116,9 +117,9 @@ void RaspberryModel::connectToMQTT() { QList client_2_topics = { FORWARDBUTTON, BACKWARDBUTTON, RIGHTBUTTON, ENTERBUTTON, UPBUTTON, DOWNBUTTON, HOMEBUTTON, MODEINDEX, - DIRECTION, REGENPOWER, TORQUEPOWER, + DIRECTION, TORQUEPOWER, }; - MqttClient *client_2 = + MqttClient *client_2 = new MqttClient(nullptr, client2_port, client_2_topics, mqttHost); connect(client_2, &MqttClient::emitServerData, this, &RaspberryModel::receiveServerData); @@ -168,6 +169,12 @@ std::optional RaspberryModel::getMotorTemp() { : std::nullopt; } +std::optional RaspberryModel::getMaxRegenCapacity() { + std::optional maxRegenCapacity = this->getById(MAXREGENCAPACITY); + return maxRegenCapacity ? std::optional(std::round(*maxRegenCapacity)) + : std::nullopt; +} + std::optional RaspberryModel::getStateOfCharge() { return this->getById(STATEOFCHARGE); } diff --git a/NERODevelopment/src/models/raspberry_model.h b/NERODevelopment/src/models/raspberry_model.h index da2e911..d39f51d 100644 --- a/NERODevelopment/src/models/raspberry_model.h +++ b/NERODevelopment/src/models/raspberry_model.h @@ -24,6 +24,7 @@ class RaspberryModel : public Model { std::optional getDir() override; std::optional getPackTemp() override; std::optional getMotorTemp() override; + std::optional getMaxRegenCapacity() override; std::optional getStateOfCharge() override; std::optional getCurrent() override; std::optional getBalancingCells() override; diff --git a/NERODevelopment/src/utils/data_type_names.h b/NERODevelopment/src/utils/data_type_names.h index eaca198..7b6f04d 100644 --- a/NERODevelopment/src/utils/data_type_names.h +++ b/NERODevelopment/src/utils/data_type_names.h @@ -7,6 +7,7 @@ #define DIRECTION "MPU/State/Direction" #define PACKTEMP "BMS/Status/Temp_Average" #define MOTORTEMP "DTI/Temps/Motor_Temperature" +#define MAXREGENCAPACITY "BMS/Commands/Max_DC_Brake_Current_Target" #define STATEOFCHARGE "BMS/Pack/SOC" #define CURRENT "DTI/Power/AC_Current" #define BALANCINGCELLS "balancingcells" @@ -31,7 +32,7 @@ #define INVERTERTEMP "invertertemp" #define MOTORPOWER "motorpower" #define FANPOWER "fanpower" -#define REGENPOWER "MPU/State/RegenLimit" +#define REGENPOWER "DTI/Power/DC_Current" #define BMSSTATE "bmsstate" #define BMSFAULT "BMS/Status/F/#" #define MPUFAULT "MPU/Fault/#"