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

Real-time data performance mods #205

Open
wants to merge 5 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
17 changes: 15 additions & 2 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ MainWindow::MainWindow(QWidget *parent) :
mKeyLeft = false;
mKeyRight = false;

shouldUpdateDisplayBars = false;

connect(mDebugTimer, SIGNAL(timeout()),
this, SLOT(timerSlotDebugMsg()));
connect(mTimer, SIGNAL(timeout()),
Expand Down Expand Up @@ -481,6 +483,8 @@ MainWindow::MainWindow(QWidget *parent) :
mPollImuTimer.start(int(1000.0 / mSettings.value("poll_rate_imu_data", 50).toDouble()));
mPollBmsTimer.start(int(1000.0 / mSettings.value("poll_rate_bms_data", 10).toDouble()));

mRepaintDisplayBarTimer.start(1000.0/30); // Set the refresh rate to 30Hz

connect(&mPollRtTimer, &QTimer::timeout, [this]() {
if (ui->actionRtData->isChecked()) {
mVesc->commands()->getValues();
Expand Down Expand Up @@ -514,6 +518,15 @@ MainWindow::MainWindow(QWidget *parent) :
}
});

connect(&mRepaintDisplayBarTimer, &QTimer::timeout, [this]() {
if (shouldUpdateDisplayBars) {
ui->dispCurrent->setVal(mMcValues.current_motor);
ui->dispDuty->setVal(mMcValues.duty_now * 100.0);

shouldUpdateDisplayBars = false;
}
});

// Restore size and position
if (mSettings.contains("mainwindow/size")) {
resize(mSettings.value("mainwindow/size").toSize());
Expand Down Expand Up @@ -951,8 +964,8 @@ void MainWindow::serialPortNotWritable(const QString &port)
void MainWindow::valuesReceived(MC_VALUES values, unsigned int mask)
{
(void)mask;
ui->dispCurrent->setVal(values.current_motor);
ui->dispDuty->setVal(values.duty_now * 100.0);
mMcValues = values;
shouldUpdateDisplayBars = true;
}

void MainWindow::paramChangedDouble(QObject *src, QString name, double newParam)
Expand Down
4 changes: 4 additions & 0 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,16 @@ private slots:
bool mKeyRight;
bool mMcConfRead;
bool mAppConfRead;
bool shouldUpdateDisplayBars;
QMap<QString, int> mPageNameIdList;

QTimer mPollRtTimer;
QTimer mPollAppTimer;
QTimer mPollImuTimer;
QTimer mPollBmsTimer;
QTimer mRepaintDisplayBarTimer;

MC_VALUES mMcValues;

PageWelcome *mPageWelcome;
PageConnection *mPageConnection;
Expand Down
2 changes: 2 additions & 0 deletions mobile/StatPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Vedder.vesc.utility 1.0
Item {
property Commands mCommands: VescIf.commands()
property bool isHorizontal: width > height
property alias updateData: commandsUpdate.enabled

Component.onCompleted: {
mCommands.emitEmptyStats()
Expand Down Expand Up @@ -87,6 +88,7 @@ Item {
}

Connections {
id: commandsUpdate
target: mCommands

onValuesSetupReceived: {
Expand Down
4 changes: 2 additions & 2 deletions pages/pageappadc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ void PageAppAdc::paramChangedDouble(QObject *src, QString name, double newParam)
y.append(val);
}
ui->throttlePlot->graph()->setData(x, y);
ui->throttlePlot->rescaleAxes();
ui->throttlePlot->replot();
ui->throttlePlot->rescaleAxesWhenVisible();
ui->throttlePlot->replotWhenVisible();
}
}

Expand Down
3 changes: 1 addition & 2 deletions pages/pageappbalance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ void PageAppBalance::timerSlot()
}
ui->balancePlot->graph(graphIndex++)->setData(xAxis, mAppDebug2);

ui->balancePlot->rescaleAxes();

ui->balancePlot->rescaleAxesWhenVisible();
ui->balancePlot->replotWhenVisible();

updateTextOutput();
Expand Down
6 changes: 3 additions & 3 deletions pages/pageappimu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ void PageAppImu::timerSlot()
ui->gyroPlot->graph(graphIndex++)->setData(xAxis, mGyroYVec);
ui->gyroPlot->graph(graphIndex++)->setData(xAxis, mGyroZVec);

ui->rpyPlot->rescaleAxes();
ui->accelPlot->rescaleAxes();
ui->gyroPlot->rescaleAxes();
ui->rpyPlot->rescaleAxesWhenVisible();
ui->accelPlot->rescaleAxesWhenVisible();
ui->gyroPlot->rescaleAxesWhenVisible();

ui->rpyPlot->replotWhenVisible();
ui->accelPlot->replotWhenVisible();
Expand Down
3 changes: 2 additions & 1 deletion pages/pageappnunchuk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ void PageAppNunchuk::paramChangedDouble(QObject *src, QString name, double newPa
y.append(val);
}
ui->throttlePlot->graph()->setData(x, y);
ui->throttlePlot->rescaleAxes();

ui->throttlePlot->rescaleAxesWhenVisible();
ui->throttlePlot->replotWhenVisible();
}
}
Expand Down
4 changes: 3 additions & 1 deletion pages/pageappppm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ void PageAppPpm::paramChangedDouble(QObject *src, QString name, double newParam)
double val = Utility::throttle_curve(i, val_acc, val_brake, mode);
y.append(val);
}

ui->throttlePlot->graph()->setData(x, y);
ui->throttlePlot->rescaleAxes();

ui->throttlePlot->rescaleAxesWhenVisible();
ui->throttlePlot->replotWhenVisible();
}
}
Expand Down
2 changes: 1 addition & 1 deletion pages/pageexperiments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ void PageExperiments::plotSamples(bool exportFormat)
}

if (ui->autoscaleButton->isChecked()) {
ui->plot->rescaleAxes();
ui->plot->rescaleAxesWhenVisible();
}

ui->plot->replotWhenVisible();
Expand Down
8 changes: 4 additions & 4 deletions pages/pageimu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,10 @@ void PageImu::timerSlot()
ui->magPlot->graph(graphIndex++)->setData(xAxis, mMagYVec);
ui->magPlot->graph(graphIndex++)->setData(xAxis, mMagZVec);

ui->rpyPlot->rescaleAxes();
ui->accelPlot->rescaleAxes();
ui->gyroPlot->rescaleAxes();
ui->magPlot->rescaleAxes();
ui->rpyPlot->rescaleAxesWhenVisible();
ui->accelPlot->rescaleAxesWhenVisible();
ui->gyroPlot->rescaleAxesWhenVisible();
ui->magPlot->rescaleAxesWhenVisible();

ui->rpyPlot->replotWhenVisible();
ui->accelPlot->replotWhenVisible();
Expand Down
32 changes: 17 additions & 15 deletions pages/pagertdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ void PageRtData::timerSlot()
}
}

if (mUpdateValPlot) {
if (mUpdateValPlot == true) {
int dataSize = mTempMosVec.size();

QVector<double> xAxis(dataSize);
Expand Down Expand Up @@ -318,7 +318,6 @@ void PageRtData::timerSlot()
ui->tempPlot->graph(graphIndex)->setName("Temperature Motor");
ui->tempPlot->graph(graphIndex)->setData(xAxis, mTempMotorVec);
ui->tempPlot->graph(graphIndex)->setVisible(ui->tempShowMotorBox->isChecked());
graphIndex++;

// RPM plot
graphIndex = 0;
Expand All @@ -331,11 +330,13 @@ void PageRtData::timerSlot()
ui->focPlot->graph(graphIndex++)->setData(xAxis, mVdVec);
ui->focPlot->graph(graphIndex++)->setData(xAxis, mVqVec);

// Check if we should rescale the graphs
if (ui->autoscaleButton->isChecked()) {
ui->currentPlot->rescaleAxes();
ui->tempPlot->rescaleAxes();
ui->rpmPlot->rescaleAxes();
ui->focPlot->rescaleAxes();
// Only rescale if visible
ui->currentPlot->rescaleAxesWhenVisible();
ui->tempPlot->rescaleAxesWhenVisible();
ui->rpmPlot->rescaleAxesWhenVisible();
ui->focPlot->rescaleAxesWhenVisible();
}

ui->currentPlot->replotWhenVisible();
Expand All @@ -346,7 +347,7 @@ void PageRtData::timerSlot()
mUpdateValPlot = false;
}

if (mUpdatePosPlot) {
if (mUpdatePosPlot == true) {
QVector<double> xAxis(mPositionVec.size());
for (int i = 0;i < mPositionVec.size();i++) {
xAxis[i] = double(i);
Expand All @@ -356,15 +357,15 @@ void PageRtData::timerSlot()
ui->posPlot->graph(0)->setData(xAxis, mPositionVec);

if (ui->autoscaleButton->isChecked()) {
ui->posPlot->rescaleAxes();
ui->posPlot->rescaleAxesWhenVisible();
}

ui->posPlot->replotWhenVisible();

mUpdatePosPlot = false;
}

if (mExperimentReplot) {
if (mExperimentReplot == true) {
ui->experimentPlot->clearGraphs();

for (int i = 0;i < mExperimentPlots.size();i++) {
Expand Down Expand Up @@ -396,10 +397,11 @@ void PageRtData::timerSlot()
ui->experimentPlot->legend->setVisible(mExperimentPlots.size() > 1);

if (ui->experimentAutoScaleButton->isChecked()) {
ui->experimentPlot->rescaleAxes();
ui->experimentPlot->rescaleAxesWhenVisible();
}

ui->experimentPlot->replotWhenVisible();

mExperimentReplot = false;
}
}
Expand Down Expand Up @@ -540,11 +542,11 @@ void PageRtData::on_zoomVButton_toggled(bool checked)

void PageRtData::on_rescaleButton_clicked()
{
ui->currentPlot->rescaleAxes();
ui->tempPlot->rescaleAxes();
ui->rpmPlot->rescaleAxes();
ui->focPlot->rescaleAxes();
ui->posPlot->rescaleAxes();
ui->currentPlot->rescaleAxesWhenVisible();
ui->tempPlot->rescaleAxesWhenVisible();
ui->rpmPlot->rescaleAxesWhenVisible();
ui->focPlot->rescaleAxesWhenVisible();
ui->posPlot->rescaleAxesWhenVisible();

ui->currentPlot->replotWhenVisible();
ui->tempPlot->replotWhenVisible();
Expand Down
33 changes: 33 additions & 0 deletions pages/pagewelcome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <QSettings>
#include <QmlHighlighter>
#include <QQuickItem>
#include <QQmlProperty>


PageWelcome::PageWelcome(QWidget *parent) :
QWidget(parent),
Expand Down Expand Up @@ -113,8 +115,39 @@ void PageWelcome::setVesc(VescInterface *vesc)
ui->qmlWidget->engine()->rootContext()->setContextProperty("Utility", &mUtil);

ui->qmlWidget->setSource(QUrl(QLatin1String("qrc:/res/qml/WelcomeQmlPanel.qml")));

// Install an event filter to monitor for when this QML widget becomes hidden
ui->qmlWidget->installEventFilter(this);
}


bool PageWelcome::eventFilter(QObject *obj, QEvent *event)
{
switch(event->type()) {
case QEvent::Show: {
// Set the telemetry to active when this page is visible
bool ret = QQmlProperty::write(ui->qmlWidget->rootObject(), "shouldTelemetryBeActive", true);
if (ret == false) {
qDebug() << "[QML][Error] shouldTelemetryBeActive was not successfully written. Perhaps that variable no longer exists in the QML component file?";
}
} break;
case QEvent::Hide: {
// Set the telemetry to inactive when this page is not visible
bool ret = QQmlProperty::write(ui->qmlWidget->rootObject(), "shouldTelemetryBeActive", false);

if (ret == false) {
qDebug() << "[QML][Error] shouldTelemetryBeActive was not successfully written. Perhaps that variable no longer exists in the QML component file?";
}
} break;
default: {
} break;
}

return QObject::eventFilter(obj, event);
}



void PageWelcome::on_autoConnectButton_clicked()
{
Utility::autoconnectBlockingWithProgress(mVesc, this);
Expand Down
3 changes: 3 additions & 0 deletions pages/pagewelcome.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ private slots:
QmlUi mQmlUi;
Utility mUtil;

protected:
bool eventFilter(QObject *obj, QEvent *event);

};

#endif // PAGEWELCOME_H
4 changes: 4 additions & 0 deletions res/qml/WelcomeQmlPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Item {
property int notchBot: 0
property int notchTop: 0

property bool shouldTelemetryBeActive: true

function setupMotors() {
if (!VescIf.isPortConnected()) {
VescIf.emitMessageDialog("Setup motors FOC",
Expand Down Expand Up @@ -213,13 +215,15 @@ Item {
RtDataSetup {
anchors.fill: parent
dialogParent: container
updateData: shouldTelemetryBeActive
}
}

Page {
StatPage {
anchors.fill: parent
anchors.margins: 20
updateData: shouldTelemetryBeActive
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions widgets/qcustomplot.h
Original file line number Diff line number Diff line change
Expand Up @@ -3910,6 +3910,14 @@ class QCP_LIB_DECL QCustomPlot : public QWidget
QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2;
QCPLegend *legend;

void rescaleAxesWhenVisible() {
if (isVisible()) {
rescaleAxes();
} else {
doRescaleOnShow = true;
}
}

void replotWhenVisible() {
if (isVisible()) {
replot(rpQueuedReplot);
Expand Down Expand Up @@ -3940,11 +3948,18 @@ class QCP_LIB_DECL QCustomPlot : public QWidget
void afterReplot();

protected:
bool doRescaleOnShow;
bool doReplotOnShow;

virtual void showEvent(QShowEvent *event) override
{
(void)event;

// Catch up on any queued events
if (doRescaleOnShow) {
rescaleAxes();
doRescaleOnShow = false;
}
if (doReplotOnShow) {
replot(rpQueuedReplot);
doReplotOnShow = false;
Expand Down
Loading