-
Notifications
You must be signed in to change notification settings - Fork 9
/
calibratedialog.cpp
181 lines (161 loc) · 7.26 KB
/
calibratedialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include "calibratedialog.h"
#include "ui_calibratedialog.h"
CalibrateDialog::CalibrateDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::CalibrateDialog)
{
ui->setupUi(this);
ui->EGroup->hide();
}
CalibrateDialog::~CalibrateDialog()
{
delete ui;
}
QVector4D CalibrateDialog::getCallibrationsSetting(){
QVector4D out(ui->xCurrentSteps->text().toDouble(),ui->yCurrentSteps->text().toDouble(),ui->zCurrentSteps->text().toDouble(),ui->eCurrentSteps->text().toDouble());
return out;
}
bool CalibrateDialog::autoCalibrateX(){
return ui->XGroup->isChecked();
}
bool CalibrateDialog::autoCalibrateY(){
return ui->YGroup->isChecked();
}
bool CalibrateDialog::autoCalibrateZ(){
return ui->ZGroup->isChecked();
}
bool CalibrateDialog::autoCalibrateE(){
return ui->EGroup->isChecked();
}
void CalibrateDialog::setAutoCalibrateX(bool calibrate){
return ui->XGroup->setChecked(calibrate);
}
void CalibrateDialog::setAutoCalibrateY(bool calibrate){
return ui->YGroup->setChecked(calibrate);
}
void CalibrateDialog::setAutoCalibrateZ(bool calibrate){
return ui->ZGroup->setChecked(calibrate);
}
void CalibrateDialog::setAutoCalibrateE(bool calibrate){
return ui->EGroup->setChecked(calibrate);
}
void CalibrateDialog::setXStepsPerMm(double value){
ui->xCurrentSteps->setText(QString::number(value));
}
void CalibrateDialog::setYStepsPerMm(double value){
ui->yCurrentSteps->setText(QString::number(value));
}
void CalibrateDialog::setZStepsPerMm(double value){
ui->zCurrentSteps->setText(QString::number(value));
}
void CalibrateDialog::setEStepsPerMm(double value){
ui->eCurrentSteps->setText(QString::number(value));
}
void CalibrateDialog::on_calibrateXBtn_clicked()
{
bool okM1=false;
bool okM2=false;
emit writeToPrinter("G28 X0");
emit writeToPrinter("M92 X"+ui->xCurrentSteps->text());
double currentStepsPerMm = ui->xCurrentSteps->text().toDouble();
double newStepsPerMm = ui->xCurrentSteps->text().toDouble();
double calibrationDistance = 50;
double firstMeasurment = QInputDialog::getDouble(this, tr("Input first measurment"),
tr("Measurment"), 0, 0, 10000, 2, &okM1);
if (okM1){
emit writeToPrinter("G1 X"+QString::number(calibrationDistance)+" F1000");
double secondMeasurment = QInputDialog::getDouble(this, tr("Input second measurment"),
tr("Measurment"), calibrationDistance, 0, 10000, 2, &okM1);
if(okM2){
newStepsPerMm=(calibrationDistance/qAbs((secondMeasurment-firstMeasurment)))*currentStepsPerMm;
ui->xCurrentSteps->setText(QString::number(newStepsPerMm));
emit writeToPrinter("M92 X"+ui->xCurrentSteps->text());
double error =qAbs((double)1-(calibrationDistance/(secondMeasurment-firstMeasurment)));
if(error>0.01){
QMessageBox *msgBox = new QMessageBox(this);
msgBox->setWindowTitle(tr("Error"));
msgBox->setText(tr("Error is %1 %, continue callibrating?").arg(QString::number(error*100)));
QPushButton *yesButton = msgBox->addButton(tr("Yes"), QMessageBox::ActionRole);
msgBox->addButton(tr("No"), QMessageBox::ActionRole);
msgBox->exec();
//If user clicks 'Yes' button , accept QCloseEvent (Close Window)
if ((QPushButton*)msgBox->clickedButton() == yesButton)
{
on_calibrateXBtn_clicked();
}
}
}
}
}
void CalibrateDialog::on_calibrateYBtn_clicked()
{
bool okM1=false;
bool okM2=false;
emit writeToPrinter("G28 Y0");
emit writeToPrinter("M92 Y"+ui->yCurrentSteps->text());
double currentStepsPerMm = ui->yCurrentSteps->text().toDouble();
double newStepsPerMm = ui->yCurrentSteps->text().toDouble();
double calibrationDistance = 50;
double firstMeasurment = QInputDialog::getDouble(this, tr("Input first measurment"),
tr("Measurment"), 0, 0, 10000, 2, &okM1);
if (okM1){
emit writeToPrinter("G1 Y"+QString::number(calibrationDistance)+" F1000");
double secondMeasurment = QInputDialog::getDouble(this, tr("Input second measurment"),
tr("Measurment"), calibrationDistance, 0, 10000, 2, &okM1);
if(okM2){
newStepsPerMm=(calibrationDistance/qAbs((secondMeasurment-firstMeasurment)))*currentStepsPerMm;
ui->yCurrentSteps->setText(QString::number(newStepsPerMm));
emit writeToPrinter("M92 Y"+ui->yCurrentSteps->text());
double error =qAbs((double)1-(calibrationDistance/(secondMeasurment-firstMeasurment)));
if(error>0.01){
QMessageBox *msgBox = new QMessageBox(this);
msgBox->setWindowTitle(tr("Error"));
msgBox->setText(tr("Error is %1 %, continue callibrating?").arg(QString::number(error*100)));
QPushButton *yesButton = msgBox->addButton(tr("Yes"), QMessageBox::ActionRole);
msgBox->addButton(tr("No"), QMessageBox::ActionRole);
msgBox->exec();
//If user clicks 'Yes' button , accept QCloseEvent (Close Window)
if ((QPushButton*)msgBox->clickedButton() == yesButton)
{
on_calibrateYBtn_clicked();
}
}
}
}
}
void CalibrateDialog::on_calibrateZBtn_clicked()
{
bool okM1=false;
bool okM2=false;
emit writeToPrinter("G28 Z0");
emit writeToPrinter("M92 Z"+ui->zCurrentSteps->text());
double currentStepsPerMm = ui->zCurrentSteps->text().toDouble();
double newStepsPerMm = ui->zCurrentSteps->text().toDouble();
double calibrationDistance = 50;
double firstMeasurment = QInputDialog::getDouble(this, tr("Input first measurment"),
tr("Measurment"), 0, 0, 10000, 2, &okM1);
if (okM1){
emit writeToPrinter("G1 Z"+QString::number(calibrationDistance)+" F200");
double secondMeasurment = QInputDialog::getDouble(this, tr("Input second measurment"),
tr("Measurment"), calibrationDistance, 0, 10000, 2, &okM1);
if(okM2){
newStepsPerMm=(calibrationDistance/qAbs((secondMeasurment-firstMeasurment)))*currentStepsPerMm;
ui->zCurrentSteps->setText(QString::number(newStepsPerMm));
emit writeToPrinter("M92 Z"+ui->zCurrentSteps->text());
double error =qAbs((double)1-(calibrationDistance/(secondMeasurment-firstMeasurment)));
if(error>0.01){
QMessageBox *msgBox = new QMessageBox(this);
msgBox->setWindowTitle(tr("Error"));
msgBox->setText(tr("Error is %1 %, continue callibrating?").arg(QString::number(error*100)));
QPushButton *yesButton = msgBox->addButton(tr("Yes"), QMessageBox::ActionRole);
msgBox->addButton(tr("No"), QMessageBox::ActionRole);
msgBox->exec();
//If user clicks 'Yes' button , accept QCloseEvent (Close Window)
if ((QPushButton*)msgBox->clickedButton() == yesButton)
{
on_calibrateZBtn_clicked();
}
}
}
}
}