Skip to content

Add Surfacing Wizard (GRBL panel) #197

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

Merged
merged 4 commits into from
Oct 8, 2021
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
Binary file added .DS_Store
Binary file not shown.
Binary file modified index.html.gz
Binary file not shown.
Binary file modified languages/de/index.html.gz
Binary file not shown.
Binary file modified languages/en/index.html.gz
Binary file not shown.
Binary file modified languages/es/index.html.gz
Binary file not shown.
Binary file modified languages/fr/index.html.gz
Binary file not shown.
Binary file modified languages/grbl/index.html.gz
Binary file not shown.
Binary file modified languages/hu/index.html.gz
Binary file not shown.
Binary file modified languages/it/index.html.gz
Binary file not shown.
Binary file modified languages/ja/index.html.gz
Binary file not shown.
Binary file modified languages/multi/index.html.gz
Binary file not shown.
Binary file modified languages/pl/index.html.gz
Binary file not shown.
Binary file modified languages/ptbr/index.html.gz
Binary file not shown.
Binary file modified languages/ru/index.html.gz
Binary file not shown.
Binary file modified languages/tr/index.html.gz
Binary file not shown.
Binary file modified languages/uk/index.html.gz
Binary file not shown.
Binary file modified languages/zh_CN/index.html.gz
Binary file not shown.
158 changes: 158 additions & 0 deletions www/js/grbl.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var interval_status = -1;
var probe_progress_status = 0;
var surface_progress_status = 0;
var grbl_error_msg = "";
var gotWCO = false;
var WCOx = 0;
Expand Down Expand Up @@ -124,6 +125,24 @@ function onprobetouchplatethicknessChange() {
return true;
}

function onsurfacewidthChange() {
var travel = parseFloat(document.getElementById('surfacewidth').value);
if (travel > 9999 || travel <= 0 || isNaN(travel) || (travel === null)) {
alertdlg(translate_text_item("Out of range"), translate_text_item("Value of surface width must be between 1 mm and 9999 mm !"));
return false;
}
return true;
}

function onsurfacelengthChange() {
var travel = parseFloat(document.getElementById('surfacelength').value);
if (travel > 9999 || travel <= 0 || isNaN(travel) || (travel === null)) {
alertdlg(translate_text_item("Out of range"), translate_text_item("Value of surface length must be between 1 mm and 9999 mm !"));
return false;
}
return true;
}

function on_autocheck_status(use_value) {
if (probe_progress_status != 0) {
document.getElementById('autocheck_status').checked = true;
Expand Down Expand Up @@ -289,6 +308,9 @@ function process_grbl_status(response) {
if (probe_progress_status != 0) {
probe_failed_notification();
}
if (surface_progress_status != 0) {
surface_failed_notification();
}
//grbl_error_msg = "";
//check we are printing or not
if (response.indexOf("|SD:") != -1) {
Expand All @@ -303,6 +325,10 @@ function process_grbl_status(response) {
document.getElementById('sd_reset_btn').style.display = "none";
}
if (tab2.toLowerCase().startsWith("idle")) {

if(surface_progress_status == 100) {
finalize_surfacing();
}
grbl_error_msg = "";
}
document.getElementById('grbl_status_text').innerHTML = translate_text_item(grbl_error_msg);
Expand All @@ -317,6 +343,16 @@ function finalize_probing() {
document.getElementById("probingtext").style.display = "none";
document.getElementById('sd_pause_btn').style.display = "none";
document.getElementById('sd_resume_btn').style.display = "none";
document.getElementById('sd_reset_btn').style.display = "none";
}

function finalize_surfacing() {
surface_progress_status = 0;
grbl_error_msg = "";
document.getElementById("surfacebtn").style.display = "table-row";
document.getElementById("surfacingtext").style.display = "none";
document.getElementById('sd_pause_btn').style.display = "none";
document.getElementById('sd_resume_btn').style.display = "none";
document.getElementById('sd_reset_btn').style.display = "none";
}

Expand All @@ -334,6 +370,9 @@ function process_grbl_SD(response) {
progress = progress.replace(">", "");
}
document.getElementById('grbl_SD_status').innerHTML = sdname + "&nbsp;<progress id='print_prg' value=" + progress + " max='100'></progress>" + progress + "%";
if(progress == 100 & surface_progress_status != 0) {
surface_progress_status = progress;
}
} else { //no SD printing
//TODO
document.getElementById('grbl_SD_status').innerHTML = "";
Expand Down Expand Up @@ -375,6 +414,7 @@ function grbl_process_msg(response) {

function grbl_reset() {
if (probe_progress_status != 0) probe_failed_notification();
if (surface_progress_status != 0) surface_failed_notification();
SendRealtimeCmd(String.fromCharCode(0x18));
}

Expand Down Expand Up @@ -410,8 +450,15 @@ function probe_failed_notification() {
beep(70, 261);
}

function surface_failed_notification() {
finalize_surfacing();
alertdlg(translate_text_item("Error"), translate_text_item("Surfacing failed !"));
beep(70, 261);
}

function StartProbeProcess() {
var cmd = "G38.2 G91 Z-";

if (!onprobemaxtravelChange() ||
!onprobefeedrateChange() ||
!onprobetouchplatethicknessChange()) {
Expand All @@ -427,3 +474,114 @@ function StartProbeProcess() {
grbl_error_msg = "";
document.getElementById('grbl_status_text').innerHTML = grbl_error_msg;
}

function StartSurfaceProcess() {
var path = "/";
var dirname = "SurfaceWizard";

var bitdiam = document.getElementById('surfacebitdiam').value;;
var stepover = document.getElementById('surfacestepover').value;;
var feedrate = document.getElementById('surfacefeedrate').value;;
var surfacewidth = document.getElementById('surfacewidth').value;
var surfacelength = document.getElementById('surfacelength').value;
var Zdepth = document.getElementById('surfacezdepth').value;
var spindle = document.getElementById('surfacespindle').value;

ncProg = CreateSurfaceProgram(bitdiam, stepover, feedrate, surfacewidth, surfacelength, Zdepth, spindle);

filename = "Surface" + "_X" + surfacewidth + "_Y" + surfacelength + "_Z-" + Zdepth + ".nc";

var blob = new Blob([ncProg], {type: "txt"});

file = new File([blob], filename);

grbl_wiz_step1_dir(path, dirname, file);
}

function grbl_wiz_step1_dir(path, dirname, file) {
var url = "/upload?path=" + encodeURIComponent(path) + "&action=createdir&filename=" + encodeURIComponent(dirname);
//console.log("path " + path + " dirname " + dirname + " filename " + file.name)
SendGetHttp(url, function() { grbl_wiz_step2_upload(file, path + dirname + "/") }, function() { grbl_wiz_error_dir(path, dirname) });
}

function grbl_wiz_step2_upload(file, path) {
if (http_communication_locked) {
alertdlg(translate_text_item("Busy..."), translate_text_item("Communications are currently locked, please wait and retry."));
console.log("communication locked");
return;
}

var url = "/upload";
//console.log("path + file.name ", path + file.name);
var formData = new FormData();
var arg = path + file.name + "S";
//append file size first to check updload is complete
formData.append(arg, file.size);
formData.append('path', path);
formData.append('myfile[]', file, path + file.name);
formData.append('path', path);
SendFileHttp(url, formData, FilesUploadProgressDisplay, function() { grbl_wiz_step3_launch(path + filename) }, function() { grbl_wiz_error_upload(file, path)});
}

function grbl_wiz_step3_launch(filename) {
surface_progress_status = 1;
SendPrinterCommand("?", false, null, null, 114, 1);
on_autocheck_status(true);
document.getElementById("surfacebtn").style.display = "none";
document.getElementById("surfacingtext").style.display = "table-row";
cmd = "[ESP220]" + filename;
SendPrinterCommand(cmd);
}

function grbl_wiz_error_dir(path, dirname) {
alert("ERROR : Wizard couldn't create dir " + dirname + " in path " + path);
alertdlg(translate_text_item("ERROR"), translate_text_item("Wizard couldn't create dir ") + dirname + translate_text_item(" in path ") + path);
finalize_surfacing();
}

function grbl_wiz_error_upload(file, path) {
alertdlg(translate_text_item("ERROR"), translate_text_item("Wizard couldn't create file ") + file.name + translate_text_item(" in path ") + path);
finalize_surfacing();
}

function CreateSurfaceProgram(bitdiam, stepover, feedrate, surfacewidth, surfacelength, Zdepth, spindle) {
var crlf = "\r\n";

effectiveCuttingWidth = Math.round(1000 * (bitdiam * (1 - stepover/100))) / 1000;
nPasses = Math.floor(surfacelength / effectiveCuttingWidth);
lastPassWidth = surfacelength % effectiveCuttingWidth;

ncProg = "G21" + crlf; // Unit = mm
ncProg += "G90" + crlf; // Absolute Positioning
ncProg += "G53 G0 Z-5" + crlf; // Move spindle to safe height
ncProg += "G54" + crlf; // Work Coordinates
ncProg += "M3 S" + spindle + crlf; // Set spindle speed
ncProg += "G4 P1.8" + crlf; // Spindle delay
ncProg += "G1 F" + feedrate + crlf; // Set feedrate
ncProg += "G0 X0 Y0" + crlf; // Move to XY origin at Z-safe height
ncProg += "G1 Z-" + Zdepth + crlf; // Move to Z origin (while starting to cut)

var Xend = 0;
for (var i = 0; i <= nPasses; i++) {
Xend == 0 ? Xend = surfacewidth : Xend = 0; // alternate X (passes are in X direction)
cmd = "G1 X" + Xend + " Y" + i * effectiveCuttingWidth + " Z-" + Zdepth;
ncProg += cmd + crlf;
if (i < nPasses) {
cmd = "G1 Y" + (i+1) * effectiveCuttingWidth; // increment Y at each pass
ncProg += cmd + crlf;
}
}

if(lastPassWidth > 0) {
Xend == 0 ? Xend = surfacewidth : Xend = 0; // alternate X
cmd = "G1 Y" + surfacelength;
ncProg += cmd + crlf;
cmd = "G1 X" + Xend + " Y" + surfacelength + " Z-" + Zdepth;
ncProg += cmd + crlf;
}

ncProg += "G53 G0 Z-5" + crlf; // Move spindle to safe height
ncProg += "M5 S0" + crlf; // Spindle off

return ncProg;
}
Loading