Skip to content

Commit

Permalink
Pen Lift Mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
petervanderwalt committed Nov 22, 2024
1 parent e2d1852 commit 7f22d26
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 49 deletions.
Binary file added images/plotter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
101 changes: 57 additions & 44 deletions js/advanced-cam-gcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ function makeGcodeExec() {
var Passes = toolpathsInScene[j].userData.camPasses;

if (toolpathsInScene[j].userData.camOperation.indexOf('Pen') == 0) {
toolon = "M3S" + toolpathsInScene[j].userData.camPenDown + "\nG4 P0.5";
tooloff = "M3S" + toolpathsInScene[j].userData.camPenUp + "\nG4 P0.5";
if (toolpathsInScene[j].userData.plotterType == "Z-Axis") {
toolon = "G0 Z" + toolpathsInScene[j].userData.camPenDownZ + " ; Activate Pen";
tooloff = "G0 Z" + toolpathsInScene[j].userData.camPenUpZ + " ; Lift Pen";
} else {
toolon = "M3S" + toolpathsInScene[j].userData.camPenDown + "\nG4 P0.5";
tooloff = "M3S" + toolpathsInScene[j].userData.camPenUp + "\nG4 P0.5";
}
ZClearance = 0;
}

Expand Down Expand Up @@ -151,6 +156,12 @@ function generateGcode(index, toolpathGrp, cutSpeed, plungeSpeed, spindleRpm, la
g += "; Pen Diameter: " + toolpathsInScene[index].userData.camToolDia + "\n";
}

if (toolpathsInScene[j].userData.camOperation.indexOf('Pen') == 0) {
if (toolpathsInScene[j].userData.plotterType == "Z-Axis") {
clearanceHeight = toolpathsInScene[j].userData.camPenUpZ;
}
}


// Optimise gcode, send commands only when changed
var isToolOn = false;
Expand Down Expand Up @@ -338,53 +349,54 @@ function generateGcode(index, toolpathGrp, cutSpeed, plungeSpeed, spindleRpm, la



// then G1 plunge into material
// then G1 plunge into material if not a pen

if (!rampplunge) {
// console.log("Direct Plunge")
g += g1 + " F" + plungeSpeed + " Z" + zpos.toFixed(4) + "; Direct Plunge\n "; // Plunge!!!!
} else {
// console.log("Ramp Plunge")
// console.log(xpos, xpos2, ypos, ypos2)
var d = distanceFormula(xpos, xpos2, ypos, ypos2)
if (d > (toolDia * 5)) {
// console.log("Ramp Plunge: Long enough")
// We can do ramp in our own little space - easiest
var deltaX = xpos2 - xpos;
var deltaY = ypos2 - ypos;
// get the line angle
var ang = Math.atan2(deltaY, deltaX);
// convert it to degrees for later math with addDegree
ang = ang * 180 / Math.PI;

var npt = [xpos, ypos]
npt = newPointFromDistanceAndAngle(npt, ang, (toolDia * 5));
if (lastxyz.z) {
var zdelta = zpos - lastxyz.z;
} else {
var zdelta = zpos - 0;
}
// console.log(zdelta)
if (lastxyz.z) {
g += "\n" + g0 + " Z" + lastxyz.z + "; Position for Plunge\n "; // G0 to Z0 then Plunge!
if (!toolpathsInScene[j].userData.camOperation.indexOf('Pen') == 0) {
if (!rampplunge) {
// console.log("Direct Plunge")
g += g1 + " F" + plungeSpeed + " Z" + zpos.toFixed(4) + "; Direct Plunge\n "; // Plunge!!!!
} else {
// console.log("Ramp Plunge")
// console.log(xpos, xpos2, ypos, ypos2)
var d = distanceFormula(xpos, xpos2, ypos, ypos2)
if (d > (toolDia * 5)) {
// console.log("Ramp Plunge: Long enough")
// We can do ramp in our own little space - easiest
var deltaX = xpos2 - xpos;
var deltaY = ypos2 - ypos;
// get the line angle
var ang = Math.atan2(deltaY, deltaX);
// convert it to degrees for later math with addDegree
ang = ang * 180 / Math.PI;

var npt = [xpos, ypos]
npt = newPointFromDistanceAndAngle(npt, ang, (toolDia * 5));
if (lastxyz.z) {
var zdelta = zpos - lastxyz.z;
} else {
var zdelta = zpos - 0;
}
// console.log(zdelta)
if (lastxyz.z) {
g += "\n" + g0 + " Z" + lastxyz.z + "; Position for Plunge\n "; // G0 to Z0 then Plunge!
} else {
g += "\n" + g0 + " Z" + 0 + "; Position for Plunge\n"; // G0 to Z0 then Plunge!
}
g += g1 + " F" + plungeSpeed;
g += " X" + npt[0].toFixed(4) + " Y" + npt[1].toFixed(4) + " Z" + (zpos - (zdelta / 2)).toFixed(4) + "\n"; // Move to XY position
g += g1 + " F" + plungeSpeed;
g += " X" + xpos.toFixed(4) + " Y" + ypos.toFixed(4) + " Z" + zpos.toFixed(4) + "\n"; // Move to XY position
} else {
g += "\n" + g0 + " Z" + 0 + "; Position for Plunge\n"; // G0 to Z0 then Plunge!
console.error("Ramp Plunge: Too short:" + d)
// Too short, either include next segment or something else
}
g += g1 + " F" + plungeSpeed;
g += " X" + npt[0].toFixed(4) + " Y" + npt[1].toFixed(4) + " Z" + (zpos - (zdelta / 2)).toFixed(4) + "\n"; // Move to XY position
g += g1 + " F" + plungeSpeed;
g += " X" + xpos.toFixed(4) + " Y" + ypos.toFixed(4) + " Z" + zpos.toFixed(4) + "\n"; // Move to XY position
} else {
console.error("Ramp Plunge: Too short:" + d)
// Too short, either include next segment or something else
// g += g1 + " F" + feedrate
// g += " X" + xpos.toFixed(4) + " Y" + ypos.toFixed(4) + "\n"; // Move to XY position
// g += g1 + " F" + plungeSpeed + " Z" + zpos.toFixed(4) + "\n"; // Plunge!!!!
}
// g += g1 + " F" + feedrate
// g += " X" + xpos.toFixed(4) + " Y" + ypos.toFixed(4) + "\n"; // Move to XY position
// g += g1 + " F" + plungeSpeed + " Z" + zpos.toFixed(4) + "\n"; // Plunge!!!!
isAtClearanceHeight = false;
}

isAtClearanceHeight = false;

} else {
// console.log("Subsequent Point", xpos, ypos, zpos, optimisedVertices[i]);
// we are in a non-first line so this is normal moving
Expand All @@ -405,7 +417,8 @@ function generateGcode(index, toolpathGrp, cutSpeed, plungeSpeed, spindleRpm, la
g += g1 + feedrate;
g += " X" + xpos.toFixed(4);
g += " Y" + ypos.toFixed(4);
g += " Z" + zpos.toFixed(4) + "\n";
//g += " Z" + zpos.toFixed(4) + "\n"; // Don't use Z from toolpath, use Z from pen up/down toolon/tooloff commands
g += "\n";
} else if (sOnSeperateLine) {
g += s + laserPwr + "\n";
g += g1 + feedrate;
Expand Down
89 changes: 85 additions & 4 deletions js/advanced-cam-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,20 @@ function initAdvancedCAM() {
} else if (id.indexOf('tpenup') == 0) {
// $('#svgUnion').text(newval);
updateCamUserData(objectseq);
} else if (id.indexOf('tpendownz') == 0) {
// $('#svgUnion').text(newval);
updateCamUserData(objectseq);
} else if (id.indexOf('tpenupz') == 0) {
// $('#svgUnion').text(newval);
updateCamUserData(objectseq);
} else if (id.indexOf('tplottertype') == 0) {
console.log('Value for ' + id + ' changed to ' + newval + ' for object ' + objectseq);
updateCamUserData(objectseq);
if (newval == "Z-Axis") {
plotterModeZ(i)
} else {
plotterModeServo(i)
}
}

});
Expand Down Expand Up @@ -222,8 +236,11 @@ function updateCamUserData(i) {
toolpathsInScene[i].userData.camTabWidth = $('#tabWidth' + i).val();
toolpathsInScene[i].userData.camTabSpace = $('#tabSpace' + i).val();
toolpathsInScene[i].userData.tRampPlunge = $('#tRampPlunge' + i).val();
toolpathsInScene[i].userData.plotterType = $('#tplottertype' + i).val();
toolpathsInScene[i].userData.camPenUp = $('#tpenup' + i).val();
toolpathsInScene[i].userData.camPenDown = $('#tpendown' + i).val();
toolpathsInScene[i].userData.camPenUpZ = $('#tpenupz' + i).val();
toolpathsInScene[i].userData.camPenDownZ = $('#tpendownz' + i).val();
toolpathsInScene[i].userData.advanced = $('#advanced' + i).is(":checked");; // Marlin, Stepcraft, Mach3, LinuxCNC
toolpathsInScene[i].name = $('#tOpName' + i).val();
$('#statusTitle').html('Configure Toolpath: ' + toolpathsInScene[i].userData.camOperation);
Expand Down Expand Up @@ -491,8 +508,22 @@ function setupJob(i) {
</div>
</td>
</tr>
<tr class="inputplotter inputpenraster">
<td>Plotter: Pen Up</td>
<td>Plotter: Type</td>
<td>
<div class="input-addon">
<span class="input-addon-label-left active-border"><i class="far fa-edit fa-fw"></i></span>
<select class="cam-form-field cam-form-field-right active-border" id="tplottertype` + i + `" objectseq="` + i + `" style="width: 280px; border-left: solid 1px #ccc; padding: 0px; padding-left: 10px;">
<option selected>Z-Axis</option>
<option>RC Servo</option>
</select>
</div>
</td>
</tr>
<tr class="inputplotter inputpenraster inputpenservo">
<td>Pen Up S-Value</td>
<td>
<div class="input-addon">
<span class="input-addon-label-left active-border"><i class="far fa-edit fa-fw"></i></span>
Expand All @@ -502,8 +533,8 @@ function setupJob(i) {
</td>
</tr>
<tr class="inputplotter inputpenraster">
<td>Plotter: Pen Down</td>
<tr class="inputplotter inputpenraster inputpenservo">
<td>Pen Down S-Value</td>
<td>
<div class="input-addon">
<span class="input-addon-label-left active-border"><i class="fas fa-edit fa-fw"></i></span>
Expand All @@ -513,6 +544,28 @@ function setupJob(i) {
</td>
</tr>
<tr class="inputplotter inputpenraster inputpenz">
<td>Pen Up Z-position</td>
<td>
<div class="input-addon">
<span class="input-addon-label-left active-border"><i class="far fa-edit fa-fw"></i></span>
<input data-role="input" data-clear-button="false" type="number" class="cam-form-field active-border" value="5" id="tpenupz` + i + `" objectseq="` + i + `" min="0" step="any">
<span class="input-addon-label-right active-border">mm</span>
</div>
</td>
</tr>
<tr class="inputplotter inputpenraster inputpenz">
<td>Pen Down Z-position</td>
<td>
<div class="input-addon">
<span class="input-addon-label-left active-border"><i class="fas fa-edit fa-fw"></i></span>
<input data-role="input" data-clear-button="false" type="number" class="cam-form-field active-border" value="0" id="tpendownz` + i + `" objectseq="` + i + `" min="0" step="any">
<span class="input-addon-label-right active-border">mm</span>
</div>
</td>
</tr>
</table>
Expand Down Expand Up @@ -668,8 +721,11 @@ function setupJob(i) {
$('#tabdepth' + i).val(toolpathsInScene[i].userData.camTabDepth);
$('#tabWidth' + i).val(toolpathsInScene[i].userData.camTabWidth);
$('#tabSpace' + i).val(toolpathsInScene[i].userData.camTabSpace);
$('#tplottertype' + i).val(toolpathsInScene[i].userData.plotterType).prop('selected', true);
$('#tpenup' + i).val(toolpathsInScene[i].userData.camPenUp);
$('#tpendown' + i).val(toolpathsInScene[i].userData.camPenDown);
$('#tpenupz' + i).val(toolpathsInScene[i].userData.camPenUpZ);
$('#tpendownz' + i).val(toolpathsInScene[i].userData.camPenDownZ);
if (toolpathsInScene[i].userData.tRampPlunge) {
$('#tRampPlunge' + i).val(toolpathsInScene[i].userData.tRampPlunge).prop('selected', true);
} else {
Expand Down Expand Up @@ -730,8 +786,11 @@ function setupJob(i) {
//$('#tabWidth' + i).val(lastused.camTabWidth);
//$('#tabSpace' + i).val(lastused.camTabSpace);
//$('#tRampPlunge' + i).val(lastused.tRampPlunge);
$('#tplottertype' + i).val(lastused.plotterType).prop('selected', true);
$('#tpenup' + i).val(lastused.camPenUp);
$('#tpendown' + i).val(lastused.camPenDown);
$('#tpenupz' + i).val(lastused.camPenUpZ);
$('#tpendownz' + i).val(lastused.camPenDownZ);
} else {
if ($("#hasPlasma").is(':checked')) {
// If user has LEAD1010 Plasma, lets force first time use to use IHS
Expand Down Expand Up @@ -932,6 +991,12 @@ function plotterMode(i) {
$('.inputdragknife').hide();
$('.inputpenraster').hide();
$('.inputplotter').show();
if ($('#tplottertype' + i).val() == "Z-Axis") {
plotterModeZ(i)
} else {
plotterModeServo(i)
}

};

function penRasterMode(i) {
Expand All @@ -944,4 +1009,20 @@ function penRasterMode(i) {
$('.inputplotter').hide();
$('.inputlaserraster').hide();
$('.inputpenraster').show();
};
if ($('#tplottertype' + i).val() == "Z-Axis") {
plotterModeZ(i)
} else {
plotterModeServo(i)
}
};

function plotterModeZ(i) {
$('.inputpenservo').hide();
$('.inputpenz').show();
}

function plotterModeServo(i) {
$('.inputpenservo').show();
$('.inputpenz').hide();

}
21 changes: 20 additions & 1 deletion js/application-settings-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,17 @@ function selectToolhead() {
localStorage.setItem("hasLaser", false);
}

if ($("#hasPenPlotter").is(':checked')) {
// console.log('Add Laser Dynamic')
// startcode += "; Plotter does not need specific startup\n"
// endcode += "; Plotter does not need specific end\n"
//$('#scommandscale').val(1000);
localStorage.setItem("hasPenPlotter", true);
} else {
localStorage.setItem("hasPenPlotter", false);
}


if ($("#hasDust").is(':checked')) {
// console.log('Add Misting')
startcode += "M8; Coolant Output On - turns on Dust Extractor if wired\n"
Expand Down Expand Up @@ -461,6 +472,9 @@ function setMachineButton(type) {
if (localStorage.getItem("hasLaser") == 'true') {
$("#hasLaser").attr('checked', true)
}
if (localStorage.getItem("hasPenPlotter") == 'true') {
$("#hasPenPlotter").attr('checked', true)
}

// workaround for Lead Plasma specifically (not quite a modular machine, has its own picture on front page overlay)
if (type == "leadmachine1010" && localStorage.getItem("hasPlasma") == 'true') {
Expand All @@ -474,7 +488,7 @@ $(document).ready(function() {
var modal = `
<!-- Settings Modal -->
<div class="dialog dark" data-overlay-click-close="true" data-role="dialog" id="settingsmodal" data-width="730" data-to-top="true">
<div class="dialog dark" data-overlay-click-close="true" data-role="dialog" id="settingsmodal" data-width="830" data-to-top="true">
<div class="dialog-title">Application Settings</div>
<div class="dialog-content" style="max-height: calc(100vh - 200px);overflow-y: auto; overflow-x: hidden;">
<form>
Expand Down Expand Up @@ -568,6 +582,11 @@ $(document).ready(function() {
<label for="hasLaser"><img src="./images/laser.png" /></label>
<div class="image-checkbox-text">Laser Diode Module</div>
</li>
<li>
<input type="checkbox" onchange="selectToolhead()" id="hasPenPlotter" />
<label for="hasPenPlotter"><img src="./images/plotter.png" /></label>
<div class="image-checkbox-text">Pen Lift<br>Mechanism</div>
</li>
<li>
<input type="checkbox" onchange="selectToolhead()" id="hasDust" />
<label for="hasDust"><img src="./images/dustshoe.png" /></label>
Expand Down

0 comments on commit 7f22d26

Please sign in to comment.