From 341e61f7a6f9deebf086a2b8147e252be6d45f33 Mon Sep 17 00:00:00 2001 From: Joshua Drake Date: Mon, 21 Nov 2022 02:03:46 -0600 Subject: Added new UI elements and brushed up calculations. --- .gitignore | 73 +++++++++++++++++++++ EVPC.pro.user | 5 +- battery.cpp | 26 +++++++- battery.h | 26 +++++--- mainwindow.cpp | 21 +++++- mainwindow.h | 2 + mainwindow.ui | 197 +++++++++++++++++++++++++++++++++++---------------------- wire.cpp | 6 +- wire.h | 1 - 9 files changed, 260 insertions(+), 97 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fab7372 --- /dev/null +++ b/.gitignore @@ -0,0 +1,73 @@ +# This file is used to ignore files which are generated +# ---------------------------------------------------------------------------- + +*~ +*.autosave +*.a +*.core +*.moc +*.o +*.obj +*.orig +*.rej +*.so +*.so.* +*_pch.h.cpp +*_resource.rc +*.qm +.#* +*.*# +core +!core/ +tags +.DS_Store +.directory +*.debug +Makefile* +*.prl +*.app +moc_*.cpp +ui_*.h +qrc_*.cpp +Thumbs.db +*.res +*.rc +/.qmake.cache +/.qmake.stash + +# qtcreator generated files +*.pro.user* + +# xemacs temporary files +*.flc + +# Vim temporary files +.*.swp + +# Visual Studio generated files +*.ib_pdb_index +*.idb +*.ilk +*.pdb +*.sln +*.suo +*.vcproj +*vcproj.*.*.user +*.ncb +*.sdf +*.opensdf +*.vcxproj +*vcxproj.* + +# MinGW generated files +*.Debug +*.Release + +# Python byte code +*.pyc + +# Binaries +# -------- +*.dll +*.exe + diff --git a/EVPC.pro.user b/EVPC.pro.user index 2dc6b5d..9d7d6d3 100644 --- a/EVPC.pro.user +++ b/EVPC.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -85,6 +85,9 @@ true + + true + diff --git a/battery.cpp b/battery.cpp index b38a0ac..e0b7c26 100644 --- a/battery.cpp +++ b/battery.cpp @@ -2,8 +2,6 @@ Battery::Battery() : activeBattery(batteries[LiionPhosphate]), - seriesCells(0), - parallelCells(0), systemVoltage(0), peakPower(0), packDischargeRate(0), @@ -31,7 +29,29 @@ void Battery::setPeakSystemPower(double power) void Battery::calculate() { - seriesCells = ceil(systemVoltage/activeBattery.nominalVoltage); + emit calculation(); +} + +int Battery::seriesCells(void) +{ + return ceil(systemVoltage/activeBattery.nominalVoltage); +} +int Battery::parallelCells(void) +{ + //return ceil(peakPower); +} +float Battery::minimumPackVoltage(void) +{ + return seriesCells()*activeBattery.minimumVoltage; +} + +float Battery::maximumPackVoltage(void) +{ + return seriesCells()*activeBattery.maximumVoltage; +} +double Battery::peakCurrent() +{ + return peakPower/minimumPackVoltage(); } diff --git a/battery.h b/battery.h index 6c0ed44..4c80917 100644 --- a/battery.h +++ b/battery.h @@ -7,18 +7,20 @@ typedef struct batteryData { QString name; double nominalVoltage; + double minimumVoltage; + double maximumVoltage; double specificEnergy; // Wh/Kg - float cellDischargeRate; - float cellChargeRate; + double cellDischargeRate; + double cellChargeRate; }batteryData_t; static const batteryData_t batteries[] { - {.name = "Li-ion Phosphate", .nominalVoltage = 3.3, .specificEnergy = 105.0, .cellDischargeRate = 30, .cellChargeRate = 10}, - {.name = "Li-ion Manganese", .nominalVoltage = 3.7, .specificEnergy = 125.0, .cellDischargeRate = 30, .cellChargeRate = 10}, - {.name = "Li-ion Cobalt", .nominalVoltage = 3.6, .specificEnergy = 200.0, .cellDischargeRate = 2, .cellChargeRate = 1}, - {.name = "NiMH", .nominalVoltage = 1.2, .specificEnergy = 90.0, .cellDischargeRate = 5, .cellChargeRate = 0.5}, - {.name = "NiCd", .nominalVoltage = 1.2, .specificEnergy = 60.0, .cellDischargeRate = 20, .cellChargeRate = 1}, + {.name = "Li-ion Phosphate", .nominalVoltage = 3.3, .minimumVoltage = 2.5, .maximumVoltage = 3.6, .specificEnergy = 105.0, .cellDischargeRate = 30, .cellChargeRate = 10}, + {.name = "Li-ion Manganese", .nominalVoltage = 3.7, .minimumVoltage = 2.5, .maximumVoltage = 4.2, .specificEnergy = 125.0, .cellDischargeRate = 30, .cellChargeRate = 10}, + {.name = "Li-ion Cobalt", .nominalVoltage = 3.6, .minimumVoltage = 2.5, .maximumVoltage = 4.2, .specificEnergy = 200.0, .cellDischargeRate = 2, .cellChargeRate = 1}, + {.name = "NiMH", .nominalVoltage = 1.2, .minimumVoltage = 1.0, .maximumVoltage = 1.3, .specificEnergy = 90.0, .cellDischargeRate = 5, .cellChargeRate = 0.5}, + {.name = "NiCd", .nominalVoltage = 1.2, .minimumVoltage = 1.0, .maximumVoltage = 1.3, .specificEnergy = 60.0, .cellDischargeRate = 20, .cellChargeRate = 1}, }; enum batteryNames { @@ -38,20 +40,26 @@ public: void setSystemVoltage(double voltage); void setPeakSystemPower(double power); void changeBatteryChemistry(int name); + + int seriesCells(void); + int parallelCells(void); + float minimumPackVoltage(void); + float maximumPackVoltage(void); + double peakCurrent(void); public slots: void calculate(void); private: batteryData_t activeBattery; - int seriesCells; - int parallelCells; double systemVoltage; double peakPower; float packDischargeRate; float packChargeRate; float packWeight; float packEnergy; + signals: + void calculation(void); }; diff --git a/mainwindow.cpp b/mainwindow.cpp index 44a3a2e..62702cd 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -12,7 +12,12 @@ MainWindow::MainWindow(QWidget *parent) connect(&m_wire,&Wire::calculation, [&]() { ui->lineEditWireGauge->setText(m_wire.gauge()); ui->lineEditWireWeight->setText(QString::number(m_wire.weight())); - ui->lineEditPeakCurrent->setText(QString::number(m_wire.peakCurrent())); + }); + + connect(&m_battery,&Battery::calculation, [&]() { + ui->lineEditCellCount->setText(QString::number(m_battery.seriesCells())+"S"); + ui->lineEditVoltageRange->setText(QString::number(m_battery.minimumPackVoltage())+" - "+QString::number(m_battery.maximumPackVoltage())); + ui->lineEditPeakCurrent->setText(QString::number(m_battery.peakCurrent())); }); } @@ -27,6 +32,7 @@ void MainWindow::on_spinBoxPeakSystemPower_valueChanged(double arg1) m_wire.setPeakSystemPower(arg1); m_wire.calculate(); m_battery.setPeakSystemPower(arg1); + m_battery.calculate(); } void MainWindow :: initializeGraphics() @@ -38,6 +44,7 @@ void MainWindow :: initializeGraphics() void MainWindow::on_comboBoxBatteryChemistry_currentIndexChanged(int index) { m_battery.changeBatteryChemistry(index); + m_battery.calculate(); } @@ -54,9 +61,10 @@ void MainWindow::on_comboBoxWireMaterial_currentIndexChanged(int index) void MainWindow::on_doubleSpinBoxSystemVoltage_valueChanged(double arg1) { - m_wire.setSystemVoltage(arg1); - m_wire.calculate(); + //m_wire.setSystemVoltage(arg1); + //m_wire.calculate(); m_battery.setSystemVoltage(arg1); + m_battery.calculate(); } @@ -66,3 +74,10 @@ void MainWindow::on_doubleSpinBoxEstimatedWireLength_valueChanged(double arg1) m_wire.calculate(); } + +void MainWindow::on_lineEditVoltageRange_textChanged(const QString &arg1) +{ + m_wire.setSystemVoltage((arg1.split(" -")[0]).toDouble()); + m_wire.calculate(); +} + diff --git a/mainwindow.h b/mainwindow.h index 359faf5..f7f0b00 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -33,6 +33,8 @@ private slots: void on_doubleSpinBoxEstimatedWireLength_valueChanged(double arg1); + void on_lineEditVoltageRange_textChanged(const QString &arg1); + private: Battery m_battery; Wire m_wire; diff --git a/mainwindow.ui b/mainwindow.ui index 0755bb5..5f0a180 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -71,27 +71,7 @@ Outputs - - - - Peak Current: - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - + @@ -99,6 +79,15 @@ 0 + + + + + 10000 + + + + Qt::AlignCenter @@ -107,7 +96,7 @@ - + @@ -123,15 +112,35 @@ + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Fuel Quantity: + + + - + - Wire Weight: + Wire Gauge: - - + + 0 @@ -146,8 +155,35 @@ - - + + + + Cell Count: + + + + + + + + 0 + 0 + + + + true + + + + + + + Wire Weight: + + + + + 0 @@ -163,34 +199,39 @@ - - - Wire Gauge: + + + + + + 10000 + + + - - - - - Cell Count: + Peak Current: - - + + - Fuel Quantity: + Voltage Range: - - + + 0 0 + + Qt::AlignCenter + true @@ -201,6 +242,12 @@ + + + 0 + 0 + + Electrical Inputs @@ -230,6 +277,28 @@ + + + + Qt::AlignCenter + + + QAbstractSpinBox::NoButtons + + + 1 + + + 100000.000000000000000 + + + QAbstractSpinBox::DefaultStepType + + + 0.000000000000000 + + + @@ -237,10 +306,10 @@ - - + + - Battery Chemistry: + Wire Material: @@ -251,8 +320,8 @@ - - + + Qt::AlignCenter @@ -263,16 +332,16 @@ 1 - 100000.000000000000000 - - - QAbstractSpinBox::DefaultStepType + 1000.000000000000000 0.000000000000000 + + + @@ -299,35 +368,13 @@ - - - - Qt::AlignCenter - - - QAbstractSpinBox::NoButtons - - - 1 - - - 1000.000000000000000 - - - 0.000000000000000 - - - - - + + - Wire Material: + Battery Chemistry: - - - diff --git a/wire.cpp b/wire.cpp index bc7a7c1..f7e776b 100644 --- a/wire.cpp +++ b/wire.cpp @@ -33,7 +33,7 @@ void Wire::calculate() { float current = peakPower/systemVoltage; int count = 0; - switch (std::distance(wireMaterials, std::find(wireMaterials,wireMaterials+sizeof(wireMaterials),activeWire))) + switch (std::distance(wireMaterials, std::find(wireMaterials,wireMaterials+sizeof(wireMaterials),activeWire))) //Decide upon Wire Gauge based on Max Current. { case Copper: { @@ -75,9 +75,5 @@ double Wire::weight() return (wireLength * activeWireData.weight)/1000.0; } -double Wire::peakCurrent() -{ - return peakPower/systemVoltage; -} diff --git a/wire.h b/wire.h index c54eed0..0dea79a 100644 --- a/wire.h +++ b/wire.h @@ -89,7 +89,6 @@ public: QString gauge(void); double weight(void); - double peakCurrent(void); public slots: void calculate(void); private: -- cgit v1.2.3