From 1321168cb22a76df96d747194fcb91863e4e0659 Mon Sep 17 00:00:00 2001 From: Joshua Drake Date: Sat, 19 Nov 2022 04:04:00 -0600 Subject: Added Wire Class. Program now has some functionality! --- EVPC.pro | 6 ++-- EVPC.pro.user | 87 +++++++++------------------------------------ battery.cpp | 2 +- battery.h | 4 +-- mainwindow.cpp | 31 +++++++++++++++- mainwindow.h | 10 ++++++ mainwindow.ui | 8 ++--- wire.cpp | 83 +++++++++++++++++++++++++++++++++++++++++++ wire.h | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 259 insertions(+), 81 deletions(-) create mode 100644 wire.cpp create mode 100644 wire.h diff --git a/EVPC.pro b/EVPC.pro index fc1919d..e85997b 100644 --- a/EVPC.pro +++ b/EVPC.pro @@ -11,11 +11,13 @@ CONFIG += c++11 SOURCES += \ battery.cpp \ main.cpp \ - mainwindow.cpp + mainwindow.cpp \ + wire.cpp HEADERS += \ battery.h \ - mainwindow.h + mainwindow.h \ + wire.h FORMS += \ mainwindow.ui diff --git a/EVPC.pro.user b/EVPC.pro.user index 7dccbb4..2dc6b5d 100644 --- a/EVPC.pro.user +++ b/EVPC.pro.user @@ -1,10 +1,10 @@ - + EnvironmentId - {254b9858-411f-4b26-805e-af190719973f} + {6ed2407f-5854-4365-9f0b-f053a9465641} ProjectExplorer.Project.ActiveTarget @@ -79,7 +79,7 @@ true true Builtin.DefaultTidyAndClazy - 4 + 6 @@ -91,16 +91,16 @@ ProjectExplorer.Project.Target.0 Desktop - Desktop Qt 5.12.11 MinGW 64-bit - Desktop Qt 5.12.11 MinGW 64-bit - qt.qt5.51211.win64_mingw73_kit + Desktop Qt 5.12.12 MinGW 64-bit + Desktop Qt 5.12.12 MinGW 64-bit + qt.qt5.51212.win64_mingw73_kit 0 0 0 0 - C:\Users\30720.DITCHWITCH\Desktop\Programming\build-EVPC-Desktop_Qt_5_12_11_MinGW_64_bit-Debug - C:/Users/30720.DITCHWITCH/Desktop/Programming/build-EVPC-Desktop_Qt_5_12_11_MinGW_64_bit-Debug + C:\Users\Josh\Documents\build-EVPC-Desktop_Qt_5_12_12_MinGW_64_bit-Debug + C:/Users/Josh/Documents/build-EVPC-Desktop_Qt_5_12_12_MinGW_64_bit-Debug true @@ -137,8 +137,8 @@ 2 - C:\Users\30720.DITCHWITCH\Desktop\Programming\build-EVPC-Desktop_Qt_5_12_11_MinGW_64_bit-Release - C:/Users/30720.DITCHWITCH/Desktop/Programming/build-EVPC-Desktop_Qt_5_12_11_MinGW_64_bit-Release + C:\Users\Josh\Documents\build-EVPC-Desktop_Qt_5_12_12_MinGW_64_bit-Release + C:/Users/Josh/Documents/build-EVPC-Desktop_Qt_5_12_12_MinGW_64_bit-Release true @@ -177,8 +177,8 @@ 0 - C:\Users\30720.DITCHWITCH\Desktop\Programming\build-EVPC-Desktop_Qt_5_12_11_MinGW_64_bit-Profile - C:/Users/30720.DITCHWITCH/Desktop/Programming/build-EVPC-Desktop_Qt_5_12_11_MinGW_64_bit-Profile + C:\Users\Josh\Documents\build-EVPC-Desktop_Qt_5_12_12_MinGW_64_bit-Profile + C:/Users/Josh/Documents/build-EVPC-Desktop_Qt_5_12_12_MinGW_64_bit-Profile true @@ -231,75 +231,20 @@ 1 - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F true - 4096 - false - false - 1000 - true - - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - - 25 - - 1 true - false - true - - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - 2 - ProjectExplorer.CustomExecutableRunConfiguration - + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/Josh/Documents/EVPC/EVPC.pro + C:/Users/Josh/Documents/EVPC/EVPC.pro false true + true false true + C:/Users/Josh/Documents/build-EVPC-Desktop_Qt_5_12_12_MinGW_64_bit-Debug 1 diff --git a/battery.cpp b/battery.cpp index 5be2fc8..b38a0ac 100644 --- a/battery.cpp +++ b/battery.cpp @@ -1,7 +1,7 @@ #include "battery.h" Battery::Battery() : - activeBattery(batteries[0]), + activeBattery(batteries[LiionPhosphate]), seriesCells(0), parallelCells(0), systemVoltage(0), diff --git a/battery.h b/battery.h index 887fb0e..6c0ed44 100644 --- a/battery.h +++ b/battery.h @@ -38,6 +38,8 @@ public: void setSystemVoltage(double voltage); void setPeakSystemPower(double power); void changeBatteryChemistry(int name); +public slots: + void calculate(void); private: batteryData_t activeBattery; @@ -49,8 +51,6 @@ private: float packChargeRate; float packWeight; float packEnergy; - - void calculate(void); signals: }; diff --git a/mainwindow.cpp b/mainwindow.cpp index 6fb2bf5..44a3a2e 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -8,6 +8,12 @@ MainWindow::MainWindow(QWidget *parent) { ui->setupUi(this); initializeGraphics(); + + 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())); + }); } MainWindow::~MainWindow() @@ -18,12 +24,15 @@ MainWindow::~MainWindow() void MainWindow::on_spinBoxPeakSystemPower_valueChanged(double arg1) { - + m_wire.setPeakSystemPower(arg1); + m_wire.calculate(); + m_battery.setPeakSystemPower(arg1); } void MainWindow :: initializeGraphics() { for(auto entry : batteries)ui->comboBoxBatteryChemistry->addItem(entry.name); + for(auto entry : wireMaterials)ui->comboBoxWireMaterial->addItem(entry); } void MainWindow::on_comboBoxBatteryChemistry_currentIndexChanged(int index) @@ -37,3 +46,23 @@ void MainWindow::on_actionactionSettings_triggered() } +void MainWindow::on_comboBoxWireMaterial_currentIndexChanged(int index) +{ + m_wire.setActiveWireType(index); + m_wire.calculate(); +} + +void MainWindow::on_doubleSpinBoxSystemVoltage_valueChanged(double arg1) +{ + m_wire.setSystemVoltage(arg1); + m_wire.calculate(); + m_battery.setSystemVoltage(arg1); +} + + +void MainWindow::on_doubleSpinBoxEstimatedWireLength_valueChanged(double arg1) +{ + m_wire.setWireLength(arg1); + m_wire.calculate(); +} + diff --git a/mainwindow.h b/mainwindow.h index 0add526..359faf5 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -3,7 +3,10 @@ #include #include +#include +#include #include "battery.h" +#include "wire.h" QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } @@ -24,8 +27,15 @@ private slots: void on_actionactionSettings_triggered(); + void on_comboBoxWireMaterial_currentIndexChanged(int index); + + void on_doubleSpinBoxSystemVoltage_valueChanged(double arg1); + + void on_doubleSpinBoxEstimatedWireLength_valueChanged(double arg1); + private: Battery m_battery; + Wire m_wire; Ui::MainWindow *ui; void initializeGraphics(void); diff --git a/mainwindow.ui b/mainwindow.ui index c7a03c8..0755bb5 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -269,7 +269,7 @@ QAbstractSpinBox::DefaultStepType - 1000.000000000000000 + 0.000000000000000 @@ -288,7 +288,7 @@ 1000.000000000000000 - 100.000000000000000 + 0.000000000000000 @@ -300,7 +300,7 @@ - + Qt::AlignCenter @@ -314,7 +314,7 @@ 1000.000000000000000 - 100.000000000000000 + 0.000000000000000 diff --git a/wire.cpp b/wire.cpp new file mode 100644 index 0000000..bc7a7c1 --- /dev/null +++ b/wire.cpp @@ -0,0 +1,83 @@ +#include "wire.h" +#include "QDebug" +Wire::Wire() : + activeWireData(copper[0]), + activeWire(wireMaterials[Copper]), + systemVoltage(0.0), + peakPower(0.0), + wireLength(0.0) +{ + +} + +void Wire::setActiveWireType(int wire) +{ + activeWire = wireMaterials[wire]; +} + +void Wire::setWireLength(float length) +{ + wireLength = length; +} +void Wire::setSystemVoltage(double voltage) +{ + systemVoltage = voltage; +} + +void Wire::setPeakSystemPower(double power) +{ + peakPower = power; +} + +void Wire::calculate() +{ + float current = peakPower/systemVoltage; + int count = 0; + switch (std::distance(wireMaterials, std::find(wireMaterials,wireMaterials+sizeof(wireMaterials),activeWire))) + { + case Copper: +{ + while(current < copper[count].maxCurrent) + { + activeWireData = copper[count]; + count++; + } + break; +} + case Aluminum: +{ + break; +} + case Silver: +{ + break; +} + case Gold: +{ + break; +} + case Tin: +{ + break; +} + } + qDebug() << activeWireData.AWG; + emit calculation(); +} + +QString Wire::gauge() +{ + return activeWireData.AWG; +} + +double Wire::weight() +{ + return (wireLength * activeWireData.weight)/1000.0; +} + +double Wire::peakCurrent() +{ + return peakPower/systemVoltage; +} + + diff --git a/wire.h b/wire.h new file mode 100644 index 0000000..c54eed0 --- /dev/null +++ b/wire.h @@ -0,0 +1,109 @@ +#ifndef WIRE_H +#define WIRE_H + +#include +#include +#include + +typedef struct wireData { + QString AWG; + double diameter; + double resistance; // Ohms/1000ft. + double maxCurrent; + float weight; // lb/1000ft. +}wireData_t; + +static const wireData_t copper[] +{ + {.AWG = "OOOO", .diameter = 0.46, .resistance = 0.04901, .maxCurrent = 260, .weight = 640.5}, + {.AWG = "OOO", .diameter = 0.4096, .resistance = 0.0618, .maxCurrent = 225, .weight = 507.9}, + {.AWG = "OO", .diameter = 0.3648, .resistance = 0.07793, .maxCurrent = 195, .weight = 402.8}, + {.AWG = "0", .diameter = 0.3249, .resistance = 0.09827, .maxCurrent = 170, .weight = 319.5}, + {.AWG = "1", .diameter = 0.2893, .resistance = 0.1239, .maxCurrent = 145, .weight = 253.5}, + {.AWG = "2", .diameter = 0.2576, .resistance = 0.1563, .maxCurrent = 130, .weight = 200.9}, + {.AWG = "3", .diameter = 0.2294, .resistance = 0.1970, .maxCurrent = 115, .weight = 159.3}, + {.AWG = "4", .diameter = 0.2043, .resistance = 0.2485, .maxCurrent = 95, .weight = 126.4}, + {.AWG = "5", .diameter = 0.1819, .resistance = 0.3133, .maxCurrent = 87, .weight = 100.2}, + {.AWG = "6", .diameter = 0.1620, .resistance = 0.3951, .maxCurrent = 75, .weight = 79.46}, + {.AWG = "7", .diameter = 0.1443, .resistance = 0.4982, .maxCurrent = 67, .weight = 63.02}, + {.AWG = "8", .diameter = 0.1285, .resistance = 0.6282, .maxCurrent = 55, .weight = 46.97}, + {.AWG = "9", .diameter = 0.1144, .resistance = 0.7921, .maxCurrent = 50, .weight = 39.63}, + {.AWG = "10", .diameter = 0.1019, .resistance = 0.9989, .maxCurrent = 40, .weight = 31.43}, + {.AWG = "11", .diameter = 0.0907, .resistance = 1.260, .maxCurrent = 37, .weight = 24.92}, + {.AWG = "12", .diameter = 0.0808, .resistance = 1.588, .maxCurrent = 30, .weight = 19.77}, + {.AWG = "13", .diameter = 0.0720, .resistance = 2.003, .maxCurrent = 28, .weight = 15.68}, + {.AWG = "14", .diameter = 0.0641, .resistance = 2.525, .maxCurrent = 25, .weight = 12.43}, + {.AWG = "15", .diameter = 0.0571, .resistance = 3.184, .maxCurrent = 24, .weight = 9.858}, + {.AWG = "16", .diameter = 0.0508, .resistance = 4.016, .maxCurrent = 22, .weight = 7.818}, + {.AWG = "17", .diameter = 0.0453, .resistance = 5.064, .maxCurrent = 19, .weight = 6.20}, + {.AWG = "18", .diameter = 0.0403, .resistance = 6.385, .maxCurrent = 16, .weight = 4.917}, + {.AWG = "19", .diameter = 0.0359, .resistance = 8.051, .maxCurrent = 14, .weight = 3.899}, + {.AWG = "20", .diameter = 0.0320, .resistance = 10.15, .maxCurrent = 11, .weight = 3.092}, + {.AWG = "21", .diameter = 0.0285, .resistance = 12.80, .maxCurrent = 9, .weight = 2.452}, + {.AWG = "22", .diameter = 0.0253, .resistance = 16.14, .maxCurrent = 7, .weight = 1.945}, + {.AWG = "23", .diameter = 0.0226, .resistance = 20.36, .maxCurrent = 4.7, .weight = 1.542}, + {.AWG = "24", .diameter = 0.0201, .resistance = 25.67, .maxCurrent = 3.5, .weight = 1.233}, + {.AWG = "25", .diameter = 0.0179, .resistance = 32.37, .maxCurrent = 2.7, .weight = 0.9699}, + {.AWG = "26", .diameter = 0.0159, .resistance = 40.81, .maxCurrent = 2.2, .weight = 0.7692}, + {.AWG = "27", .diameter = 0.0142, .resistance = 51.47, .maxCurrent = 1.7, .weight = 0.6100}, + {.AWG = "28", .diameter = 0.0126, .resistance = 64.90, .maxCurrent = 1.4, .weight = 0.4837}, + {.AWG = "29", .diameter = 0.0113, .resistance = 81.84, .maxCurrent = 1.2, .weight = 0.3863}, + {.AWG = "30", .diameter = 0.0100, .resistance = 103.2, .maxCurrent = 0.86, .weight = 0.3042}, + {.AWG = "31", .diameter = 0.00893, .resistance = 130.1, .maxCurrent = 0.7, .weight = 0.2413}, + {.AWG = "32", .diameter = 0.00795, .resistance = 164.1, .maxCurrent = 0.53, .weight = 0.1913}, + {.AWG = "33", .diameter = 0.00708, .resistance = 206.9, .maxCurrent = 0.43, .weight = 0.1517}, + {.AWG = "34", .diameter = 0.00630, .resistance = 260.9, .maxCurrent = 0.33, .weight = 0.1203}, + {.AWG = "35", .diameter = 0.00561, .resistance = 329.0, .maxCurrent = 0.27, .weight = 0.09542}, + {.AWG = "36", .diameter = 0.00500, .resistance = 414.8, .maxCurrent = 0.21, .weight = 0.07567}, + {.AWG = "37", .diameter = 0.00445, .resistance = 523.1, .maxCurrent = 0.17, .weight = 0.06001}, + {.AWG = "38", .diameter = 0.00397, .resistance = 659.6, .maxCurrent = 0.13, .weight = 0.044759}, + {.AWG = "39", .diameter = 0.00353, .resistance = 831.8, .maxCurrent = 0.11, .weight = 0.03744}, + {.AWG = "40", .diameter = 0.00314, .resistance = 1049, .maxCurrent = 0.09, .weight = 0.02993} +}; + +static const QString wireMaterials[] +{ + "Copper", + "Aluminum", + "Silver", + "Gold", + "Tin", +}; +enum wireNames +{ + Copper = 0, + Aluminum, + Silver, + Gold, + Tin, +}; +class Wire : public QObject +{ + Q_OBJECT +public: + Wire(); + void setActiveWireType(int wire); + void setWireLength(float length); + void setSystemVoltage(double voltage); + void setPeakSystemPower(double power); + + QString gauge(void); + double weight(void); + double peakCurrent(void); +public slots: + void calculate(void); +private: + wireData_t activeWireData; + QString activeWire; + double systemVoltage; + double peakPower; + double wireLength; + + void determineGauge(void); + +signals: + void calculation(void); + +}; + +#endif // WIRE_H -- cgit v1.2.3