Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use potentiometer for angle offset calib #380

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions configparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1841,7 +1841,11 @@ bool ConfigParams::moveGroupUp(QString group)
for (int i = 0;i < mParamGrouping.size();i++) {
if (mParamGrouping.at(i).first.toLower() == group.toLower()) {
if (i > 0) {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
mParamGrouping.swapItemsAt(i, i - 1);
#else
qSwap(mParamGrouping[i], mParamGrouping[i - 1]);
#endif
return true;
} else {
return false;
Expand All @@ -1856,7 +1860,11 @@ bool ConfigParams::moveGroupDown(QString group)
for (int i = 0;i < mParamGrouping.size();i++) {
if (mParamGrouping.at(i).first.toLower() == group.toLower()) {
if (i < (mParamGrouping.size() - 1)) {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
mParamGrouping.swapItemsAt(i, i + 1);
#else
qSwap(mParamGrouping[i], mParamGrouping[i + 1]);
#endif
return true;
} else {
return false;
Expand All @@ -1873,7 +1881,11 @@ bool ConfigParams::moveSubgroupUp(QString group, QString subgroup)
for (int j = 0;j < mParamGrouping.at(i).second.size();j++) {
if (mParamGrouping.at(i).second.at(j).first.toLower() == subgroup.toLower()) {
if (j > 0) {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
mParamGrouping[i].second.swapItemsAt(j, j - 1);
#else
qSwap(mParamGrouping[i].second[j], mParamGrouping[i].second[j - 1]);
#endif
return true;
} else {
return false;
Expand All @@ -1892,7 +1904,11 @@ bool ConfigParams::moveSubgroupDown(QString group, QString subgroup)
for (int j = 0;j < mParamGrouping.at(i).second.size();j++) {
if (mParamGrouping.at(i).second.at(j).first.toLower() == subgroup.toLower()) {
if (j < (mParamGrouping.at(i).second.size() - 1)) {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
mParamGrouping[i].second.swapItemsAt(j, j + 1);
#else
qSwap(mParamGrouping[i].second[j], mParamGrouping[i].second[j + 1]);
#endif
return true;
} else {
return false;
Expand All @@ -1913,7 +1929,11 @@ bool ConfigParams::moveSubgroupParamUp(QString group, QString subgroup, QString
for (int k = 0;k < mParamGrouping.at(i).second.at(j).second.size();k++) {
if (mParamGrouping.at(i).second.at(j).second.at(k).toLower() == param.toLower()) {
if (k > 0) {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
mParamGrouping[i].second[j].second.swapItemsAt(k, k - 1);
#else
qSwap(mParamGrouping[i].second[j].second[k], mParamGrouping[i].second[j].second[k - 1]);
#endif
return true;
} else {
return false;
Expand All @@ -1936,7 +1956,11 @@ bool ConfigParams::moveSubgroupParamDown(QString group, QString subgroup, QStrin
for (int k = 0;k < mParamGrouping.at(i).second.at(j).second.size();k++) {
if (mParamGrouping.at(i).second.at(j).second.at(k).toLower() == param.toLower()) {
if (k < (mParamGrouping.at(i).second.at(j).second.size() - 1)) {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
mParamGrouping[i].second[j].second.swapItemsAt(k, k + 1);
#else
qSwap(mParamGrouping[i].second[j].second[k], mParamGrouping[i].second[j].second[k + 1]);
#endif
return true;
} else {
return false;
Expand Down
14 changes: 14 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,20 @@ static void addFonts() {

int main(int argc, char *argv[])
{
// Set the platform plugin to xcb
qputenv("QT_QPA_PLATFORM", QByteArray("xcb"));
qputenv("QT_XCB_GL_INTEGRATION", QByteArray("glx"));
qputenv("LIBGL_ALWAYS_SOFTWARE", QByteArray("1"));
qputenv("QT_QUICK_BACKEND", QByteArray("software"));

// Set OpenGL format
QSurfaceFormat format;
format.setDepthBufferSize(24);
format.setStencilBufferSize(8);
format.setVersion(2, 0); // Set OpenGL version to 2.0
format.setProfile(QSurfaceFormat::NoProfile);
QSurfaceFormat::setDefaultFormat(format);

// Settings
QCoreApplication::setOrganizationName("VESC");
QCoreApplication::setOrganizationDomain("vesc-project.com");
Expand Down
12 changes: 10 additions & 2 deletions pages/pageloganalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ PageLogAnalysis::PageLogAnalysis(QWidget *parent) :
ui->plot->axisRect()->setRangeDrag(Qt::Orientations());

double upper = ui->plot->xAxis->range().upper;
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
double progress = ui->plot->xAxis->pixelToCoord(event->position().x()) / upper;
#else
double progress = ui->plot->xAxis->pixelToCoord(event->x()) / upper;
#endif
double diff = event->angleDelta().y();
double d1 = diff * progress;
double d2 = diff * (1.0 - progress);
Expand Down Expand Up @@ -1713,8 +1717,12 @@ void PageLogAnalysis::on_saveCsvButton_clicked()

for (int i = 0;i < mLog.size();i++) {
for (int j = 0;j < mLog.at(i).size();j++) {
os << Qt::fixed
<< qSetRealNumberPrecision(mLogHeader.at(j).precision)
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
os << Qt::fixed;
#else
os.setRealNumberNotation(QTextStream::FixedNotation);
#endif
os << qSetRealNumberPrecision(mLogHeader.at(j).precision)
<< mLog.at(i).at(j);

if (j < (mLog.at(i).size() - 1)) {
Expand Down
51 changes: 51 additions & 0 deletions pages/pagevescpackage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,51 @@ void PageVescPackage::on_writeButton_clicked()
mLoader.installVescPackageFromPath(ui->loadEdit->text());
}

#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
QString PageVescPackage::convertHtmlToMarkdown(const QString &html) {
QString markdown = html;

// <b> and </b> to **
markdown.replace(QRegularExpression("<b>(.*?)</b>"), "**\\1**");

// <i> and </i> to *
markdown.replace(QRegularExpression("<i>(.*?)</i>"), "*\\1*");

// <br> and <br/> to newline
markdown.replace(QRegularExpression("<br\\s*/?>"), "\n");

// <h1> to <h6> to #
markdown.replace(QRegularExpression("<h1>(.*?)</h1>"), "# \\1\n");
markdown.replace(QRegularExpression("<h2>(.*?)</h2>"), "## \\1\n");
markdown.replace(QRegularExpression("<h3>(.*?)</h3>"), "### \\1\n");
markdown.replace(QRegularExpression("<h4>(.*?)</h4>"), "#### \\1\n");
markdown.replace(QRegularExpression("<h5>(.*?)</h5>"), "##### \\1\n");
markdown.replace(QRegularExpression("<h6>(.*?)</h6>"), "###### \\1\n");

// <ul> and <ol> to list
markdown.replace(QRegularExpression("<ul>"), "");
markdown.replace(QRegularExpression("<ol>"), "");
markdown.replace(QRegularExpression("<li>(.*?)</li>"), "- \\1\n");
markdown.replace(QRegularExpression("</ul>"), "");
markdown.replace(QRegularExpression("</ol>"), "");

// <a href="url">text</a> to [text](url)
markdown.replace(QRegularExpression("<a\\s+href=\"(.*?)\".*?>(.*?)</a>"), "[\\2](\\1)");

// <img src="url" alt="alt" /> to ![alt](url)
markdown.replace(QRegularExpression("<img\\s+src=\"(.*?)\".*?alt=\"(.*?)\".*?/?>"), "!\\[\\2\\](\\1)");

// <p> to newline and </p> to another newline
markdown.replace(QRegularExpression("<p>"), "");
markdown.replace(QRegularExpression("</p>"), "\n\n");

// Remove other HTML tags
markdown.remove(QRegularExpression("<[^>]*>"));

return markdown;
}
#endif

void PageVescPackage::on_outputRefreshButton_clicked()
{
QFile f(ui->outputEdit->text());
Expand All @@ -295,7 +340,13 @@ void PageVescPackage::on_outputRefreshButton_clicked()
QString line1 = QTextStream(&pkg.description).readLine();
if (line1.contains("<!DOCTYPE HTML PUBLIC", Qt::CaseInsensitive)) {
ui->descriptionEdit->document()->setHtml(pkg.description);

#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
QString md = ui->descriptionEdit->document()->toMarkdown();
#else
QString md = convertHtmlToMarkdown(ui->descriptionEdit->document()->toHtml());
#endif

ui->descriptionEdit->document()->setPlainText(md);
} else {
ui->descriptionEdit->document()->setPlainText(pkg.description);
Expand Down
3 changes: 3 additions & 0 deletions pages/pagevescpackage.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ private slots:
void on_saveButton_clicked();
void on_loadRefreshButton_clicked();
void on_writeButton_clicked();
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
QString convertHtmlToMarkdown(const QString &html);
#endif
void on_outputRefreshButton_clicked();
void on_dlArchiveButton_clicked();
void on_uninstallButton_clicked();
Expand Down
14 changes: 14 additions & 0 deletions res/config/6.06/parameters_mcconf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3187,6 +3187,18 @@ p, li { white-space: pre-wrap; }
<suffix> °</suffix>
<vTx>9</vTx>
</p_pid_offset>
<p_pid_offset_pot_calib>
<longName>Use Potentionmeter for Offset Angle Calibration</longName>
<type>5</type>
<transmittable>1</transmittable>
<description>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Roboto'; ; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Allow the speed controller to to apply braking current. In general this option should be enabled, but for some applications it might make sense to disable braking during speed control.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</description>
<cDefine>MCCONF_P_PID_OFFSET_POT_CALIB</cDefine>
<valInt>0</valInt>
</p_pid_offset_pot_calib>
<p_pid_kd_proc>
<longName>Position PID Kd Process</longName>
<type>1</type>
Expand Down Expand Up @@ -4671,6 +4683,7 @@ p, li { white-space: pre-wrap; }
<ser>p_pid_ang_div</ser>
<ser>p_pid_gain_dec_angle</ser>
<ser>p_pid_offset</ser>
<ser>p_pid_offset_pot_calib</ser>
<ser>cc_startup_boost_duty</ser>
<ser>cc_min_current</ser>
<ser>cc_gain</ser>
Expand Down Expand Up @@ -5069,6 +5082,7 @@ p, li { white-space: pre-wrap; }
<param>p_pid_ang_div</param>
<param>p_pid_gain_dec_angle</param>
<param>p_pid_offset</param>
<param>p_pid_offset_pot_calib</param>
</subgroupParams>
</subgroup>
</group>
Expand Down
17 changes: 17 additions & 0 deletions vescinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,17 @@ VescInterface::VescInterface(QObject *parent) : QObject(parent)
os << mLastImuValues.gyroZ << ";";

os << msPos << ";";
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
os << Qt::fixed << qSetRealNumberPrecision(8) << lat << ";";
os << Qt::fixed << qSetRealNumberPrecision(8) << lon << ";";
#else
os.setRealNumberNotation(QTextStream::FixedNotation);
os.setRealNumberPrecision(8);
os << lat << ";";
os.setRealNumberNotation(QTextStream::FixedNotation);
os.setRealNumberPrecision(8);
os << lon << ";";
#endif
os << alt << ";";
os << gVel << ";";
os << vVel << ";";
Expand Down Expand Up @@ -808,15 +817,23 @@ void VescInterface::deleteProfile(int index)
void VescInterface::moveProfileUp(int index)
{
if (index > 0 && index < mProfiles.size()) {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
mProfiles.swapItemsAt(index, index - 1);
#else
qSwap(mProfiles[index], mProfiles[index - 1]);
#endif
emit profilesUpdated();
}
}

void VescInterface::moveProfileDown(int index)
{
if (index >= 0 && index < (mProfiles.size() - 1)) {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
mProfiles.swapItemsAt(index, index + 1);
#else
qSwap(mProfiles[index], mProfiles[index + 1]);
#endif
emit profilesUpdated();
}
}
Expand Down
4 changes: 4 additions & 0 deletions widgets/aspectimglabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ void AspectImgLabel::resizeEvent(QResizeEvent *event)
{
QLabel::resizeEvent(event);

#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
const QPixmap &pix = pixmap(Qt::ReturnByValue);
#else
const QPixmap &pix = *pixmap();
#endif

if (!pix.isNull()) {
int wLabel = width();
Expand Down
6 changes: 6 additions & 0 deletions widgets/helpdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,17 @@ HelpDialog::HelpDialog(QString title, QString text, QWidget *parent) :
setAttribute(Qt::WA_DeleteOnClose);
setWindowTitle(title);

#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
// For Qt 5.14.0 and above, set text as Markdown if it starts with '#'
if (text.trimmed().startsWith('#')) {
ui->textEdit->setMarkdown(text);
} else {
ui->textEdit->setText(text);
}
#else
// For Qt versions below 5.14.0, always set text as plain text
ui->textEdit->setText(text);
#endif

ui->textEdit->viewport()->setAutoFillBackground(false);
}
Expand Down
Loading