diff --git a/js/cam/assemblers/AssemblerPost.js b/js/cam/assemblers/AssemblerPost.js index d2b8febd0e25e91a1310d4523827d6a3fc62b73b..3d7eebe82ac0680bb1c6c7f8d4ac0b278f4035f8 100644 --- a/js/cam/assemblers/AssemblerPost.js +++ b/js/cam/assemblers/AssemblerPost.js @@ -21,7 +21,7 @@ define(['underscore', 'appState', 'lattice', 'cam'], function(_, appState, latti this.customFunctionsContext = { zClearHeight: 8,//height above part to clear during assembly zPreload: 0.2, - wait: 0.75,//seconds + stockWait: 0.75,//seconds blOvershoot: 1.0 }; @@ -58,25 +58,42 @@ define(['underscore', 'appState', 'lattice', 'cam'], function(_, appState, latti return data; }; - this.customMoveXY = function(position, index, exporter, settings, context){ + this.customMoveXY = function(position, lastPosition, index, exporter, settings, context){//already offset for dual heads var data = ""; + + var overshoot = false; + var overshootPosition = position.clone(); + + //always approach from +x +y direction + if (lastPosition.x < position.x){ + overshoot = true; + overshootPosition.x += context.blOvershoot; + } + + if (lastPosition.y < position.y){ + overshoot = true; + overshootPosition.y += context.blOvershoot; + } + + if (overshoot) data += exporter.rapidXY(overshootPosition, settings); data += exporter.rapidXY(position, settings); + return data; }; - this.customPlacePart = function(position, index, material, exporter, settings, context){ + this.customPlacePart = function(position, index, material, exporter, settings, context){//already offset for dual heads var data = ""; data += exporter.rapidZ(position.z + settings.safeHeight, settings); - data += exporter.moveZ(position.z, settings); + data += exporter.moveZ(position.z - context.zPreload, settings); if (material == "brass") data += exporter.addLine("M3"); else if (material == "fiberGlass") data += exporter.addLine("M4"); data += exporter.addComment(JSON.stringify(index)); - data += exporter.addLine("G4", ["P" + context.wait]); + data += exporter.addLine("G4", ["P" + context.stockWait]); data += exporter.addLine("M5"); - data += exporter.moveZ(position.z, settings); + data += exporter.moveZ(position.z - context.zPreload, settings);//need this line? data += exporter.moveZ(position.z + settings.safeHeight, settings); data += exporter.rapidZ(position.z + context.zClearHeight, settings); @@ -182,13 +199,73 @@ define(['underscore', 'appState', 'lattice', 'cam'], function(_, appState, latti position.sub(stock.getPosition().multiplyScalar(settings.scale)); position.sub(settings.originPosition); - data += this.customMoveXY(position.clone(), index.clone(), exporter, settings, context); + data += this.customMoveXY(position.clone(), exporter.getPostPosition(), index.clone(), exporter, settings, context); - data += this.customPlacePart(position, index, material, exporter, settings, context); + data += this.customPlacePart(position.clone(), index.clone(), material, exporter, settings, context); return data; }; return AssemblerPost; -}); \ No newline at end of file +}); + + +//don't delete +// this.customHeader = function(exporter, settings, context){ +// var data = ""; +// data += exporter.setUnits(lattice.get("units")); +// data += this.customHome(exporter, settings, context); +// return data; +// }; +// +// this.customFooter = function(exporter, settings, context){ +// var data = ""; +// data += this.customHome(exporter, settings, context); +// return data; +// }; +// +// this.customHome = function(exporter, settings, context){ +// var data = ""; +// data += exporter.goHome(settings); +// return data; +// }; +// +// this.customPickUpStock = function(exporter, settings, context){//not relevant for your assembler +// var data = ""; +// return data; +// }; +// +// this.customChangeZLayer = function(currentIndex, lastIndex, exporter, settings, context){ +// var data = ""; +// if (lastIndex === null || (currentIndex.z-lastIndex.z)%2 != 0){ +// data += exporter.addLine("G0", ["A" + (currentIndex.z%2*0.3125).toFixed(4)], "new layer"); +// data += "\n"; +// } +// return data; +// }; +// +// this.customMoveXY = function(position, index, exporter, settings, context){//already offset for dual heads +// var data = ""; +// data += exporter.rapidXY(position, settings); +// return data; +// }; +// +// this.customPlacePart = function(position, index, material, exporter, settings, context){//already offset for dual heads +// var data = ""; +// data += exporter.rapidZ(position.z + settings.safeHeight, settings); +// data += exporter.moveZ(position.z - context.zPreload, settings); +// +// if (material == "brass") data += exporter.addLine("M3"); +// else if (material == "fiberGlass") data += exporter.addLine("M4"); +// +// data += exporter.addComment(JSON.stringify(index)); +// +// data += exporter.addLine("G4", ["P" + context.stockWait]); +// data += exporter.addLine("M5"); +// data += exporter.moveZ(position.z - context.zPreload, settings);//need this line? +// +// data += exporter.moveZ(position.z + settings.safeHeight, settings); +// data += exporter.rapidZ(position.z + context.zClearHeight, settings); +// return data; +// }; \ No newline at end of file diff --git a/js/cam/processes/GCodeExporter.js b/js/cam/processes/GCodeExporter.js index a6c0e4046a376080d72615a1a0f22ce04150c7e4..1c631273a94d58045a4072faa1b109c246ce9625 100644 --- a/js/cam/processes/GCodeExporter.js +++ b/js/cam/processes/GCodeExporter.js @@ -2,11 +2,12 @@ * Created by aghassaei on 3/10/15. */ -define(['underscore', 'cam', 'lattice'], function(_, cam, lattice){ +define(['underscore', 'cam', 'lattice', 'three'], function(_, cam, lattice, THREE){ function GCodeExporter() { //keep track of speeds for F commands this.postSpeed = null; + this.postPosition = new THREE.Vector3(0,0,0); this.animationSpeed = null; } @@ -71,9 +72,18 @@ define(['underscore', 'cam', 'lattice'], function(_, cam, lattice){ }; GCodeExporter.prototype._goXYZ = function(x, y, z){ - if (x !== null) x = "X"+parseFloat(x).toFixed(3); - if (y !== null) y = "Y"+parseFloat(y).toFixed(3); - if (z !== null) z = "Z"+parseFloat(z).toFixed(3); + if (x !== null) { + x = "X"+parseFloat(x).toFixed(3); + this.postPosition.x = x; + } + if (y !== null) { + y = "Y"+parseFloat(y).toFixed(3); + this.postPosition.y = y; + } + if (z !== null) { + z = "Z"+parseFloat(z).toFixed(3); + this.postPosition.z = z; + } return this.addLine("G01", [x,y,z]); }; @@ -82,6 +92,10 @@ define(['underscore', 'cam', 'lattice'], function(_, cam, lattice){ return data + this.rapidXY({x:0, y:0}, settings); }; + GCodeExporter.prototype.getPostPosition = function(){ + return this.postPosition.clone(); + }; + diff --git a/js/plists/CamPList.js b/js/plists/CamPList.js index 6368967b19160a975e5a4091c623bc0f020e6af8..d2b8aeeda1139f32ffd71074684750390b06d251 100644 --- a/js/plists/CamPList.js +++ b/js/plists/CamPList.js @@ -128,7 +128,7 @@ define(['three'], function(THREE){ camProcess: "gcode", rapidHeight: 30, rapidHeightRelative: true, - safeHeight: 4.5, + safeHeight: 4, originPosition: new THREE.Vector3(0,0,0), rapidSpeeds:{xy: 250, z: 250}, feedRate:{xy: 6, z: 6}