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

Added Probe Height and laser/drill mode switch #127

Open
wants to merge 3 commits into
base: grbl_1_1
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
53 changes: 49 additions & 4 deletions src/frmmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ bool frmMain::isGCodeFile(QString fileName)
|| fileName.endsWith(".nc", Qt::CaseInsensitive)
|| fileName.endsWith(".ncc", Qt::CaseInsensitive)
|| fileName.endsWith(".ngc", Qt::CaseInsensitive)
|| fileName.endsWith(".gcode", Qt::CaseInsensitive)
|| fileName.endsWith(".tap", Qt::CaseInsensitive);
}

Expand Down Expand Up @@ -363,6 +364,7 @@ void frmMain::loadSettings()
m_settings->setLaserPowerMax(set.value("laserPowerMax", 100).toInt());
m_settings->setRapidSpeed(set.value("rapidSpeed", 0).toInt());
m_settings->setHeightmapProbingFeed(set.value("heightmapProbingFeed", 0).toInt());
m_settings->setHeightmapProbeHeight(set.value("heightmapProbeHeight", 0).toDouble());
m_settings->setAcceleration(set.value("acceleration", 10).toInt());
m_settings->setToolAngle(set.value("toolAngle", 0).toDouble());
m_settings->setToolType(set.value("toolType", 0).toInt());
Expand Down Expand Up @@ -453,6 +455,9 @@ void frmMain::loadSettings()
ui->cboHeightMapInterpolationType->setCurrentIndex(set.value("heightmapInterpolationType", 0).toInt());
ui->chkHeightMapInterpolationShow->setChecked(set.value("heightmapInterpolationShow", false).toBool());

ui->chkLaserMode->setChecked(set.value("laserMode", false).toBool());
ui->chkUseProbeHeight->setChecked(set.value("useProbeHeight", false).toBool());

foreach (ColorPicker* pick, m_settings->colors()) {
pick->setColor(QColor(set.value(pick->objectName().mid(3), "black").toString()));
}
Expand Down Expand Up @@ -516,6 +521,7 @@ void frmMain::saveSettings()
set.setValue("restoreMode", m_settings->restoreMode());
set.setValue("rapidSpeed", m_settings->rapidSpeed());
set.setValue("heightmapProbingFeed", m_settings->heightmapProbingFeed());
set.setValue("heightmapProbeHeight", m_settings->heightmapProbeHeight());
set.setValue("acceleration", m_settings->acceleration());
set.setValue("toolAngle", m_settings->toolAngle());
set.setValue("toolType", m_settings->toolType());
Expand Down Expand Up @@ -584,6 +590,9 @@ void frmMain::saveSettings()
set.setValue("heightmapInterpolationType", ui->cboHeightMapInterpolationType->currentIndex());
set.setValue("heightmapInterpolationShow", ui->chkHeightMapInterpolationShow->isChecked());

set.setValue("laserMode", ui->chkLaserMode->isChecked());
set.setValue("useProbeHeight", ui->chkUseProbeHeight->isChecked());

foreach (ColorPicker* pick, m_settings->colors()) {
set.setValue(pick->objectName().mid(3), pick->color().name());
}
Expand Down Expand Up @@ -723,7 +732,12 @@ void frmMain::updateControlsState() {

ui->cmdFileSend->menu()->actions().first()->setEnabled(!ui->cmdHeightMapMode->isChecked());

m_selectionDrawer.setVisible(!ui->cmdHeightMapMode->isChecked());
m_selectionDrawer.setVisible(!ui->cmdHeightMapMode->isChecked());

if (ui->cmdHeightMapMode->isChecked()) ui->chkUseProbeHeight->setVisible(true);
else{
ui->chkUseProbeHeight->setVisible(false);
}
}

void frmMain::openPort()
Expand Down Expand Up @@ -1173,6 +1187,7 @@ void frmMain::onSerialPortReadyRead()
// "[PRB:0.000,0.000,0.000:0];ok"
QRegExp rx(".*PRB:([^,]*),([^,]*),([^]^:]*)");
double z = qQNaN();

if (rx.indexIn(response) != -1) {
qDebug() << "probing coordinates:" << rx.cap(1) << rx.cap(2) << rx.cap(3);
z = toMetric(rx.cap(3).toDouble());
Expand Down Expand Up @@ -1609,7 +1624,7 @@ void frmMain::on_cmdFileOpen_clicked()
if (!saveChanges(false)) return;

QString fileName = QFileDialog::getOpenFileName(this, tr("Open"), m_lastFolder,
tr("G-Code files (*.nc *.ncc *.ngc *.tap *.txt);;All files (*.*)"));
tr("G-Code files (*.nc *.ncc *.ngc *.gcode *.tap *.txt);;All files (*.*)"));

if (!fileName.isEmpty()) m_lastFolder = fileName.left(fileName.lastIndexOf(QRegExp("[/\\\\]+")));

Expand Down Expand Up @@ -2618,7 +2633,7 @@ bool frmMain::saveProgramToFile(QString fileName, GCodeTableModel *model)

void frmMain::on_actFileSaveTransformedAs_triggered()
{
QString fileName = (QFileDialog::getSaveFileName(this, tr("Save file as"), m_lastFolder, tr("G-Code files (*.nc *.ncc *.ngc *.tap *.txt)")));
QString fileName = (QFileDialog::getSaveFileName(this, tr("Save file as"), m_lastFolder, tr("G-Code files (*.nc *.ncc *.ngc *.gcode *.tap *.txt)")));

if (!fileName.isEmpty()) {
saveProgramToFile(fileName, &m_programHeightmapModel);
Expand All @@ -2628,7 +2643,7 @@ void frmMain::on_actFileSaveTransformedAs_triggered()
void frmMain::on_actFileSaveAs_triggered()
{
if (!m_heightMapMode) {
QString fileName = (QFileDialog::getSaveFileName(this, tr("Save file as"), m_lastFolder, tr("G-Code files (*.nc *.ncc *.ngc *.tap *.txt)")));
QString fileName = (QFileDialog::getSaveFileName(this, tr("Save file as"), m_lastFolder, tr("G-Code files (*.nc *.ncc *.ngc *.gcode *.tap *.txt)")));

if (!fileName.isEmpty()) if (saveProgramToFile(fileName, &m_programModel)) {
m_programFileName = fileName;
Expand Down Expand Up @@ -3151,6 +3166,7 @@ bool frmMain::updateHeightMapGrid()
// Generate probe program
double gridStepX = gridPointsX > 1 ? borderRect.width() / (gridPointsX - 1) : 0;
double gridStepY = gridPointsY > 1 ? borderRect.height() / (gridPointsY - 1) : 0;
double zoffset = m_settings->heightmapProbeHeight();

qDebug() << "generating probe program";

Expand All @@ -3164,6 +3180,20 @@ bool frmMain::updateHeightMapGrid()
// .arg(ui->txtHeightMapGridZTop->value()));
m_probeModel.setData(m_probeModel.index(m_probeModel.rowCount() - 1, 1), QString("G38.2Z%1")
.arg(ui->txtHeightMapGridZBottom->value()));

if (ui->chkUseProbeHeight->isChecked())
{
// Check if we have to set Z probe offset for non conductive materials
m_probeModel.setData(m_probeModel.index(m_probeModel.rowCount() - 1, 1), QString("G92Z%1") // Set Z to Probe Height
.arg(zoffset));
qDebug() << "Setting Z to Probe Height " << zoffset;

}else
{
m_probeModel.setData(m_probeModel.index(m_probeModel.rowCount() - 1, 1), QString("G92Z0")); // Set Z as 0
qDebug() << "Setting Z to 0 as origin point";
}

m_probeModel.setData(m_probeModel.index(m_probeModel.rowCount() - 1, 1), QString("G0Z%1")
.arg(ui->txtHeightMapGridZTop->value()));

Expand All @@ -3182,6 +3212,8 @@ bool frmMain::updateHeightMapGrid()
}
}

m_probeModel.setData(m_probeModel.index(m_probeModel.rowCount() - 1, 1), QString("G0X0Y0")); // Return to Point of Origin

m_programLoading = false;

if (m_currentDrawer == m_probeDrawer) updateParser();
Expand Down Expand Up @@ -3977,3 +4009,16 @@ void frmMain::on_cmdStop_clicked()
m_queue.clear();
m_serialPort.write(QByteArray(1, char(0x85)));
}

void frmMain::on_chkLaserMode_toggled(bool checked)
{
if(ui->chkLaserMode->isChecked())
{
sendCommand("$32=1",-1,1);
}else
{
sendCommand("$32=0",-1,1);
}

updateControlsState();
}
4 changes: 4 additions & 0 deletions src/frmmain.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ private slots:

void on_cmdStop_clicked();

void on_chkLaserMode_clicked();

void on_chkLaserMode_toggled(bool checked);

protected:
void showEvent(QShowEvent *se);
void hideEvent(QHideEvent *he);
Expand Down
55 changes: 51 additions & 4 deletions src/frmmain.ui
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ QSlider::handle:horizontal:hover {
<double>999.000000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
<double>5.000000000000000</double>
</property>
</widget>
</item>
Expand Down Expand Up @@ -692,7 +692,7 @@ QSlider::handle:horizontal:hover {
<double>999.000000000000000</double>
</property>
<property name="value">
<double>-1.000000000000000</double>
<double>-10.000000000000000</double>
</property>
</widget>
</item>
Expand Down Expand Up @@ -966,6 +966,31 @@ QSlider::handle:horizontal:hover {
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkUseProbeHeight">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>22</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Use Probe Height</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<spacer name="spacerBot">
<property name="orientation">
Expand Down Expand Up @@ -1542,7 +1567,7 @@ QSlider::handle:horizontal:hover {
<x>0</x>
<y>-416</y>
<width>228</width>
<height>691</height>
<height>685</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -2463,11 +2488,33 @@ QSlider::handle:horizontal:hover {
</item>
<item>
<widget class="QCheckBox" name="chkKeyboardControl">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Keyboard control</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkLaserMode">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Laser Mode</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -2616,7 +2663,7 @@ padding-right: 8;</string>
<x>0</x>
<y>0</y>
<width>952</width>
<height>26</height>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="mnuFile">
Expand Down
14 changes: 13 additions & 1 deletion src/frmsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,17 @@ void frmSettings::setHeightmapProbingFeed(int heightmapProbingFeed)
ui->txtHeightMapProbingFeed->setValue(heightmapProbingFeed);
}

double frmSettings::heightmapProbeHeight()
{
return ui->txtHeightMapProbeHeight->value();
}

void frmSettings::setHeightmapProbeHeight(double heightmapProbeHeight)
{
ui->txtHeightMapProbeHeight->setValue(heightmapProbeHeight);
}


int frmSettings::acceleration()
{
return ui->txtAcceleration->value();
Expand Down Expand Up @@ -638,11 +649,12 @@ void frmSettings::on_cmdDefaults_clicked()
setSpindleSpeedMax(10000);
setLaserPowerMin(0);
setLaserPowerMax(100);
setTouchCommand("G21G91G38.2Z-30F100; G0Z1; G38.2Z-2F10");
setTouchCommand("G21G91G38.2Z-30F100; G0Z1; G38.2Z-2F1; G92Z0(change Z0 by your probe Height and delete this text); G1Z5F200");
setSafePositionCommand("G21G90; G53G0Z0");
setMoveOnRestore(false);
setRestoreMode(0);
setHeightmapProbingFeed(10);
setHeightmapProbeHeight(1.55);
setUnits(0);

setArcLength(0.0);
Expand Down
4 changes: 4 additions & 0 deletions src/frmsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class frmSettings : public QDialog
void setRapidSpeed(int rapidSpeed);
int heightmapProbingFeed();
void setHeightmapProbingFeed(int heightmapProbingFeed);
double heightmapProbeHeight();
void setHeightmapProbeHeight(double heightmapProbeHeight);
int acceleration();
void setAcceleration(int acceleration);
int queryStateTime();
Expand Down Expand Up @@ -142,6 +144,8 @@ private slots:

void on_radGrayscaleZ_toggled(bool checked);

void on_chkGrayscale_clicked();

private:
Ui::frmSettings *ui;
void searchPorts();
Expand Down
Loading