From 179ed918aed1c9f190ae6846ea4bcccccbeab18f Mon Sep 17 00:00:00 2001 From: Joshua Drake Date: Mon, 21 Nov 2022 16:34:17 -0600 Subject: Added Pre-Charge functionality and made thing prettier. --- EVPC.pro | 4 + battery.cpp | 8 +- battery.h | 3 +- generator.cpp | 27 +++ generator.h | 26 +++ mainwindow.cpp | 233 ++++++++++++++++++- mainwindow.h | 27 ++- mainwindow.ui | 687 ++++++++++++++++++++++++++++++++++++++++++++++++--------- precharge.cpp | 62 ++++++ precharge.h | 38 ++++ 10 files changed, 999 insertions(+), 116 deletions(-) create mode 100644 generator.cpp create mode 100644 generator.h create mode 100644 precharge.cpp create mode 100644 precharge.h diff --git a/EVPC.pro b/EVPC.pro index e85997b..74365c3 100644 --- a/EVPC.pro +++ b/EVPC.pro @@ -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) diff --git a/battery.h b/battery.h index 4c80917..cb2e1f6 100644 --- a/battery.h +++ b/battery.h @@ -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 + +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(&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(&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(&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(&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 #include #include +#include #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 @@ 0 0 - 800 - 600 + 1100 + 900 - + + + 0 + 0 + + + - 800 + 0 600 + + + 1100 + 900 + + Electric Vehicle Parameter Calculator @@ -41,17 +53,41 @@ - 800 - 545 + 1100 + 845 + + + 0 + 0 + + + + + 0 + 600 + + 0 + + + 0 + 0 + + + + + 0 + 600 + + -1 @@ -62,7 +98,7 @@ Data - + -1 @@ -96,14 +132,25 @@ - - + + + + Voltage Range: + + + + + 0 0 + + background-color: rgba(255, 255, 255,80); +color: rgba(0, 0, 0,80); + Qt::AlignCenter @@ -112,41 +159,42 @@ - - - - Qt::Vertical + + + + color: rgba(0, 0, 0, 120); - - - 20 - 40 - + + Average PreCharge Power: - + - + Fuel Quantity: - - + + - Wire Gauge: + Wire Weight: - - + + 0 0 + + background-color: rgba(255, 255, 255,80); +color: rgba(0, 0, 0,80); + Qt::AlignCenter @@ -162,28 +210,158 @@ - - + + 0 0 + + Qt::AlignCenter + true - - + + + + color: rgba(0, 0, 0, 120); + - Wire Weight: + Generator KV: - - + + + + + 0 + 0 + + + + background-color: rgba(255, 255, 255,80); +color: rgba(0, 0, 0,80); + + + Qt::AlignCenter + + + true + + + + + + + + 0 + 0 + + + + Qt::AlignCenter + + + true + + + + + + + + 0 + 0 + + + + 0 - 0 + + + Qt::AlignCenter + + + true + + + + + + + color: rgba(0, 0, 0, 120); + + + Maximum Resistance: + + + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 20 + 40 + + + + + + + + + 0 + 0 + + + + background-color: rgba(255, 255, 255,80); +color: rgba(0, 0, 0,80); + + + Qt::AlignCenter + + + true + + + + + + + + 0 + 0 + + + + background-color: rgba(255, 255, 255,80); +color: rgba(0, 0, 0,80); + + + -- + + + Qt::AlignCenter + + + true + + + + + 0 @@ -198,6 +376,16 @@ + + + + color: rgba(0, 0, 0, 120); + + + Actual Pre-Charge Time: + + + @@ -214,15 +402,25 @@ - - + + - Voltage Range: + Wire Gauge: - - + + + + color: rgba(0, 0, 0, 120); + + + Peak Inrush Current: + + + + + 0 @@ -237,10 +435,123 @@ + + + + font: 10pt; +color: rgb(0, 0, 0); + + + Pre-Charge Circuit + + + Qt::AlignCenter + + + + + + + + + + + 0 + 0 + + + + Mechanical Inputs + + + + + + Run Time: + + + + + + + QFrame::NoFrame + + + <html><head/><body><p>Engine/Power Source:</p></body></html> + + + + + + + Qt::AlignCenter + + + QAbstractSpinBox::NoButtons + + + false + + + 2 + + + 96.000000000000000 + + + 8.000000000000000 + + + + + + + Qt::AlignCenter + + + QAbstractSpinBox::NoButtons + + + 1 + + + 1000.000000000000000 + + + 100.000000000000000 + + + + + + + + + + Vehicle Weight: + + + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 20 + 40 + + + + - + @@ -270,10 +581,45 @@ 0 - - + + + + + 0 + 0 + + + + font: 10pt; +color: rgb(0, 0, 0); + - System Voltage: + Pre-Charge Circuit + + + Qt::AlignHCenter|Qt::AlignTop + + + + + + + + + + Qt::AlignCenter + + + QAbstractSpinBox::NoButtons + + + 1 + + + 1000.000000000000000 + + + 0.000000000000000 @@ -299,29 +645,18 @@ - - - - Peak System Power: + + + + color: rgba(0, 0, 0, 120); - - - - - Wire Material: + System Capacitance (uF): - - - - false - - - - - + + Qt::AlignCenter @@ -339,11 +674,12 @@ - - - - - + + + + background-color: rgba(255, 255, 255,80); +color: rgba(0, 0, 0,80); + Qt::AlignCenter @@ -354,45 +690,47 @@ 1 - 1000.000000000000000 + 100.000000000000000 - - 0.000000000000000 + + + + + + Nominal Voltage: - - + + - Estimated Wire Length: + Peak System Power: - - + + + + color: rgba(0, 0, 0, 120); + - Battery Chemistry: + Percentage Desired: - - - - - - - Mechanical Inputs - - - - + + - Vehicle Weight: + Battery Chemistry: - - + + + + background-color: rgba(255, 255, 255,80); +color: rgba(0, 0, 0,80); + Qt::AlignCenter @@ -400,57 +738,190 @@ QAbstractSpinBox::NoButtons - 1 + 0 - 1000.000000000000000 + 100000.000000000000000 + + + + + + + background-color: rgba(255, 255, 255,80); +color: rgba(0, 0, 0,80); + + + Qt::AlignCenter + + + QAbstractSpinBox::NoButtons + + + 0.010000000000000 + + + 99.989999999999995 - 100.000000000000000 + 0.010000000000000 - - + + + + true + + + Qt::NoContextMenu + + + color: rgba(0, 0, 0, 120); + - Run Time: + Desired Pre-Charge Time: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - + + + + Estimated Wire Length: + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Wire Material: + + + + + + + false + + + + + + + + 0 + 0 + + + + background-color: rgba(255, 255, 255,80); +color: rgba(0, 0, 0,80); + Qt::AlignCenter QAbstractSpinBox::NoButtons - - false + + - 2 + 3 - 96.000000000000000 + 10000.000000000000000 - - 8.000000000000000 + + + + + + color: rgba(0, 0, 0, 120); + + + Generator RPM: - - - - QFrame::NoFrame + + + + + 0 + 0 + + + + color: rgba(0, 0, 0, 120); - <html><head/><body><p>Engine/Power Source:</p></body></html> + Minimum Allowable SOC: - - + + + + background-color: rgba(255, 255, 255,80); +color: rgba(0, 0, 0,80); + + + Qt::AlignCenter + + + QAbstractSpinBox::NoButtons + + + 60.000000000000000 + + + + + + + color: rgba(0, 0, 0, 120); + + + Chosen Resistance: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + background-color: rgba(255, 255, 255,80); +color: rgba(0, 0, 0,80); + + + Qt::AlignCenter + + + QAbstractSpinBox::NoButtons + + + 10000.000000000000000 + + 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 +#include + +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 -- cgit v1.2.3