Skip to content

Commit

Permalink
Added ld_lq_diff to inductance measurement ui
Browse files Browse the repository at this point in the history
  • Loading branch information
vedderb committed Nov 21, 2021
1 parent 99fdf2c commit 12fdd2a
Show file tree
Hide file tree
Showing 7 changed files with 246 additions and 198 deletions.
6 changes: 5 additions & 1 deletion commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,11 @@ void Commands::processPacket(QByteArray data)
case COMM_DETECT_MOTOR_R_L: {
double r = vb.vbPopFrontDouble32(1e6);
double l = vb.vbPopFrontDouble32(1e3);
emit motorRLReceived(r, l);
double ld_lq_diff = 0.0;
if (vb.size() >= 4) {
ld_lq_diff = vb.vbPopFrontDouble32(1e3);
}
emit motorRLReceived(r, l, ld_lq_diff);
} break;

case COMM_DETECT_MOTOR_FLUX_LINKAGE: {
Expand Down
2 changes: 1 addition & 1 deletion commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Commands : public QObject
void decodedAdcReceived(double value, double voltage, double value2, double voltage2);
void decodedChukReceived(double value);
void decodedBalanceReceived(BALANCE_VALUES values);
void motorRLReceived(double r, double l);
void motorRLReceived(double r, double l, double ld_lq_diff);
void motorLinkageReceived(double flux_linkage);
void encoderParamReceived(double offset, double ratio, bool inverted);
void customAppDataReceived(QByteArray data);
Expand Down
5 changes: 3 additions & 2 deletions utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,12 +513,13 @@ QVector<double> Utility::measureRLBlocking(VescInterface *vesc)

vesc->commands()->measureRL();

auto conn = connect(vesc->commands(), &Commands::motorRLReceived, [&res](double r, double l) {
auto conn = connect(vesc->commands(), &Commands::motorRLReceived, [&res](double r, double l, double ld_lq_diff) {
res.append(r);
res.append(l);
res.append(ld_lq_diff);
});

waitSignal(vesc->commands(), SIGNAL(motorRLReceived(double, double)), 8000);
waitSignal(vesc->commands(), SIGNAL(motorRLReceived(double, double, double)), 8000);
disconnect(conn);

return res;
Expand Down
2 changes: 1 addition & 1 deletion vesc_tool.pro
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ VT_INTRO_VERSION = 1
VT_CONFIG_VERSION = 2

# Set to 0 for stable versions and to test version number for development versions.
VT_IS_TEST_VERSION = 43
VT_IS_TEST_VERSION = 44

VT_ANDROID_VERSION_ARMV7 = 95
VT_ANDROID_VERSION_ARM64 = 96
Expand Down
19 changes: 16 additions & 3 deletions widgets/detectfoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ void DetectFoc::setVesc(VescInterface *vesc)
mVesc = vesc;

if (mVesc) {
connect(mVesc->commands(), SIGNAL(motorRLReceived(double,double)),
this, SLOT(motorRLReceived(double,double)));
connect(mVesc->commands(), SIGNAL(motorRLReceived(double,double,double)),
this, SLOT(motorRLReceived(double,double,double)));
connect(mVesc->commands(), SIGNAL(motorLinkageReceived(double)),
this, SLOT(motorLinkageReceived(double)));
connect(mVesc->mcConfig(), SIGNAL(paramChangedDouble(QObject*,QString,double)),
Expand All @@ -145,7 +145,7 @@ void DetectFoc::setVesc(VescInterface *vesc)
}
}

void DetectFoc::motorRLReceived(double r, double l)
void DetectFoc::motorRLReceived(double r, double l, double ld_lq_diff)
{
if (!mRunning) {
return;
Expand All @@ -162,6 +162,7 @@ void DetectFoc::motorRLReceived(double r, double l)
mVesc->emitStatusMessage(tr("FOC Detection Result Received"), true);
ui->resistanceBox->setValue(r * 1e3);
ui->inductanceBox->setValue(l);
ui->inductanceDiffBox->setValue(ld_lq_diff);
ui->kpBox->setValue(0.0);
ui->kiBox->setValue(0.0);
on_calcKpKiButton_clicked();
Expand Down Expand Up @@ -224,6 +225,7 @@ void DetectFoc::on_applyAllButton_clicked()
if (mVesc) {
double r = ui->resistanceBox->value() / 1e3;
double l = ui->inductanceBox->value();
double ld_lq_diff = ui->inductanceDiffBox->value();
double lambda = ui->lambdaBox->value() / 1e3;

if (r < 1e-10) {
Expand All @@ -247,8 +249,16 @@ void DetectFoc::on_applyAllButton_clicked()
return;
}

if (ld_lq_diff > (l / 4.0)) {
QMessageBox::information(this,
tr("Salient Motor"),
tr("This motor has some saliency and could benefit from the MTPA-algorithm. You "
"can activate it from the FOC->Advanced page. Be careful when testing!"));
}

mVesc->mcConfig()->updateParamDouble("foc_motor_r", r);
mVesc->mcConfig()->updateParamDouble("foc_motor_l", l / 1e6);
mVesc->mcConfig()->updateParamDouble("foc_motor_ld_lq_diff", ld_lq_diff / 1e6);
mVesc->mcConfig()->updateParamDouble("foc_motor_flux_linkage", lambda);

mVesc->emitStatusMessage(tr("R, L and \u03BB applied"), true);
Expand Down Expand Up @@ -287,6 +297,7 @@ void DetectFoc::updateColors()
{
bool r_ok = ui->resistanceBox->value() > 1e-10;
bool l_ok = ui->inductanceBox->value() > 1e-10;
bool l_diff_ok = ui->inductanceDiffBox->value() > 1e-10;
bool lambda_ok = ui->lambdaBox->value() > 1e-10;
bool gain_ok = ui->obsGainBox->value() > 1e-10;
bool kp_ok = ui->kpBox->value() > 1e-10;
Expand All @@ -302,6 +313,8 @@ void DetectFoc::updateColors()
arg(r_ok ? style_green : style_red));
ui->inductanceBox->setStyleSheet(QString("#inductanceBox {%1}").
arg(l_ok ? style_green : style_red));
ui->inductanceDiffBox->setStyleSheet(QString("#inductanceDiffBox {%1}").
arg(l_diff_ok ? style_green : style_red));
ui->lambdaBox->setStyleSheet(QString("#lambdaBox {%1}").
arg(lambda_ok ? style_green : style_red));
ui->obsGainBox->setStyleSheet(QString("#obsGainBox {%1}").
Expand Down
2 changes: 1 addition & 1 deletion widgets/detectfoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class DetectFoc : public QWidget
bool lastOkValuesApplied() const;

private slots:
void motorRLReceived(double r, double l);
void motorRLReceived(double r, double l, double ld_lq_diff);
void motorLinkageReceived(double flux_linkage);
void paramChangedDouble(QObject *src, QString name, double newParam);

Expand Down
Loading

0 comments on commit 12fdd2a

Please sign in to comment.