Skip to content

Commit

Permalink
Merge branch 'vedderb:master' into ci
Browse files Browse the repository at this point in the history
  • Loading branch information
darwinbeing authored Nov 27, 2023
2 parents 88e764c + fea3368 commit e096f0a
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 36 deletions.
98 changes: 83 additions & 15 deletions pages/pagemotorcomparison.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ PageMotorComparison::PageMotorComparison(QWidget *parent) :
[this]() { settingChanged(); });
connect(ui->testModeRpmPowerButton, &QRadioButton::toggled,
[this]() { settingChanged(); });
connect(ui->testModeExpButton, &QRadioButton::toggled,
[this]() { settingChanged(); });
connect(ui->testModeVbusButton, &QRadioButton::toggled,
[this]() { settingChanged(); });

connect(ui->testLiveUpdateBox, &QCheckBox::toggled,
[this](bool checked) { (void)checked; settingChanged(); });
Expand Down Expand Up @@ -318,6 +322,39 @@ PageMotorComparison::PageMotorComparison(QWidget *parent) :
addDataItem(name, ui->m2PlotTable, hasScale);
};

mSettingUpdateRequired = false;
mSettingUpdateTimer = new QTimer(this);
mSettingUpdateTimer->start(20);

connect(mSettingUpdateTimer, &QTimer::timeout, [this]() {
if (mSettingUpdateRequired) {
ui->testTorqueBox->setEnabled(ui->testModeTorqueButton->isChecked() ||
ui->testModeRpmButton->isChecked() ||
ui->testModeVbusButton->isChecked());
ui->testPowerBox->setEnabled(ui->testModeRpmPowerButton->isChecked() ||
ui->testModeExpButton->isChecked());
ui->testRpmStartBox->setEnabled(ui->testModeRpmPowerButton->isChecked() ||
ui->testModeExpButton->isChecked());
ui->testRpmBox->setEnabled(ui->testModeRpmPowerButton->isChecked() ||
ui->testModeExpButton->isChecked() ||
ui->testModeRpmButton->isChecked() ||
ui->testModeTorqueButton->isChecked());
ui->testExpBox->setEnabled(ui->testModeExpButton->isChecked());
ui->testExpBaseTorqueBox->setEnabled(ui->testModeExpButton->isChecked());
ui->testVbusBox->setEnabled(ui->testModeVbusButton->isChecked());

if (ui->tabWidget->currentIndex() == 1) {
setQmlMotorParams();
}

if (ui->testLiveUpdateBox->isChecked()) {
on_testRunButton_clicked();
}

mSettingUpdateRequired = false;
}
});

addDataItemBoth("Efficiency");
addDataItemBoth("Mot Loss Tot");
addDataItemBoth("Mot Loss Res");
Expand Down Expand Up @@ -393,19 +430,7 @@ void PageMotorComparison::setVesc(VescInterface *vesc)

void PageMotorComparison::settingChanged()
{
ui->testTorqueBox->setEnabled(ui->testModeTorqueButton->isChecked() || ui->testModeRpmButton->isChecked());
ui->testPowerBox->setEnabled(ui->testModeRpmPowerButton->isChecked() || ui->testModeExpButton->isChecked());
ui->testRpmStartBox->setEnabled(ui->testModeRpmPowerButton->isChecked() || ui->testModeExpButton->isChecked());
ui->testExpBox->setEnabled(ui->testModeExpButton->isChecked());
ui->testExpBaseTorqueBox->setEnabled(ui->testModeExpButton->isChecked());

if (ui->tabWidget->currentIndex() == 1) {
setQmlMotorParams();
}

if (ui->testLiveUpdateBox->isChecked()) {
on_testRunButton_clicked();
}
mSettingUpdateRequired = true;
}

bool PageMotorComparison::reloadConfigs()
Expand Down Expand Up @@ -542,7 +567,7 @@ void PageMotorComparison::updateDataAndPlot(double posx, double yMin, double yMa
md.configure(&mM2Config, getParamsUi(2));
md.update(posx, torque);
updateTable(md, ui->m2PlotTable);
} else {
} else if (ui->testModeExpButton->isChecked()) {
double rpm_start = ui->testRpmStartBox->value();
double rps = posx * 2.0 * M_PI / 60.0;
double prop_exp = ui->testExpBox->value();
Expand All @@ -560,6 +585,14 @@ void PageMotorComparison::updateDataAndPlot(double posx, double yMin, double yMa
md.configure(&mM2Config, getParamsUi(2));
md.update(posx, torque);
updateTable(md, ui->m2PlotTable);
} else if (ui->testModeVbusButton->isChecked()) {
MotorData md;
md.configure(&mM1Config, getParamsUi(1));
md.updateTorqueVBus(posx, ui->testVbusBox->value());
updateTable(md, ui->m1PlotTable);
md.configure(&mM2Config, getParamsUi(2));
md.updateTorqueVBus(posx, ui->testVbusBox->value());
updateTable(md, ui->m2PlotTable);
}
}
}
Expand Down Expand Up @@ -932,6 +965,37 @@ void PageMotorComparison::on_testRunButton_clicked()
updateGraphs(xAxis, yAxes, names);
};

auto plotVbusSweep = [this, updateData, updateGraphs, plotPoints](QTableWidget *table,
ConfigParams &config, MotorDataParams param) {
double torque = fabs(ui->testTorqueBox->value());
double vbus = ui->testVbusBox->value();

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

double torque_start = -torque;
if (!ui->testNegativeBox->isChecked()) {
torque_start = torque / plotPoints;
}

for (double t = torque_start;t < torque;t += (torque / plotPoints)) {
MotorData md;
md.configure(&config, param);
md.updateTorqueVBus(t, vbus);
xAxis.append(t);
updateData(md, table, yAxes, names);

if (md.rpm_motor_shaft >= param.maxRpm) {
mVesc->emitMessageDialog("Max RPM", "Maximum motor shaft RPM exceeded", false);
break;
}
}

ui->plot->xAxis->setLabel("Torque (Nm)");
updateGraphs(xAxis, yAxes, names);
};

auto plotQmlSweep = [this, updateData, updateGraphs, plotPoints](QTableWidget *table,
ConfigParams &config, MotorDataParams param, int motor) {

Expand Down Expand Up @@ -990,10 +1054,14 @@ void PageMotorComparison::on_testRunButton_clicked()
ui->plot->clearGraphs();
plotPowerSweep(ui->m1PlotTable, mM1Config, getParamsUi(1));
plotPowerSweep(ui->m2PlotTable, mM2Config, getParamsUi(2));
} else {
} else if (ui->testModeExpButton->isChecked()) {
ui->plot->clearGraphs();
plotPropSweep(ui->m1PlotTable, mM1Config, getParamsUi(1));
plotPropSweep(ui->m2PlotTable, mM2Config, getParamsUi(2));
} else if (ui->testModeVbusButton->isChecked()) {
ui->plot->clearGraphs();
plotVbusSweep(ui->m1PlotTable, mM1Config, getParamsUi(1));
plotVbusSweep(ui->m2PlotTable, mM2Config, getParamsUi(2));
}
}

Expand Down
23 changes: 21 additions & 2 deletions pages/pagemotorcomparison.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <QWidget>
#include <QPair>
#include <QTimer>
#include "vescinterface.h"
#include "configparams.h"
#include "widgets/qcustomplot.h"
Expand Down Expand Up @@ -134,9 +135,23 @@ struct MotorData {
params = prm;
}

Q_INVOKABLE void update(double rpm, double torque) {
Q_INVOKABLE bool updateTorqueVBus(double torque, double vbus) {
double rpm_guess = 1000.0;

for (int i = 0;i < 20;i++) {
if (!update(rpm_guess, torque)) {
return false;
}

rpm_guess *= vbus / vbus_min;
}

return true;
}

Q_INVOKABLE bool update(double rpm, double torque) {
if (config == nullptr) {
return;
return false;
}

// See https://www.mathworks.com/help/physmod/sps/ref/pmsm.html
Expand Down Expand Up @@ -214,6 +229,8 @@ struct MotorData {

kv_bldc = rpm_motor_shaft / (vbus_min * (sqrt(3.0) / 2.0));
kv_bldc_noload = (60.0 * 0.95) / (lambda * (3.0 / 2.0) * M_PI * 2.0 * pole_pairs);

return true;
}

ConfigParams *config;
Expand Down Expand Up @@ -336,6 +353,8 @@ private slots:
QPair<double, double> mVerticalLineYLast;
bool mRunDone;
Utility mUtil;
QTimer *mSettingUpdateTimer;
bool mSettingUpdateRequired;

bool mQmlXNameOk;
bool mQmlXMinOk;
Expand Down
67 changes: 48 additions & 19 deletions pages/pagemotorcomparison.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>1586</width>
<height>946</height>
<width>1450</width>
<height>945</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -41,7 +41,7 @@
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Common</string>
<string>Custom</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="spacing">
Expand All @@ -61,6 +61,26 @@
</property>
<item>
<layout class="QGridLayout" name="gridLayout_4">
<item row="1" column="0">
<widget class="QRadioButton" name="testModeRpmPowerButton">
<property name="toolTip">
<string>Sweep from the start RPM to the end RPM at the set Power.</string>
</property>
<property name="text">
<string>RPM/Power</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QRadioButton" name="testModeExpButton">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Torque + RPM Exponential mode. Sweep from 0 to end RPM and use the base torque + exponent on the RPM to derive the power requirement. The test will be scaled such that the specified power is at the full RPM. The power for the base torque will be required in addition to that.&lt;/p&gt;&lt;p&gt;Propellers and impellers in air and water usually just have the exponent while traction vehicles have a base torque from the rolling resistance + an exponent from wind resistance.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Exp</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QRadioButton" name="testModeTorqueButton">
<property name="toolTip">
Expand All @@ -87,23 +107,13 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="testModeRpmPowerButton">
<property name="toolTip">
<string>Sweep from the start RPM to the end RPM at the set Power.</string>
</property>
<property name="text">
<string>RPM/Power</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QRadioButton" name="testModeExpButton">
<item row="0" column="2">
<widget class="QRadioButton" name="testModeVbusButton">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Torque + RPM Exponential mode. Sweep from 0 to end RPM and use the base torque + exponent on the RPM to derive the power requirement. The test will be scaled such that the specified power is at the full RPM. The power for the base torque will be required in addition to that.&lt;/p&gt;&lt;p&gt;Propellers and impellers in air and water usually just have the exponent while traction vehicles have a base torque from the rolling resistance + an exponent from wind resistance.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Torque sweep while keeping the bus voltage constant.</string>
</property>
<property name="text">
<string>Torque + Exp</string>
<string>Vbus</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -273,13 +283,32 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<item row="3" column="0">
<widget class="QCheckBox" name="testNegativeBox">
<property name="toolTip">
<string>Include negative RPM and Torque in tests.</string>
</property>
<property name="text">
<string>Include Negative</string>
<string>Negative</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QDoubleSpinBox" name="testVbusBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="suffix">
<string> V</string>
</property>
<property name="decimals">
<number>1</number>
</property>
<property name="maximum">
<double>9999.000000000000000</double>
</property>
<property name="value">
<double>48.000000000000000</double>
</property>
</widget>
</item>
Expand Down

0 comments on commit e096f0a

Please sign in to comment.