Skip to content

Commit

Permalink
Added negative value support to comparison tool
Browse files Browse the repository at this point in the history
  • Loading branch information
vedderb committed Nov 24, 2021
1 parent 93ef5c0 commit 7034f24
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 53 deletions.
20 changes: 16 additions & 4 deletions pages/pagemotorcomparison.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ PageMotorComparison::PageMotorComparison(QWidget *parent) :

connect(ui->testLiveUpdateBox, &QCheckBox::toggled,
[this](bool checked) { (void)checked; settingChanged(); });
connect(ui->testNegativeBox, &QCheckBox::toggled,
[this](bool checked) { (void)checked; settingChanged(); });

connect(ui->testRpmBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
[this](double value) { (void)value; settingChanged(); });
Expand Down Expand Up @@ -387,7 +389,7 @@ bool PageMotorComparison::reloadConfigs()

void PageMotorComparison::updateDataAndPlot(double posx, double yMin, double yMax)
{
if (posx < 0.0) {
if (posx < 0.0 && !ui->testNegativeBox->isChecked()) {
posx = 0.0;
}

Expand Down Expand Up @@ -668,14 +670,19 @@ void PageMotorComparison::on_testRunButton_clicked()

auto plotTorqueSweep = [this, updateData, updateGraphs](QTableWidget *table,
ConfigParams &config, TestParams param) {
double torque = ui->testTorqueBox->value();
double torque = fabs(ui->testTorqueBox->value());
double rpm = ui->testRpmBox->value();

QVector<double> xAxis;
QVector<QVector<double> > yAxes;
QVector<QString> names;

for (double t = torque / 1000.0;t < torque;t += (torque / 1000.0)) {
double torque_start = -torque;
if (!ui->testNegativeBox->isChecked()) {
torque_start = torque / 1000.0;
}

for (double t = torque_start;t < torque;t += (torque / 1000.0)) {
MotorData md;
md.update(config, rpm, t, param);
xAxis.append(t);
Expand All @@ -700,7 +707,12 @@ void PageMotorComparison::on_testRunButton_clicked()
QVector<QVector<double> > yAxes;
QVector<QString> names;

for (double r = rpm / 1000.0;r < rpm;r += (rpm / 1000.0)) {
double rpm_start = -rpm;
if (!ui->testNegativeBox->isChecked()) {
rpm_start = rpm / 1000.0;
}

for (double r = rpm_start;r < rpm;r += (rpm / 1000.0)) {
MotorData md;
md.update(config, r, torque, param);
xAxis.append(r);
Expand Down
6 changes: 4 additions & 2 deletions pages/pagemotorcomparison.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private slots:
double rps_out = rpm * 2.0 * M_PI / 60.0;
double rps_motor = rps_out * params.gearing;
double e_rps = rps_motor * pole_pairs;
double t_nl = (3.0 / 2.0) * i_nl * lambda * pole_pairs; // No-load torque from core losses
double t_nl = SIGN(rpm) * (3.0 / 2.0) * i_nl * lambda * pole_pairs; // No-load torque from core losses

iq = ((torque_motor_shaft + t_nl) * (2.0 / 3.0) / (lambda * pole_pairs));
id = -params.fwCurrent;
Expand Down Expand Up @@ -169,7 +169,9 @@ private slots:
loss_tot = loss_motor_tot + loss_gearing;
p_out = rps_motor * torque_motor_shaft * params.motorNum * params.gearingEfficiency;
p_in = rps_motor * torque_motor_shaft * params.motorNum + loss_motor_tot;
efficiency = p_out / p_in;

efficiency = fmin(fabs(p_out), fabs(p_in)) / fmax(fabs(p_out), fabs(p_in));

vq = r * iq + e_rps * (lambda + id * ld);
vd = r * id - e_rps * lq * iq;
vbus_min = (3.0 / 2.0) * sqrt(vq * vq + vd * vd) / (sqrt(3.0) / 2.0) / 0.95;
Expand Down
104 changes: 57 additions & 47 deletions pages/pagemotorcomparison.ui
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,13 @@
<property name="spacing">
<number>2</number>
</property>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="testRpmBox">
<item row="1" column="0">
<widget class="QDoubleSpinBox" name="testRpmStartBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>End RPM</string>
<string>Start RPM</string>
</property>
<property name="prefix">
<string/>
Expand All @@ -102,42 +105,42 @@
<property name="decimals">
<number>0</number>
</property>
<property name="minimum">
<double>10.000000000000000</double>
</property>
<property name="maximum">
<double>999999.000000000000000</double>
</property>
<property name="singleStep">
<double>100.000000000000000</double>
</property>
<property name="value">
<double>8000.000000000000000</double>
<double>500.000000000000000</double>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QDoubleSpinBox" name="testPowerBox">
<item row="2" column="0">
<widget class="QDoubleSpinBox" name="testExpBaseTorqueBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Base Torque</string>
</property>
<property name="prefix">
<string>Pwr: </string>
<string>B: </string>
</property>
<property name="suffix">
<string> W</string>
<string> Nm</string>
</property>
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>0.100000000000000</double>
<number>3</number>
</property>
<property name="maximum">
<double>999999.000000000000000</double>
<double>999.000000000000000</double>
</property>
<property name="singleStep">
<double>100.000000000000000</double>
</property>
<property name="value">
<double>2000.000000000000000</double>
<double>0.200000000000000</double>
</property>
</widget>
</item>
Expand All @@ -152,6 +155,9 @@
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-9999.000000000000000</double>
</property>
<property name="maximum">
<double>9999.000000000000000</double>
</property>
Expand All @@ -163,13 +169,38 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QDoubleSpinBox" name="testRpmStartBox">
<item row="0" column="0">
<widget class="QDoubleSpinBox" name="testPowerBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="prefix">
<string>Pwr: </string>
</property>
<property name="suffix">
<string> W</string>
</property>
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>0.100000000000000</double>
</property>
<property name="maximum">
<double>999999.000000000000000</double>
</property>
<property name="singleStep">
<double>100.000000000000000</double>
</property>
<property name="value">
<double>2000.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="testRpmBox">
<property name="toolTip">
<string>Start RPM</string>
<string>End RPM</string>
</property>
<property name="prefix">
<string/>
Expand All @@ -180,17 +211,14 @@
<property name="decimals">
<number>0</number>
</property>
<property name="minimum">
<double>10.000000000000000</double>
</property>
<property name="maximum">
<double>999999.000000000000000</double>
</property>
<property name="singleStep">
<double>100.000000000000000</double>
</property>
<property name="value">
<double>500.000000000000000</double>
<double>8000.000000000000000</double>
</property>
</widget>
</item>
Expand Down Expand Up @@ -219,36 +247,18 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QDoubleSpinBox" name="testExpBaseTorqueBox">
<property name="enabled">
<bool>false</bool>
</property>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="testNegativeBox">
<property name="toolTip">
<string>Base Torque</string>
</property>
<property name="prefix">
<string>B: </string>
</property>
<property name="suffix">
<string> Nm</string>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="maximum">
<double>999.000000000000000</double>
<string>Include negative RPM and Torque in tests.</string>
</property>
<property name="singleStep">
<double>0.200000000000000</double>
<property name="text">
<string>Include Negative</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QComboBox" name="testTorqueExpPresetBox"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
Expand Down

0 comments on commit 7034f24

Please sign in to comment.