Skip to content

Commit

Permalink
Merge pull request #418 from MaslowCNC/Make-gcode-work-again
Browse files Browse the repository at this point in the history
Make gcode work again
  • Loading branch information
BarbourSmith committed Apr 25, 2020
2 parents a6c6998 + 0abeac9 commit 866a7df
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
43 changes: 31 additions & 12 deletions dist/maslowWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -108909,31 +108909,50 @@ return d[d.length-1];};return ", funcName].join("");
const svgString = await toSvg(Shape.fromGeometry(values[0]).Union().center().section().outline().toKeptGeometry());
return svgString;
case 'stackedOutline':
console.log("Running stacked outline 11:02");
const gcodeShape = Shape.fromGeometry(values[0]);
const thickness = gcodeShape.size().height;
console.log("Thickness: " + thickness);
const toolSize = values[1];
const numberOfPasses = values[2];
const speed = values[3];
const tabs = values[4];
const safeHeight = values[5];

const distPerPass = -1*thickness/numberOfPasses;

const oneProfile = gcodeShape.Union().center().section().toolpath(toolSize, { joinPaths: true });
var oneProfile = gcodeShape.Union().center().section().toolpath(toolSize, { joinPaths: true });

const profiles = [];
var i = 1;
while(i <= numberOfPasses){
profiles.push(oneProfile.move(0,0,i*distPerPass));
i++;
}
console.log(oneProfile.geometry.paths);


//Split each path into it's layers
oneProfile.geometry.paths.forEach((path, index) => {
var newPath = [];
var i = 1;
while(i <= numberOfPasses){
newPath.push([path[0][0], path[0][1], safeHeight]); //Move to the starting position before plunging
path.forEach(point => {
newPath.push([point[0], point[1], point[2] + i*distPerPass]);
});
newPath.push([path[0][0], path[0][1], path[0][2] + i*distPerPass]); //Add the first point again to close the path
i++;
}
const lastIndex = newPath.length - 1;
newPath.push([newPath[lastIndex][0], newPath[lastIndex][1], safeHeight]); //Retract back to safe height after finishing move
oneProfile.geometry.paths[index] = newPath;
});

//Join all the layers into a single continuous path
var completePath = [[0,0, safeHeight]];
oneProfile.geometry.paths.forEach(path => {
completePath = completePath.concat(path);
});

console.log(profiles);
console.log("Complete path");
console.log(completePath);

const assembledPaths = Assembly(...profiles);
oneProfile.geometry.paths = [completePath];

return assembledPaths.toKeptGeometry();
return oneProfile.toKeptGeometry();
case 'gcode':
return "G0 would be here"
case 'outline':
Expand Down
13 changes: 10 additions & 3 deletions src/js/molecules/gcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default class Gcode extends Atom {
this.addIO('input', 'passes', this, 'number', 6)
this.addIO('input', 'speed', this, 'number', 500)
this.addIO('input', 'tabs', this, 'string', "true")
this.addIO('input', 'safe height', this, 'number', 6)

this.addIO('output', 'gcode', this, 'geometry', '')

Expand All @@ -44,7 +45,7 @@ export default class Gcode extends Atom {
*/
updateValue(){
try{
const values = [this.findIOValue('geometry'), this.findIOValue('tool size'), this.findIOValue('passes'), this.findIOValue('speed'), this.findIOValue('tabs')]
const values = [this.findIOValue('geometry'), this.findIOValue('tool size'), this.findIOValue('passes'), this.findIOValue('speed'), this.findIOValue('tabs'), this.findIOValue('safe height')]
this.basicThreadValueProcessing(values, "stackedOutline")
}catch(err){this.setAlert(err)}
}
Expand All @@ -55,8 +56,14 @@ export default class Gcode extends Atom {
updateSidebar(){
var valueList = super.updateSidebar()

this.createButton(valueList,this,'Download Gcode',() => {
const blob = new Blob([this.value], {type: 'text/plain;charset=utf-8'})
this.createButton(valueList,this,'Download Gcode',() => {const feedRate = this.findIOValue('speed')
var gcodeString = "G20 \nG90 \n"

this.value.paths[0].forEach(point => {
gcodeString += "G1 X" + point[0] + " Y" + point[1] + " Z" + point[2] + " F" + feedRate + "\n"
})

const blob = new Blob([gcodeString], {type: 'text/plain;charset=utf-8'})
saveAs(blob, GlobalVariables.topLevelMolecule.name+'.nc')
})
}
Expand Down

0 comments on commit 866a7df

Please sign in to comment.