summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Kostovsky <luntik2012@gmail.com>2024-11-24 19:55:13 +0100
committerNikita Kostovsky <luntik2012@gmail.com>2024-11-24 19:55:13 +0100
commit05a8166fa1ada3b386a4e0cce30c60f396587476 (patch)
treeb906a7065e823bfa279bbda68e100a7bfb761517
parent8ac3204aa7911aec20967c4d57b92da027b1ad03 (diff)
implement printer controls; implement calibration data collection
-rw-r--r--Main.qml197
-rw-r--r--main.cpp139
2 files changed, 263 insertions, 73 deletions
diff --git a/Main.qml b/Main.qml
index 8d87aab..65fa5a0 100644
--- a/Main.qml
+++ b/Main.qml
@@ -15,8 +15,8 @@ ApplicationWindow {
height: 480
visible: true
// visibility: Window.Maximized
- // visibility: ApplicationWindow.Maximized
- visibility: ApplicationWindow.FullScreen
+ visibility: ApplicationWindow.Maximized
+ // visibility: ApplicationWindow.FullScreen
title: qsTr("Hello World")
@@ -135,13 +135,37 @@ ApplicationWindow {
console.log("response status: ", response.status);
return;
}
+ });
+ }
- // console.log("resetEncoder result:", response.content);
+ function startCalibration() {
+ var url = apiRoot + "/commands/startCalibration";
+ console.log("startCalibration:", url);
- // var json = JSON.parse(response.content);
+ XHR.sendRequest("POST", url, function(response) {
+
+ if (response.status != "200") {
+ console.log("response status: ", response.status);
+ return;
+ }
});
}
+ function sendGCode(gcode) {
+ var url = apiRoot + "/commands/gCode";
+ console.log("gCode:", url);
+
+ var withFeedRate = gcode + " F" + feedRateSpinBox.value
+
+ XHR.sendRequest("POST", url, function(response) {
+
+ if (response.status != "200") {
+ console.log("response status: ", response.status);
+ return;
+ }
+ }, withFeedRate);
+ }
+
RowLayout {
id: horizontalLayout
@@ -154,7 +178,7 @@ ApplicationWindow {
Layout.fillHeight: true
Layout.fillWidth: true
- Layout.minimumWidth: 150
+ Layout.minimumWidth: 250
ColumnLayout {
id: columnLayout
@@ -278,6 +302,10 @@ ApplicationWindow {
onValueChanged: writeParams()
}
+ Label {
+ text: qsTr("Laser level (1/50K):")
+ }
+
SpinBox {
id: laserLevelSpinBox
@@ -300,9 +328,168 @@ ApplicationWindow {
onCheckedChanged: writeParams()
}
+ Label {
+ text: qsTr("Printer distance (mm):")
+ }
+
+ TextField {
+ id: printerDistanceMmTextField
+
+ Layout.fillWidth: true
+
+ text: "10"
+ // onValueChanged: writeParams()
+ }
+
+ Label {
+ text: qsTr("Feed rate (%):")
+ }
+
+ SpinBox {
+ id: feedRateSpinBox
+
+ Layout.fillWidth: true
+
+ from: 1
+ to: 500
+ stepSize: 50
+ editable: true
+
+ value: 300
+ }
+
+ GridLayout {
+ id: printerControlGridLayout
+
+ columns: 4
+
+ Label {
+ Layout.row: 0
+ Layout.column: 1
+
+ text: "X/Y"
+ }
+
+ Label {
+ Layout.row: 0
+ Layout.column: 3
+
+ text: "Z"
+ }
+
+ Button {
+ id: yUpButton
+
+ Layout.row: 1
+ Layout.column: 1
+
+ text: "\u2191"
+ onClicked: sendGCode("G1 Y" + printerDistanceMmTextField.text)
+
+ highlighted: true
+ }
+
+ Button {
+ id: zUpButton
+
+ Layout.row: 1
+ Layout.column: 3
+
+ text: "\u2191"
+ onClicked: sendGCode("G1 Z" + printerDistanceMmTextField.text)
+
+ highlighted: true
+ }
+
+ Button {
+ id: xDownButton
+
+ Layout.row: 2
+ Layout.column: 0
+
+ text: "\u2190"
+ onClicked: sendGCode("G1 X-" + printerDistanceMmTextField.text)
+
+ highlighted: true
+ }
+
+ Button {
+ id: xyHomeButton
+
+ Layout.row: 2
+ Layout.column: 1
+
+ text: "\u2302"
+ // onClicked: sendGCode("G1 X-" + printerDistanceMmSpinBox.text)
+
+ highlighted: true
+ }
+
+ Button {
+ id: xUpButton
+
+ Layout.row: 2
+ Layout.column: 2
+
+ text: "\u2192"
+ onClicked: sendGCode("G1 X" + printerDistanceMmTextField.text)
+
+ highlighted: true
+ }
+
+ Button {
+ id: zHomeButton
+
+ Layout.row: 2
+ Layout.column: 3
+
+ text: "\u2302"
+ // onClicked: sendGCode("G1 X-" + printerDistanceMmSpinBox.text)
+
+ highlighted: true
+ }
+
+ Button {
+ id: yDownButton
+
+ Layout.row: 3
+ Layout.column: 1
+
+ text: "\u2193"
+ onClicked: sendGCode("G1 Y-" + printerDistanceMmTextField.text)
+
+ highlighted: true
+ }
+
+ Button {
+ id: zDownButton
+
+ Layout.row: 3
+ Layout.column: 3
+
+ text: "\u2193"
+ onClicked: sendGCode("G1 Z-" + printerDistanceMmTextField.text)
+
+ highlighted: true
+ }
+ }
+
Button {
+ Layout.fillWidth: true
+
text: qsTr("Reset encoder")
onClicked: resetEncoder()
+
+ highlighted: true
+ }
+
+ Button {
+ Layout.fillWidth: true
+
+ text: qsTr("Start calibration")
+ onClicked: startCalibration()
+
+ highlighted: true
}
Item {
diff --git a/main.cpp b/main.cpp
index 377fc84..34719ef 100644
--- a/main.cpp
+++ b/main.cpp
@@ -59,93 +59,96 @@ int main(int argc, char *argv[])
manager->get(request);
});
- QObject::connect(manager, &QNetworkAccessManager::finished,
- [&](QNetworkReply *reply) {
- // qDebug() << "replyFinished";
- if (reply->error()) {
- qDebug() << "replyFinished:" << reply->errorString();
- return;
- }
+ QObject::connect(manager, &QNetworkAccessManager::finished, [&](QNetworkReply *reply) {
+ // qDebug() << "replyFinished";
+ if (reply->error()) {
+ qDebug() << "replyFinished:" << reply->errorString();
+ reply->deleteLater();
- auto json = QJsonDocument::fromJson(reply->readAll())
- .object();
- auto jsonPixels = json["pixels"].toArray();
- auto encoderPosition = json["encoderPosition"].toInteger();
- auto measurementCounter = json["measurementCounter"].toInteger();
- auto timestampUs = json["timestampUs"].toInteger();
+ return;
+ }
- // y_profile.clear();
+ auto json = QJsonDocument::fromJson(reply->readAll())
+ .object();
+ auto jsonPixels = json["pixels"].toArray();
+ auto encoderPosition = json["encoderPosition"].toInteger();
+ auto measurementCounter = json["measurementCounter"].toInteger();
+ auto timestampUs = json["timestampUs"].toInteger();
- for (int i = 0; i < jsonPixels.count(); ++i) {
- y_profile[i] = jsonPixels.at(i).toDouble();
- }
+ // y_profile.clear();
- QVector<qreal> y_diff(y_profile.count());
- qreal max_diff { 0. };
- qreal min_diff { 1000000. };
- size_t max_diff_idx = 0;
- size_t min_diff_idx = 0;
- qreal avg_diff { 0. };
+ for (int i = 0; i < jsonPixels.count(); ++i) {
+ y_profile[i] = jsonPixels.at(i).toDouble();
+ }
- for (size_t i = 0; i < y_profile.count(); ++i) {
- y_diff[i] = y_profile.at(i) - prev_y_profile.at(i);
+ QVector<qreal> y_diff(y_profile.count());
+ qreal max_diff { 0. };
+ qreal min_diff { 1000000. };
+ size_t max_diff_idx = 0;
+ size_t min_diff_idx = 0;
+ qreal avg_diff { 0. };
- if (y_diff.at(i) > max_diff) {
- max_diff = y_diff.at(i);
- max_diff_idx = i;
- }
+ for (size_t i = 0; i < y_profile.count(); ++i) {
+ y_diff[i] = y_profile.at(i) - prev_y_profile.at(i);
- if (y_diff.at(i) < min_diff) {
- min_diff = y_diff.at(i);
- min_diff_idx = i;
- }
+ if (y_diff.at(i) > max_diff) {
+ max_diff = y_diff.at(i);
+ max_diff_idx = i;
+ }
- avg_diff += fabs(y_diff.at(i));
- }
+ if (y_diff.at(i) < min_diff) {
+ min_diff = y_diff.at(i);
+ min_diff_idx = i;
+ }
- avg_diff /= y_diff.size();
+ avg_diff += fabs(y_diff.at(i));
+ }
- // for (size_t i = 0; i < y_profile.size(); ++i) {
- // if
- // }
+ avg_diff /= y_diff.size();
- // // const auto max_diff = std::max_element(y_diff.begin(), y_diff.end());
- // const auto avg_diff = std::accumulate(y_diff.begin(), y_diff.end(), 0.0) / y_diff.size();
- std::sort(y_diff.begin(), y_diff.end());
- const auto median_diff = y_diff.at(y_diff.size() * 3 / 4);
+ // for (size_t i = 0; i < y_profile.size(); ++i) {
+ // if
+ // }
- // if (qFuzzyIsNull(max_diff)) {
- // qDebug() << "max_diff is null";
+ // // const auto max_diff = std::max_element(y_diff.begin(), y_diff.end());
+ // const auto avg_diff = std::accumulate(y_diff.begin(), y_diff.end(), 0.0) / y_diff.size();
+ std::sort(y_diff.begin(), y_diff.end());
+ const auto median_diff = y_diff.at(y_diff.size() * 3 / 4);
- // static bool done = [&]() -> bool {
- // for (const auto & y : y_profile) {
- // qDebug() << y;
- // }
- // return true;
- // }();
+ // if (qFuzzyIsNull(max_diff)) {
+ // qDebug() << "max_diff is null";
- // manager->get(request);
+ // static bool done = [&]() -> bool {
+ // for (const auto & y : y_profile) {
+ // qDebug() << y;
+ // }
+ // return true;
+ // }();
- // return;
- // }
+ // manager->get(request);
- graph->setData(x_profile, y_profile);
+ // return;
+ // }
- engine.rootContext()->setContextProperty("max_diff", max_diff);
- engine.rootContext()->setContextProperty("max_diff_idx", int(max_diff_idx));
- engine.rootContext()->setContextProperty("min_diff", min_diff);
- engine.rootContext()->setContextProperty("min_diff_idx", int(min_diff_idx));
- engine.rootContext()->setContextProperty("avg_diff", avg_diff);
- engine.rootContext()->setContextProperty("median_diff", median_diff);
- engine.rootContext()->setContextProperty("encoderPosition", encoderPosition);
- engine.rootContext()->setContextProperty("measurementCounter", measurementCounter);
- engine.rootContext()->setContextProperty("timestampUs", timestampUs);
+ graph->setData(x_profile, y_profile);
- manager->get(request);
- pixelsAutoRestartTimer.start();
+ engine.rootContext()->setContextProperty("max_diff", max_diff);
+ engine.rootContext()->setContextProperty("max_diff_idx", int(max_diff_idx));
+ engine.rootContext()->setContextProperty("min_diff", min_diff);
+ engine.rootContext()->setContextProperty("min_diff_idx", int(min_diff_idx));
+ engine.rootContext()->setContextProperty("avg_diff", avg_diff);
+ engine.rootContext()->setContextProperty("median_diff", median_diff);
+ engine.rootContext()->setContextProperty("encoderPosition", encoderPosition);
+ engine.rootContext()->setContextProperty("measurementCounter", measurementCounter);
+ engine.rootContext()->setContextProperty("timestampUs", timestampUs);
- prev_y_profile = y_profile;
- });
+ manager->get(request);
+ pixelsAutoRestartTimer.start();
+
+ prev_y_profile = y_profile;
+
+ reply->deleteLater();
+ });
manager->get(request);
pixelsAutoRestartTimer.start();