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

#41: Debug Graph #92

Merged
merged 19 commits into from
Apr 12, 2024
Merged
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
78 changes: 78 additions & 0 deletions NERODesign/content/DebugGraph.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtCharts 2.6

Item {
id: chartItem
width: 800
height: 480

property string chartTitle: "AVERAGE CELL TEMPERATURE"

property int minX: 0
property int maxX: 20
property string xLabel: "TIME (MS)"

property int minY: 0
property int maxY: 50
property string yLabel: "TEMPERATURE (C)"

property var dummyData: [
{"x": 0, "y": 30},
{"x": 4, "y": 15},
{"x": 6, "y": 30},
{"x": 8, "y": 15},
{"x": 13, "y": 40},
{"x": 18, "y": 15},
{"x": 20, "y": 27}
]

ChartView {
anchors.fill: parent
backgroundColor: "black"
title: chartItem.chartTitle
titleColor: "white"
legend.visible: false

ValuesAxis {
id: xAxis
min: chartItem.minX
max: chartItem.maxX
gridVisible: false
color: "white"
labelsColor: "white"
titleText: "<font color='white'>" + chartItem.xLabel + "</font>"
tickCount: chartItem.maxX + 1
labelFormat: "%d"
}

ValuesAxis {
id: yAxis
min: chartItem.minY
max: chartItem.maxY
gridVisible: false
labelsColor: "white"
color: "white"
titleText: "<font color='white'>" + chartItem.yLabel + "</font>"
tickCount: chartItem.maxY / 5 + 1
labelFormat: "%d"
}

LineSeries {
id: series
name: "Temperature"
color: "red"
axisX: xAxis
axisY: yAxis
}
}

Repeater {
model: dummyData
delegate: Item {
Component.onCompleted: {
series.append(modelData.x, modelData.y);
}
}
}
}
5 changes: 4 additions & 1 deletion NERODevelopment/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ set(PROJECT_SOURCES
src/controllers/flappybirdcontroller.h
src/controllers/keyboardcontroller.h
src/controllers/configurationcontroller.h
src/controllers/debuggraphcontroller.h

src/models/mock_model.h
src/models/model.h
Expand All @@ -51,6 +52,7 @@ set(PROJECT_SOURCES
src/controllers/flappybirdcontroller.cpp
src/controllers/keyboardcontroller.cpp
src/controllers/configurationcontroller.cpp
src/controllers/debuggraphcontroller.cpp

src/models/mock_model.cpp
src/models/model.cpp
Expand All @@ -68,7 +70,7 @@ set(PROJECT_SOURCES
src/controllers/speedcontroller.cpp
)

find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick Network Mqtt Protobuf)
find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick Network Mqtt Protobuf Widgets)

qt_add_executable(NEROApp ${PROJECT_SOURCES})

Expand All @@ -95,6 +97,7 @@ target_link_libraries(NEROApp PRIVATE
Qt6::Mqtt
Qt6::Quick
Qt6::Protobuf
Qt6::Widgets
)

if (BUILD_QDS_COMPONENTS)
Expand Down
2 changes: 1 addition & 1 deletion NERODevelopment/content/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ qt6_add_qml_module(content
CriticalFaultIcon.qml
NonCriticalWarning.qml
MicrophoneComponent.qml
DebugGraph.qml
EfficiencyScreen.qml

TorqueValueComponent.qml
TorqueAdj.qml

Expand Down
79 changes: 79 additions & 0 deletions NERODevelopment/content/DebugGraph.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtCharts 2.6
import NERO

Item {
id: chartItem
width: 800
height: 480

property string chartTitle: ""

property int minX: 0
property int maxX: debugGraphController.graphData.length
property string xLabel: "TIME (MS)"

property int minY: debugGraphController.minY
property int maxY: debugGraphController.maxY
property string yLabel: ""

property var dummyData: debugGraphController.graphData

onDummyDataChanged: {
console.log(maxX)
series.clear()
}

onVisibleChanged: {
debugGraphController.setTitle(chartTitle)
}
ChartView {
anchors.fill: parent
backgroundColor: "black"
title: chartItem.chartTitle
titleColor: "white"
legend.visible: false

ValuesAxis {
id: xAxis
min: chartItem.minX
max: chartItem.maxX
gridVisible: false
color: "white"
labelsColor: "white"
titleText: "<font color='white'>" + chartItem.xLabel + "</font>"
tickCount: chartItem.maxX - chartItem.minX + 1
labelFormat: "%d"
}

ValuesAxis {
id: yAxis
min: chartItem.minY
max: chartItem.maxY
gridVisible: false
labelsColor: "white"
color: "white"
titleText: "<font color='white'>" + chartItem.yLabel + "</font>"
tickCount: 5
labelFormat: "%d"
}

LineSeries {
id: series
name: "Temperature"
color: "red"
axisX: xAxis
axisY: yAxis
}
}

Repeater {
model: dummyData
delegate: Item {
Component.onCompleted: {
series.append(modelData.x, modelData.y)
}
}
}
}
18 changes: 14 additions & 4 deletions NERODevelopment/content/DebugTable.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import NERO

Item {
id: debugTable
width: 800
height: 480
anchors.fill: parent

property variant topics: debugTableController.topics
property variant values: debugTableController.selectedValues
property int selectedTopicIndex: debugTableController.selectedTopicsIndex
property int selectedValueIndex: debugTableController.selectedValuesIndex
property bool scrollingTopics: debugTableController.scrollingTopics
property bool showGraph: debugTableController.showGraph

property int rowHeight: 30

Expand All @@ -30,6 +30,9 @@ Item {
case Qt.Key_Down:
debugTableController.downButtonPressed()
break
case Qt.Key_Return:
debugTableController.enterButtonPressed()
break
default:
break
}
Expand Down Expand Up @@ -139,12 +142,19 @@ Item {
}
}

property var columnWidths: [valuesTableView.width * 3
/ 4, valuesTableView.width / 8, valuesTableView.width / 8]
property var columnWidths: [valuesTableView.width
/ 2, valuesTableView.width / 4, valuesTableView.width / 4]
columnWidthProvider: function (column) {
return columnWidths[column]
}
}
}
}

DebugGraph {
visible: showGraph
chartTitle: values[selectedValueIndex]["id"]
yLabel: values[selectedValueIndex]["unit"]
anchors.fill: parent
}
}
2 changes: 1 addition & 1 deletion NERODevelopment/content/NavigationController.qml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Item {
}

HomeMenuItem {
highlighted: selectedPageIndex === 5
highlighted: selectedPageIndex === 6
text: "Exit"
}
}
Expand Down
108 changes: 108 additions & 0 deletions NERODevelopment/src/controllers/debuggraphcontroller.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#include "debuggraphcontroller.h"

DebugGraphController::DebugGraphController(Model *model, QObject *parent)
: ButtonController(model, 3, parent) {
connect(model, &Model::onCurrentDataChange, this,
&DebugGraphController::update);
}

QList<QJsonObject> DebugGraphController::graphData() const {
return this->m_graphData;
}

QString DebugGraphController::unit() const { return this->m_unit; }

QString DebugGraphController::title() const { return this->m_title; }

int DebugGraphController::maxY() const { return this->m_maxY; }

int DebugGraphController::minY() const { return this->m_minY; }

int DebugGraphController::getNumPoints() { return this->m_num_points; }

void DebugGraphController::setGraphData(QList<QJsonObject> json) {
if (this->m_graphData != json) {
this->m_graphData = json;
emit this->graphDataChanged();
}
}

void DebugGraphController::setUnit(QString unit) { this->m_unit = unit; }

void DebugGraphController::setTitle(QString title) {
if (m_title == title) {
this->m_model->removePinnedData(title);
return;
}
this->m_title = title;
this->m_model->addPinnedData(title);
emit this->titleChanged();
}

void DebugGraphController::setMaxY(int max) {
if (this->m_maxY != max) {
this->m_maxY = max;
emit this->maxYChanged();
}
}

void DebugGraphController::setMinY(int min) {
if (this->m_minY != min) {
this->m_minY = min;
emit this->minYChanged();
}
}

void DebugGraphController::setValues(QString title, QString unit) {
setUnit(unit);
setTitle(title);
}

void DebugGraphController::update() {
if (this->m_model->currentPageIndex != this->m_pageIndex)
return;

if (QDateTime::currentMSecsSinceEpoch() - this->m_last_refresh <
this->m_refresh_rate) {
return;
}
this->m_last_refresh = QDateTime::currentMSecsSinceEpoch();

this->m_model->updatePinnedData();

QList<QJsonObject> allPoints;
QMap<QString, DebugPlotValue> pinnedData = this->m_model->getPinnedData();

int globalIndex = this->m_num_points - 1;

const QList<float> &dataList = pinnedData[this->m_title].data;

for (int i = 0; i < std::min(this->m_num_points, (int)dataList.length());
++i) {
float value = dataList.at(i);
if (!std::isnan(value) && std::isfinite(value)) {
QJsonObject point;
point["x"] = globalIndex--;
point["y"] = value;
allPoints.append(point);
}
}

int maxY = -99999;
int minY = 99999;

for (const QJsonObject &point : allPoints) {
int yValue = point["y"].toInt();
if (yValue > maxY) {
maxY = yValue;
}
if (yValue < minY) {
minY = yValue;
}
}

setMaxY(maxY + 5);
setMinY(minY - 5);

setGraphData(allPoints);
}
Loading
Loading