diff options
author | Joshua Drake <joshua.drake@ditchwitch.com> | 2022-11-21 16:34:17 -0600 |
---|---|---|
committer | Joshua Drake <joshua.drake@ditchwitch.com> | 2022-11-21 16:34:17 -0600 |
commit | 179ed918aed1c9f190ae6846ea4bcccccbeab18f (patch) | |
tree | 1fabd0bbc20e102097eeecf18e2238f121629d0f | |
parent | 341e61f7a6f9deebf086a2b8147e252be6d45f33 (diff) |
Added Pre-Charge functionality and made thing prettier.
-rw-r--r-- | EVPC.pro | 4 | ||||
-rw-r--r-- | battery.cpp | 8 | ||||
-rw-r--r-- | battery.h | 3 | ||||
-rw-r--r-- | generator.cpp | 27 | ||||
-rw-r--r-- | generator.h | 26 | ||||
-rw-r--r-- | mainwindow.cpp | 233 | ||||
-rw-r--r-- | mainwindow.h | 27 | ||||
-rw-r--r-- | mainwindow.ui | 687 | ||||
-rw-r--r-- | precharge.cpp | 62 | ||||
-rw-r--r-- | precharge.h | 38 |
10 files changed, 999 insertions, 116 deletions
@@ -10,13 +10,17 @@ CONFIG += c++11 SOURCES += \ battery.cpp \ + generator.cpp \ main.cpp \ mainwindow.cpp \ + precharge.cpp \ wire.cpp HEADERS += \ battery.h \ + generator.h \ mainwindow.h \ + precharge.h \ wire.h FORMS += \ diff --git a/battery.cpp b/battery.cpp index e0b7c26..d4a8ae7 100644 --- a/battery.cpp +++ b/battery.cpp @@ -4,6 +4,7 @@ Battery::Battery() : activeBattery(batteries[LiionPhosphate]), systemVoltage(0), peakPower(0), + minimumAllowableSOC(0), packDischargeRate(0), packChargeRate(0), packWeight(0), @@ -26,6 +27,10 @@ void Battery::setPeakSystemPower(double power) { peakPower = power; } +void Battery::setMinimumSOC(double SOC) +{ + minimumAllowableSOC = SOC; +} void Battery::calculate() { @@ -43,7 +48,8 @@ int Battery::parallelCells(void) float Battery::minimumPackVoltage(void) { - return seriesCells()*activeBattery.minimumVoltage; + float min = seriesCells()*activeBattery.minimumVoltage; + return (min) + (maximumPackVoltage()-min)*(minimumAllowableSOC*0.01); } float Battery::maximumPackVoltage(void) @@ -40,6 +40,7 @@ public: void setSystemVoltage(double voltage); void setPeakSystemPower(double power); void changeBatteryChemistry(int name); + void setMinimumSOC(double SOC); int seriesCells(void); int parallelCells(void); @@ -53,11 +54,11 @@ private: batteryData_t activeBattery; double systemVoltage; double peakPower; + double minimumAllowableSOC; float packDischargeRate; float packChargeRate; float packWeight; float packEnergy; - signals: void calculation(void); diff --git a/generator.cpp b/generator.cpp new file mode 100644 index 0000000..07416b7 --- /dev/null +++ b/generator.cpp @@ -0,0 +1,27 @@ +#include "generator.h" + +Generator::Generator() : + RPM(0), + systemVoltage(0) +{ + +} + +void Generator::setRPM(double speed) +{ + RPM = speed; +} +void Generator::setSystemVoltage(double voltage) +{ + systemVoltage = voltage; +} + +void Generator::calculate() +{ + emit calculation(); +} + +double Generator::generatorKV() +{ + return RPM/systemVoltage; +} diff --git a/generator.h b/generator.h new file mode 100644 index 0000000..0aad560 --- /dev/null +++ b/generator.h @@ -0,0 +1,26 @@ +#ifndef GENERATOR_H +#define GENERATOR_H + +#include <QObject> + +class Generator : public QObject +{ + Q_OBJECT +public: + Generator(); + + void setRPM(double speed); + void setSystemVoltage(double voltage); + + double generatorKV(void); +public slots: + void calculate(void); +private: + double RPM; + double systemVoltage; +signals: + void calculation(void); + +}; + +#endif // GENERATOR_H diff --git a/mainwindow.cpp b/mainwindow.cpp index 62702cd..8559778 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -6,6 +6,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { + /*TODO fix crash after changing Voltage!!!! */ ui->setupUi(this); initializeGraphics(); @@ -19,6 +20,146 @@ MainWindow::MainWindow(QWidget *parent) ui->lineEditVoltageRange->setText(QString::number(m_battery.minimumPackVoltage())+" - "+QString::number(m_battery.maximumPackVoltage())); ui->lineEditPeakCurrent->setText(QString::number(m_battery.peakCurrent())); }); + + connect(&m_generator,&Generator::calculation, [&]() { + ui->lineEditGeneratorKV->setText(QString::number(m_generator.generatorKV())); + }); + + connect(&m_precharge,&Precharge::calculation, [&]() { + ui->lineEditMaximumPrechargeResistance->setText(QString::number(m_precharge.maximumResistance())); + ui->lineEditActualPreChargeTime->setText(QString::number(m_precharge.actualPreChargeTime())); + ui->lineEditPeakInRushCurrent->setText(QString::number(m_precharge.peakInRushCurrent())); + ui->lineEditAveragePreChargePower->setText(QString::number(m_precharge.averagePower())); + }); + + connect(ui->doubleSpinBoxPreChargePercentageDesired,static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), [=]() { + ui->lineEditActualPreChargeTime->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->lineEditAveragePreChargePower->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->lineEditMaximumPrechargeResistance->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->lineEditPeakInRushCurrent->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + + ui->labelActualPreChargeTime->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelAveragePreChargePower->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelMaxResistance->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelPeakInRushCurrent->setStyleSheet("color: rgb(0, 0, 0);"); + + ui->doubleSpinBoxChosenResistance->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->doubleSpinBoxPreChargePercentageDesired->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->doubleSpinBoxPreChargeTime->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->doubleSpinBoxSystemCapacitance->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + + ui->labelChosenResistance->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelPreChargePercentageDesired->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelDesiredPreChargeTime->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelSystemCapacitance->setStyleSheet("color: rgb(0, 0, 0);"); + + }); + + connect(ui->doubleSpinBoxSystemCapacitance,static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), [=]() { + ui->lineEditActualPreChargeTime->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->lineEditAveragePreChargePower->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->lineEditMaximumPrechargeResistance->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->lineEditPeakInRushCurrent->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + + ui->labelActualPreChargeTime->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelAveragePreChargePower->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelMaxResistance->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelPeakInRushCurrent->setStyleSheet("color: rgb(0, 0, 0);"); + + ui->labelActualPreChargeTime->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelAveragePreChargePower->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelMaxResistance->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelPeakInRushCurrent->setStyleSheet("color: rgb(0, 0, 0);"); + + ui->doubleSpinBoxChosenResistance->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->doubleSpinBoxPreChargePercentageDesired->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->doubleSpinBoxPreChargeTime->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->doubleSpinBoxSystemCapacitance->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + + ui->labelChosenResistance->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelPreChargePercentageDesired->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelDesiredPreChargeTime->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelSystemCapacitance->setStyleSheet("color: rgb(0, 0, 0);"); + + }); + + connect(ui->doubleSpinBoxPreChargeTime,static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), [=]() { + ui->lineEditActualPreChargeTime->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->lineEditAveragePreChargePower->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->lineEditMaximumPrechargeResistance->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->lineEditPeakInRushCurrent->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + + ui->labelActualPreChargeTime->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelAveragePreChargePower->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelMaxResistance->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelPeakInRushCurrent->setStyleSheet("color: rgb(0, 0, 0);"); + + ui->doubleSpinBoxChosenResistance->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->doubleSpinBoxPreChargePercentageDesired->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->doubleSpinBoxPreChargeTime->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->doubleSpinBoxSystemCapacitance->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + + ui->labelChosenResistance->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelPreChargePercentageDesired->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelDesiredPreChargeTime->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelSystemCapacitance->setStyleSheet("color: rgb(0, 0, 0);"); + + }); + + connect(ui->doubleSpinBoxChosenResistance,static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), [=]() { + ui->lineEditActualPreChargeTime->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->lineEditAveragePreChargePower->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->lineEditMaximumPrechargeResistance->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->lineEditPeakInRushCurrent->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + + ui->labelActualPreChargeTime->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelAveragePreChargePower->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelMaxResistance->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelPeakInRushCurrent->setStyleSheet("color: rgb(0, 0, 0);"); + + ui->doubleSpinBoxChosenResistance->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->doubleSpinBoxPreChargePercentageDesired->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->doubleSpinBoxPreChargeTime->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->doubleSpinBoxSystemCapacitance->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + + ui->labelChosenResistance->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelPreChargePercentageDesired->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelDesiredPreChargeTime->setStyleSheet("color: rgb(0, 0, 0);"); + ui->labelSystemCapacitance->setStyleSheet("color: rgb(0, 0, 0);"); + + }); } MainWindow::~MainWindow() @@ -65,6 +206,8 @@ void MainWindow::on_doubleSpinBoxSystemVoltage_valueChanged(double arg1) //m_wire.calculate(); m_battery.setSystemVoltage(arg1); m_battery.calculate(); + m_generator.setSystemVoltage(arg1); + m_generator.calculate(); } @@ -77,7 +220,95 @@ void MainWindow::on_doubleSpinBoxEstimatedWireLength_valueChanged(double arg1) void MainWindow::on_lineEditVoltageRange_textChanged(const QString &arg1) { - m_wire.setSystemVoltage((arg1.split(" -")[0]).toDouble()); + double min = arg1.split(" - ")[0].toDouble(); + double max = arg1.split(" - ")[1].toDouble(); + + m_wire.setSystemVoltage(min); m_wire.calculate(); + + m_precharge.setMaximumVoltage(max); + m_precharge.calculate(); +} + + +void MainWindow::on_doubleSpinBoxMinimumAllowableSOC_valueChanged(double arg1) +{ + m_battery.setMinimumSOC(arg1); + m_battery.calculate(); + if (arg1 > 0) + { + ui->doubleSpinBoxMinimumAllowableSOC->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->labelMinimumAllowableSOC->setStyleSheet("color: rgb(0, 0, 0);"); + } + else + { + ui->doubleSpinBoxMinimumAllowableSOC->setStyleSheet("background-color: rgba(255, 255, 255, 80);" + "color: rgba(0, 0, 0, 80);"); + ui->labelMinimumAllowableSOC->setStyleSheet("color: rgba(0, 0, 0, 120);"); + } +} + + +void MainWindow::on_doubleSpinBoxGeneratorRPM_valueChanged(double arg1) +{ + m_generator.setRPM(arg1); + m_generator.calculate(); + if (arg1 > 0) + { + ui->doubleSpinBoxGeneratorRPM->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->labelGeneratorRPM->setStyleSheet("color: rgb(0, 0, 0);"); + + ui->lineEditGeneratorKV->setStyleSheet("background-color: rgb(255, 255, 255);" + "color: rgb(0, 0, 0);"); + ui->labelGeneratorKV->setStyleSheet("color: rgb(0, 0, 0);"); + } + else + { + ui->doubleSpinBoxGeneratorRPM->setStyleSheet("background-color: rgba(255, 255, 255, 80);" + "color: rgba(0, 0, 0, 80);"); + ui->labelGeneratorRPM->setStyleSheet("color: rgba(0, 0, 0, 120);"); + + ui->lineEditGeneratorKV->setStyleSheet("background-color: rgba(255, 255, 255, 80);" + "color: rgba(0, 0, 0, 80);"); + ui->labelGeneratorKV->setStyleSheet("color: rgba(0, 0, 0, 120);"); + ui->lineEditGeneratorKV->setText("--"); + } +} + + +void MainWindow::on_doubleSpinBoxPreChargeTime_valueChanged(double arg1) +{ + m_precharge.setPreChargeTime(arg1); + m_precharge.calculate(); +} + + +void MainWindow::on_doubleSpinBoxSystemCapacitance_valueChanged(double arg1) +{ + m_precharge.setSystemCapacitance(arg1); + m_precharge.calculate(); +} + + +void MainWindow::on_doubleSpinBoxPreChargePercentageDesired_valueChanged(double arg1) +{ + m_precharge.setPreChargePercentage(arg1); + m_precharge.calculate(); +} + + +void MainWindow::on_doubleSpinBoxChosenResistance_valueChanged(double arg1) +{ + m_precharge.setChosenResistance(arg1); + m_precharge.calculate(); +} + + +void MainWindow::on_lineEditMaximumPrechargeResistance_textChanged(const QString &arg1) +{ + ui->doubleSpinBoxChosenResistance->setMaximum(arg1.toDouble()); + if(ui->doubleSpinBoxChosenResistance->value() > arg1.toDouble()) ui->doubleSpinBoxChosenResistance->setValue(arg1.toDouble()); } diff --git a/mainwindow.h b/mainwindow.h index f7f0b00..f8ce84e 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -5,8 +5,11 @@ #include <QSettings> #include <QString> #include <QComboBox> +#include <QDoubleSpinBox> #include "battery.h" #include "wire.h" +#include "generator.h" +#include "precharge.h" QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } @@ -19,6 +22,14 @@ class MainWindow : public QMainWindow public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); +private: + Battery m_battery; + Wire m_wire; + Generator m_generator; + Precharge m_precharge; + + Ui::MainWindow *ui; + void initializeGraphics(void); private slots: void on_spinBoxPeakSystemPower_valueChanged(double arg1); @@ -35,11 +46,17 @@ private slots: void on_lineEditVoltageRange_textChanged(const QString &arg1); -private: - Battery m_battery; - Wire m_wire; + void on_doubleSpinBoxMinimumAllowableSOC_valueChanged(double arg1); - Ui::MainWindow *ui; - void initializeGraphics(void); + void on_doubleSpinBoxGeneratorRPM_valueChanged(double arg1); + + void on_doubleSpinBoxPreChargeTime_valueChanged(double arg1); + + void on_doubleSpinBoxSystemCapacitance_valueChanged(double arg1); + + void on_doubleSpinBoxPreChargePercentageDesired_valueChanged(double arg1); + + void on_doubleSpinBoxChosenResistance_valueChanged(double arg1); + void on_lineEditMaximumPrechargeResistance_textChanged(const QString &arg1); }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index 5f0a180..4c47a92 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -6,16 +6,28 @@ <rect> <x>0</x> <y>0</y> - <width>800</width> - <height>600</height> + <width>1100</width> + <height>900</height> </rect> </property> - <property name="maximumSize"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Minimum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> <size> - <width>800</width> + <width>0</width> <height>600</height> </size> </property> + <property name="maximumSize"> + <size> + <width>1100</width> + <height>900</height> + </size> + </property> <property name="windowTitle"> <string>Electric Vehicle Parameter Calculator</string> </property> @@ -41,17 +53,41 @@ </property> <property name="maximumSize"> <size> - <width>800</width> - <height>545</height> + <width>1100</width> + <height>845</height> </size> </property> <layout class="QGridLayout" name="gridLayout"> <item row="0" column="0"> <widget class="QTabWidget" name="tabWidget"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Minimum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>0</width> + <height>600</height> + </size> + </property> <property name="currentIndex"> <number>0</number> </property> <widget class="QWidget" name="tabData"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Minimum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>0</width> + <height>600</height> + </size> + </property> <property name="toolTipDuration"> <number>-1</number> </property> @@ -62,7 +98,7 @@ <string>Data</string> </attribute> <layout class="QGridLayout" name="gridLayout_2"> - <item row="0" column="1" rowspan="2"> + <item row="0" column="2" rowspan="2"> <widget class="QGroupBox" name="groupElectricalOutputs"> <property name="toolTipDuration"> <number>-1</number> @@ -96,14 +132,25 @@ </property> </widget> </item> - <item row="3" column="1"> - <widget class="QLineEdit" name="lineEditWireGauge"> + <item row="1" column="0"> + <widget class="QLabel" name="labelVoltageRange"> + <property name="text"> + <string>Voltage Range:</string> + </property> + </widget> + </item> + <item row="9" column="1"> + <widget class="QLineEdit" name="lineEditActualPreChargeTime"> <property name="sizePolicy"> <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> + <property name="styleSheet"> + <string notr="true">background-color: rgba(255, 255, 255,80); +color: rgba(0, 0, 0,80);</string> + </property> <property name="alignment"> <set>Qt::AlignCenter</set> </property> @@ -112,41 +159,42 @@ </property> </widget> </item> - <item row="7" column="0"> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> + <item row="11" column="0"> + <widget class="QLabel" name="labelAveragePreChargePower"> + <property name="styleSheet"> + <string notr="true">color: rgba(0, 0, 0, 120);</string> </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> + <property name="text"> + <string>Average PreCharge Power:</string> </property> - </spacer> + </widget> </item> - <item row="5" column="0"> + <item row="6" column="0"> <widget class="QLabel" name="labelFuelAmount"> <property name="text"> <string>Fuel Quantity:</string> </property> </widget> </item> - <item row="3" column="0"> - <widget class="QLabel" name="labelWireGauge"> + <item row="4" column="0"> + <widget class="QLabel" name="labelWireWeight"> <property name="text"> - <string>Wire Gauge:</string> + <string>Wire Weight:</string> </property> </widget> </item> - <item row="4" column="1"> - <widget class="QLineEdit" name="lineEditWireWeight"> + <item row="10" column="1"> + <widget class="QLineEdit" name="lineEditPeakInRushCurrent"> <property name="sizePolicy"> <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> + <property name="styleSheet"> + <string notr="true">background-color: rgba(255, 255, 255,80); +color: rgba(0, 0, 0,80);</string> + </property> <property name="alignment"> <set>Qt::AlignCenter</set> </property> @@ -162,28 +210,158 @@ </property> </widget> </item> - <item row="5" column="1"> - <widget class="QLineEdit" name="lineEditFuelAmount"> + <item row="3" column="1"> + <widget class="QLineEdit" name="lineEditWireGauge"> <property name="sizePolicy"> <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> <property name="readOnly"> <bool>true</bool> </property> </widget> </item> - <item row="4" column="0"> - <widget class="QLabel" name="labelWireWeight"> + <item row="5" column="0"> + <widget class="QLabel" name="labelGeneratorKV"> + <property name="styleSheet"> + <string notr="true">color: rgba(0, 0, 0, 120);</string> + </property> <property name="text"> - <string>Wire Weight:</string> + <string>Generator KV:</string> </property> </widget> </item> - <item row="0" column="1"> - <widget class="QLineEdit" name="lineEditCellCount"> + <item row="11" column="1"> + <widget class="QLineEdit" name="lineEditAveragePreChargePower"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="styleSheet"> + <string notr="true">background-color: rgba(255, 255, 255,80); +color: rgba(0, 0, 0,80);</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="4" column="1"> + <widget class="QLineEdit" name="lineEditWireWeight"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLineEdit" name="lineEditVoltageRange"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>0 - 0</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="8" column="0"> + <widget class="QLabel" name="labelMaxResistance"> + <property name="styleSheet"> + <string notr="true">color: rgba(0, 0, 0, 120);</string> + </property> + <property name="text"> + <string>Maximum Resistance:</string> + </property> + </widget> + </item> + <item row="12" column="0"> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Expanding</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + <item row="8" column="1"> + <widget class="QLineEdit" name="lineEditMaximumPrechargeResistance"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="styleSheet"> + <string notr="true">background-color: rgba(255, 255, 255,80); +color: rgba(0, 0, 0,80);</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="5" column="1"> + <widget class="QLineEdit" name="lineEditGeneratorKV"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="styleSheet"> + <string notr="true">background-color: rgba(255, 255, 255,80); +color: rgba(0, 0, 0,80);</string> + </property> + <property name="text"> + <string>--</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="6" column="1"> + <widget class="QLineEdit" name="lineEditFuelAmount"> <property name="sizePolicy"> <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> <horstretch>0</horstretch> @@ -198,6 +376,16 @@ </property> </widget> </item> + <item row="9" column="0"> + <widget class="QLabel" name="labelActualPreChargeTime"> + <property name="styleSheet"> + <string notr="true">color: rgba(0, 0, 0, 120);</string> + </property> + <property name="text"> + <string>Actual Pre-Charge Time:</string> + </property> + </widget> + </item> <item row="2" column="0"> <widget class="QLabel" name="labelPeakCurrent"> <property name="toolTip"> @@ -214,15 +402,25 @@ </property> </widget> </item> - <item row="1" column="0"> - <widget class="QLabel" name="labelVoltageRange"> + <item row="3" column="0"> + <widget class="QLabel" name="labelWireGauge"> <property name="text"> - <string>Voltage Range:</string> + <string>Wire Gauge:</string> </property> </widget> </item> - <item row="1" column="1"> - <widget class="QLineEdit" name="lineEditVoltageRange"> + <item row="10" column="0"> + <widget class="QLabel" name="labelPeakInRushCurrent"> + <property name="styleSheet"> + <string notr="true">color: rgba(0, 0, 0, 120);</string> + </property> + <property name="text"> + <string>Peak Inrush Current:</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="lineEditCellCount"> <property name="sizePolicy"> <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> <horstretch>0</horstretch> @@ -237,10 +435,123 @@ </property> </widget> </item> + <item row="7" column="0" colspan="2"> + <widget class="QLabel" name="labelPreChargeDivider_2"> + <property name="styleSheet"> + <string notr="true">font: 10pt; +color: rgb(0, 0, 0);</string> + </property> + <property name="text"> + <string>Pre-Charge Circuit</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item row="0" column="1" rowspan="2"> + <widget class="QGroupBox" name="groupBoxMechanical"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="title"> + <string>Mechanical Inputs</string> + </property> + <layout class="QGridLayout" name="gridLayout_5"> + <item row="2" column="0"> + <widget class="QLabel" name="labelRunTime"> + <property name="text"> + <string>Run Time:</string> + </property> + </widget> + </item> + <item row="3" column="0"> + <widget class="QLabel" name="labelEnginePowerSource"> + <property name="frameShape"> + <enum>QFrame::NoFrame</enum> + </property> + <property name="text"> + <string><html><head/><body><p>Engine/Power Source:</p></body></html></string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QDoubleSpinBox" name="doubleSpinBoxRunTime"> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + <property name="buttonSymbols"> + <enum>QAbstractSpinBox::NoButtons</enum> + </property> + <property name="showGroupSeparator" stdset="0"> + <bool>false</bool> + </property> + <property name="decimals"> + <number>2</number> + </property> + <property name="maximum"> + <double>96.000000000000000</double> + </property> + <property name="value"> + <double>8.000000000000000</double> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QDoubleSpinBox" name="doubleSpinBoxVehicleWeight"> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + <property name="buttonSymbols"> + <enum>QAbstractSpinBox::NoButtons</enum> + </property> + <property name="decimals"> + <number>1</number> + </property> + <property name="maximum"> + <double>1000.000000000000000</double> + </property> + <property name="value"> + <double>100.000000000000000</double> + </property> + </widget> + </item> + <item row="3" column="1"> + <widget class="QComboBox" name="comboBoxEnginePowerSource"/> + </item> + <item row="0" column="0"> + <widget class="QLabel" name="labelVehicleWeight"> + <property name="text"> + <string>Vehicle Weight:</string> + </property> + </widget> + </item> + <item row="4" column="0"> + <spacer name="verticalSpacer_3"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Expanding</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> </layout> </widget> </item> - <item row="0" column="0"> + <item row="0" column="0" rowspan="2"> <widget class="QGroupBox" name="groupElectricalInputs"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> @@ -270,10 +581,45 @@ <property name="verticalSpacing"> <number>0</number> </property> - <item row="1" column="0"> - <widget class="QLabel" name="labelSystemVoltage"> + <item row="7" column="0" colspan="2"> + <widget class="QLabel" name="labelPreChargeDivider"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Minimum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="styleSheet"> + <string notr="true">font: 10pt; +color: rgb(0, 0, 0);</string> + </property> <property name="text"> - <string>System Voltage:</string> + <string>Pre-Charge Circuit</string> + </property> + <property name="alignment"> + <set>Qt::AlignHCenter|Qt::AlignTop</set> + </property> + </widget> + </item> + <item row="6" column="1"> + <widget class="QComboBox" name="comboBoxWireMaterial"/> + </item> + <item row="2" column="1"> + <widget class="QDoubleSpinBox" name="doubleSpinBoxEstimatedWireLength"> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + <property name="buttonSymbols"> + <enum>QAbstractSpinBox::NoButtons</enum> + </property> + <property name="decimals"> + <number>1</number> + </property> + <property name="maximum"> + <double>1000.000000000000000</double> + </property> + <property name="value"> + <double>0.000000000000000</double> </property> </widget> </item> @@ -299,29 +645,18 @@ </property> </widget> </item> - <item row="0" column="0"> - <widget class="QLabel" name="labelPeakSystemPower"> - <property name="text"> - <string>Peak System Power:</string> + <item row="9" column="0"> + <widget class="QLabel" name="labelSystemCapacitance"> + <property name="styleSheet"> + <string notr="true">color: rgba(0, 0, 0, 120);</string> </property> - </widget> - </item> - <item row="4" column="0"> - <widget class="QLabel" name="labelWireMaterial"> <property name="text"> - <string>Wire Material:</string> + <string>System Capacitance (uF):</string> </property> </widget> </item> - <item row="3" column="1"> - <widget class="QComboBox" name="comboBoxBatteryChemistry"> - <property name="editable"> - <bool>false</bool> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QDoubleSpinBox" name="doubleSpinBoxEstimatedWireLength"> + <item row="1" column="1"> + <widget class="QDoubleSpinBox" name="doubleSpinBoxSystemVoltage"> <property name="alignment"> <set>Qt::AlignCenter</set> </property> @@ -339,11 +674,12 @@ </property> </widget> </item> - <item row="4" column="1"> - <widget class="QComboBox" name="comboBoxWireMaterial"/> - </item> - <item row="1" column="1"> - <widget class="QDoubleSpinBox" name="doubleSpinBoxSystemVoltage"> + <item row="3" column="1"> + <widget class="QDoubleSpinBox" name="doubleSpinBoxMinimumAllowableSOC"> + <property name="styleSheet"> + <string notr="true">background-color: rgba(255, 255, 255,80); +color: rgba(0, 0, 0,80);</string> + </property> <property name="alignment"> <set>Qt::AlignCenter</set> </property> @@ -354,45 +690,47 @@ <number>1</number> </property> <property name="maximum"> - <double>1000.000000000000000</double> + <double>100.000000000000000</double> </property> - <property name="value"> - <double>0.000000000000000</double> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="labelSystemVoltage"> + <property name="text"> + <string>Nominal Voltage:</string> </property> </widget> </item> - <item row="2" column="0"> - <widget class="QLabel" name="labelEstimatedWireLength"> + <item row="0" column="0"> + <widget class="QLabel" name="labelPeakSystemPower"> <property name="text"> - <string>Estimated Wire Length:</string> + <string>Peak System Power:</string> </property> </widget> </item> - <item row="3" column="0"> - <widget class="QLabel" name="labelBatteryChemistry"> + <item row="10" column="0"> + <widget class="QLabel" name="labelPreChargePercentageDesired"> + <property name="styleSheet"> + <string notr="true">color: rgba(0, 0, 0, 120);</string> + </property> <property name="text"> - <string>Battery Chemistry:</string> + <string>Percentage Desired:</string> </property> </widget> </item> - </layout> - </widget> - </item> - <item row="1" column="0"> - <widget class="QGroupBox" name="groupBoxMechanical"> - <property name="title"> - <string>Mechanical Inputs</string> - </property> - <layout class="QGridLayout" name="gridLayout_5"> - <item row="0" column="0"> - <widget class="QLabel" name="labelVehicleWeight"> + <item row="5" column="0"> + <widget class="QLabel" name="labelBatteryChemistry"> <property name="text"> - <string>Vehicle Weight:</string> + <string>Battery Chemistry:</string> </property> </widget> </item> - <item row="0" column="1"> - <widget class="QDoubleSpinBox" name="doubleSpinBoxVehicleWeight"> + <item row="4" column="1"> + <widget class="QDoubleSpinBox" name="doubleSpinBoxGeneratorRPM"> + <property name="styleSheet"> + <string notr="true">background-color: rgba(255, 255, 255,80); +color: rgba(0, 0, 0,80);</string> + </property> <property name="alignment"> <set>Qt::AlignCenter</set> </property> @@ -400,57 +738,190 @@ <enum>QAbstractSpinBox::NoButtons</enum> </property> <property name="decimals"> - <number>1</number> + <number>0</number> </property> <property name="maximum"> - <double>1000.000000000000000</double> + <double>100000.000000000000000</double> + </property> + </widget> + </item> + <item row="10" column="1"> + <widget class="QDoubleSpinBox" name="doubleSpinBoxPreChargePercentageDesired"> + <property name="styleSheet"> + <string notr="true">background-color: rgba(255, 255, 255,80); +color: rgba(0, 0, 0,80);</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + <property name="buttonSymbols"> + <enum>QAbstractSpinBox::NoButtons</enum> + </property> + <property name="minimum"> + <double>0.010000000000000</double> + </property> + <property name="maximum"> + <double>99.989999999999995</double> </property> <property name="value"> - <double>100.000000000000000</double> + <double>0.010000000000000</double> </property> </widget> </item> - <item row="1" column="0"> - <widget class="QLabel" name="labelRunTime"> + <item row="8" column="0"> + <widget class="QLabel" name="labelDesiredPreChargeTime"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="contextMenuPolicy"> + <enum>Qt::NoContextMenu</enum> + </property> + <property name="styleSheet"> + <string notr="true">color: rgba(0, 0, 0, 120);</string> + </property> <property name="text"> - <string>Run Time:</string> + <string>Desired Pre-Charge Time:</string> + </property> + <property name="alignment"> + <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> </property> </widget> </item> - <item row="1" column="1"> - <widget class="QDoubleSpinBox" name="doubleSpinBoxRunTime"> + <item row="2" column="0"> + <widget class="QLabel" name="labelEstimatedWireLength"> + <property name="text"> + <string>Estimated Wire Length:</string> + </property> + </widget> + </item> + <item row="12" column="0"> + <spacer name="verticalSpacer_2"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + <item row="6" column="0"> + <widget class="QLabel" name="labelWireMaterial"> + <property name="text"> + <string>Wire Material:</string> + </property> + </widget> + </item> + <item row="5" column="1"> + <widget class="QComboBox" name="comboBoxBatteryChemistry"> + <property name="editable"> + <bool>false</bool> + </property> + </widget> + </item> + <item row="9" column="1"> + <widget class="QDoubleSpinBox" name="doubleSpinBoxSystemCapacitance"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="styleSheet"> + <string notr="true">background-color: rgba(255, 255, 255,80); +color: rgba(0, 0, 0,80);</string> + </property> <property name="alignment"> <set>Qt::AlignCenter</set> </property> <property name="buttonSymbols"> <enum>QAbstractSpinBox::NoButtons</enum> </property> - <property name="showGroupSeparator" stdset="0"> - <bool>false</bool> + <property name="suffix"> + <string extracomment="(uF)"/> </property> <property name="decimals"> - <number>2</number> + <number>3</number> </property> <property name="maximum"> - <double>96.000000000000000</double> + <double>10000.000000000000000</double> </property> - <property name="value"> - <double>8.000000000000000</double> + </widget> + </item> + <item row="4" column="0"> + <widget class="QLabel" name="labelGeneratorRPM"> + <property name="styleSheet"> + <string notr="true">color: rgba(0, 0, 0, 120);</string> + </property> + <property name="text"> + <string>Generator RPM:</string> </property> </widget> </item> - <item row="2" column="0"> - <widget class="QLabel" name="labelEnginePowerSource"> - <property name="frameShape"> - <enum>QFrame::NoFrame</enum> + <item row="3" column="0"> + <widget class="QLabel" name="labelMinimumAllowableSOC"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Minimum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="styleSheet"> + <string notr="true">color: rgba(0, 0, 0, 120);</string> </property> <property name="text"> - <string><html><head/><body><p>Engine/Power Source:</p></body></html></string> + <string>Minimum Allowable SOC:</string> </property> </widget> </item> - <item row="2" column="1"> - <widget class="QComboBox" name="comboBoxEnginePowerSource"/> + <item row="8" column="1"> + <widget class="QDoubleSpinBox" name="doubleSpinBoxPreChargeTime"> + <property name="styleSheet"> + <string notr="true">background-color: rgba(255, 255, 255,80); +color: rgba(0, 0, 0,80);</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + <property name="buttonSymbols"> + <enum>QAbstractSpinBox::NoButtons</enum> + </property> + <property name="maximum"> + <double>60.000000000000000</double> + </property> + </widget> + </item> + <item row="11" column="0"> + <widget class="QLabel" name="labelChosenResistance"> + <property name="styleSheet"> + <string notr="true">color: rgba(0, 0, 0, 120);</string> + </property> + <property name="text"> + <string>Chosen Resistance:</string> + </property> + <property name="alignment"> + <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item row="11" column="1"> + <widget class="QDoubleSpinBox" name="doubleSpinBoxChosenResistance"> + <property name="styleSheet"> + <string notr="true">background-color: rgba(255, 255, 255,80); +color: rgba(0, 0, 0,80);</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + <property name="buttonSymbols"> + <enum>QAbstractSpinBox::NoButtons</enum> + </property> + <property name="maximum"> + <double>10000.000000000000000</double> + </property> + </widget> </item> </layout> </widget> diff --git a/precharge.cpp b/precharge.cpp new file mode 100644 index 0000000..e19820b --- /dev/null +++ b/precharge.cpp @@ -0,0 +1,62 @@ +#include "precharge.h" +#include "QDebug" + +Precharge::Precharge() : + maximumVoltage(0), + preChargeTime(0), + preChargePercentage(100), + chosenResistance(0), + systemCapacitance(0) +{ + +} + +void Precharge::setMaximumVoltage(double voltage) +{ + maximumVoltage = voltage; +} +void Precharge::setPreChargeTime(double time) +{ + preChargeTime = time; +} +void Precharge::setPreChargePercentage(double percentage) +{ + preChargePercentage = percentage; +} +void Precharge::setSystemCapacitance(float capacitance) +{ + systemCapacitance = capacitance*std::pow(10,-6); //uF + qDebug() << systemCapacitance; +} + +void Precharge::setChosenResistance(double resistance) +{ + chosenResistance = resistance; +} + +void Precharge::calculate() +{ + emit calculation(); +} + +double Precharge::maximumResistance(void) +{ + return preChargeTime/(-std::log(1-(preChargePercentage*0.01))*systemCapacitance); +} + +double Precharge::actualPreChargeTime(void) +{ + return (-std::log(1-(preChargePercentage*0.01)))*chosenResistance*systemCapacitance; +} + +double Precharge::peakInRushCurrent(void) +{ + return maximumVoltage/chosenResistance; +} + +double Precharge::averagePower(void) +{ + return (((systemCapacitance*std::pow(maximumVoltage,2))/2)*(1-exp((-2*actualPreChargeTime())/(chosenResistance*systemCapacitance))))/actualPreChargeTime(); +} + + diff --git a/precharge.h b/precharge.h new file mode 100644 index 0000000..376b067 --- /dev/null +++ b/precharge.h @@ -0,0 +1,38 @@ +#ifndef PRECHARGE_H +#define PRECHARGE_H + +#include <QObject> +#include <QtMath> + +class Precharge : public QObject +{ + Q_OBJECT +public: + Precharge(); + + void setMaximumVoltage(double voltage); + void setPreChargeTime(double time); + void setPreChargePercentage(double percentage); + void setSystemCapacitance(float capacitance); + void setChosenResistance(double resistance); + + double maximumResistance(void); + double actualPreChargeTime(void); + double peakInRushCurrent(void); + double averagePower(void); +public slots: + void calculate(void); + +private: + double maximumVoltage; + double preChargeTime; + double preChargePercentage; + double chosenResistance; + float systemCapacitance; + +signals: + void calculation(void); + +}; + +#endif // PRECHARGE_H |