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 Dec 10, 2023
2 parents bf2448e + 03725ac commit eb5dd14
Show file tree
Hide file tree
Showing 4 changed files with 236 additions and 112 deletions.
14 changes: 0 additions & 14 deletions QCodeEditor/src/internal/QCodeEditor.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -815,20 +815,6 @@ void QCodeEditor::keyPressEvent(QKeyEvent* e) {
moveCursor(QTextCursor::MoveOperation::Left);
break;
}

// If it's close brace - check parentheses
if (el.second == e->text())
{
auto symbol = charUnderCursor();

if (symbol == el.second)
{
textCursor().deletePreviousChar();
moveCursor(QTextCursor::MoveOperation::Right);
}

break;
}
}
}
}
Expand Down
61 changes: 58 additions & 3 deletions pages/pagemotorcomparison.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ PageMotorComparison::PageMotorComparison(QWidget *parent) :
[this]() { settingChanged(); });
connect(ui->testModeVBFWButton, &QRadioButton::toggled,
[this]() { settingChanged(); });
connect(ui->testModeVBRPMButton, &QRadioButton::toggled,
[this]() { settingChanged(); });

connect(ui->testLiveUpdateBox, &QCheckBox::toggled,
[this](bool checked) { (void)checked; settingChanged(); });
Expand Down Expand Up @@ -251,6 +253,10 @@ PageMotorComparison::PageMotorComparison(QWidget *parent) :
[this](double value) { (void)value; settingChanged(); });
connect(ui->m2FwBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
[this](double value) { (void)value; settingChanged();});
connect(ui->m1MtpaBox, &QCheckBox::toggled,
[this](bool checked) { (void)checked; settingChanged(); });
connect(ui->m2MtpaBox, &QCheckBox::toggled,
[this](bool checked) { (void)checked; settingChanged(); });

connect(ui->m1TempIncBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
[this](double value) { (void)value; settingChanged(); });
Expand Down Expand Up @@ -335,7 +341,8 @@ PageMotorComparison::PageMotorComparison(QWidget *parent) :
ui->testTorqueBox->setEnabled(ui->testModeTorqueButton->isChecked() ||
ui->testModeRpmButton->isChecked() ||
ui->testModeVbusButton->isChecked() ||
ui->testModeVBFWButton->isChecked());
ui->testModeVBFWButton->isChecked() ||
ui->testModeVBRPMButton->isChecked());
ui->testPowerBox->setEnabled(ui->testModeRpmPowerButton->isChecked() ||
ui->testModeExpButton->isChecked());
ui->testRpmStartBox->setEnabled(ui->testModeRpmPowerButton->isChecked() ||
Expand All @@ -344,11 +351,13 @@ PageMotorComparison::PageMotorComparison(QWidget *parent) :
ui->testModeExpButton->isChecked() ||
ui->testModeRpmButton->isChecked() ||
ui->testModeTorqueButton->isChecked() ||
ui->testModeVBFWButton->isChecked());
ui->testModeVBFWButton->isChecked() ||
ui->testModeVBRPMButton->isChecked());
ui->testExpBox->setEnabled(ui->testModeExpButton->isChecked());
ui->testExpBaseTorqueBox->setEnabled(ui->testModeExpButton->isChecked());
ui->testVbusBox->setEnabled(ui->testModeVbusButton->isChecked() ||
ui->testModeVBFWButton->isChecked());
ui->testModeVBFWButton->isChecked() ||
ui->testModeVBRPMButton->isChecked());

if (ui->tabWidget->currentIndex() == 1) {
setQmlMotorParams();
Expand Down Expand Up @@ -608,6 +617,14 @@ void PageMotorComparison::updateDataAndPlot(double posx, double yMin, double yMa
md.configure(&mM2Config, getParamsUi(2));
md.updateTorqueVBusFW(posx, ui->testRpmBox->value(), ui->testVbusBox->value());
updateTable(md, ui->m2PlotTable);
} else if (ui->testModeVBRPMButton->isChecked()) {
MotorData md;
md.configure(&mM1Config, getParamsUi(1));
md.updateRpmVBusFW(ui->testTorqueBox->value(), posx, ui->testVbusBox->value());
updateTable(md, ui->m1PlotTable);
md.configure(&mM2Config, getParamsUi(2));
md.updateRpmVBusFW(ui->testTorqueBox->value(), posx, ui->testVbusBox->value());
updateTable(md, ui->m2PlotTable);
}
}
}
Expand All @@ -623,13 +640,15 @@ MotorDataParams PageMotorComparison::getParamsUi(int motor)
sel.tempInc = ui->m1TempIncBox->value();
sel.fwCurrent = ui->m1FwBox->value();
sel.maxRpm = ui->m1MaxRpmBox->value();
sel.mtpa = ui->m1MtpaBox->isChecked();
} else if (motor == 2) {
sel.gearing = ui->m2GearingBox->value();
sel.gearingEfficiency = ui->m2GearEfficiencyBox->value() / 100.0;
sel.motorNum = ui->m2MotorNumBox->value();
sel.tempInc = ui->m2TempIncBox->value();
sel.fwCurrent = ui->m2FwBox->value();
sel.maxRpm = ui->m2MaxRpmBox->value();
sel.mtpa = ui->m2MtpaBox->isChecked();
}

return sel;
Expand Down Expand Up @@ -1053,6 +1072,38 @@ void PageMotorComparison::on_testRunButton_clicked()
updateGraphs(xAxis, yAxes, names);
};

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

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

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

for (double r = rpm_start;r < rpm;r += (rpm / plotPoints)) {
MotorData md;
md.configure(&config, param);
md.updateRpmVBusFW(torque, r, vbus);
xAxis.append(r);
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("RPM");
updateGraphs(xAxis, yAxes, names);
};

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

Expand Down Expand Up @@ -1123,6 +1174,10 @@ void PageMotorComparison::on_testRunButton_clicked()
ui->plot->clearGraphs();
plotVBFWSweep(ui->m1PlotTable, mM1Config, getParamsUi(1));
plotVBFWSweep(ui->m2PlotTable, mM2Config, getParamsUi(2));
} else if (ui->testModeVBRPMButton->isChecked()) {
ui->plot->clearGraphs();
plotVBRPMSweep(ui->m1PlotTable, mM1Config, getParamsUi(1));
plotVBRPMSweep(ui->m2PlotTable, mM2Config, getParamsUi(2));
}
}

Expand Down
63 changes: 61 additions & 2 deletions pages/pagemotorcomparison.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct MotorDataParams {
fwCurrent = 0.0;
motorNum = 1.0;
tempInc = 0.0;
mtpa = false;
}

double gearing;
Expand All @@ -44,6 +45,7 @@ struct MotorDataParams {
double fwCurrent;
double motorNum;
double tempInc;
bool mtpa;
};

struct MotorData {
Expand Down Expand Up @@ -135,6 +137,64 @@ struct MotorData {
params = prm;
}

Q_INVOKABLE bool updateRpmVBusFW(double torque, double rpm, double vbus) {
double fw_max = params.fwCurrent;
params.fwCurrent = 0.0;

if (!update(rpm, torque)) {
params.fwCurrent = fw_max;
return false;
}

if (vbus_min < vbus) {
params.fwCurrent = fw_max;
return true;
}

double vbus_lower = vbus_min;
params.fwCurrent = fw_max;
update(rpm, torque);
double vbus_upper = vbus_min;

if (vbus_upper > vbus) {
return updateRpmVBus(rpm, vbus);
}

params.fwCurrent = Utility::map(vbus, vbus_lower, vbus_upper, 0.0, fw_max);

for (int i = 0;i < 20;i++) {
if (!update(rpm, torque)) {
params.fwCurrent = fw_max;
return false;
}

params.fwCurrent *= vbus_min / vbus;

if (params.fwCurrent > fw_max) {
params.fwCurrent = fw_max;
}

if (params.fwCurrent < 0.0) {
params.fwCurrent = 0.0;
}
}

params.fwCurrent = fw_max;
return true;
}

Q_INVOKABLE bool updateRpmVBus(double rpm, double vbus, double torque_guess = 5.0) {
for (int i = 0;i < 20;i++) {
if (!update(rpm, torque_guess)) {
return false;
}

torque_guess *= vbus / vbus_min;
}

return true;
}

Q_INVOKABLE bool updateTorqueVBusFW(double torque, double rpm, double vbus) {
double fw_max = params.fwCurrent;
params.fwCurrent = 0.0;
Expand Down Expand Up @@ -210,7 +270,6 @@ struct MotorData {
double i_nl = config->getParamDouble("si_motor_nl_current");
double pole_pairs = double(config->getParamInt("si_motor_poles")) / 2.0;
double wheel_diam = config->getParamDouble("si_wheel_diameter");
bool use_mpta = config->getParamEnum("foc_mtpa_mode");

r += r * 0.00386 * (params.tempInc);

Expand All @@ -237,7 +296,7 @@ struct MotorData {
iq += iq_adj;

// See https://github.com/vedderb/bldc/pull/179
if (use_mpta && fabs(ld_lq_diff) > 1e-9) {
if (params.mtpa && fabs(ld_lq_diff) > 1e-9) {
id = (lambda - sqrt(SQ(lambda) + 8.0 * SQ(ld_lq_diff) * SQ(iq))) / (4.0 * ld_lq_diff);
iq_adj = iq - SIGN(iq) * sqrt(SQ(iq) - SQ(id));
iq = SIGN(iq) * sqrt(SQ(iq) - SQ(id));
Expand Down
Loading

0 comments on commit eb5dd14

Please sign in to comment.