diff --git a/js/cam/Assembler.js b/js/cam/Assembler.js index 4b35ba6458f5bd3cd50f2d93efd88758e9d79631..6f9a82adceded6a68d55c9848b209672fe81dc24 100644 --- a/js/cam/Assembler.js +++ b/js/cam/Assembler.js @@ -18,7 +18,15 @@ Assembler = Backbone.Model.extend({ processAndSave: function(){ var exporter; if (this.get("camProcess") == "shopbot") exporter = new ShopbotExporter(); - if (exporter) exporter.processAndSave(); + else if (this.get("camProcess") == "gcode") exporter = new GCodeExporter(); + if (exporter) { + var data = ""; + data += exporter.makeHeader(); + data += exporter.moveZ(3); + data += exporter.move3(1, 4, 5); + data += exporter.makeFooter(); + exporter.save(data); + } else console.warn("cam process not supported"); }, diff --git a/js/cam/GCodeExporter.js b/js/cam/GCodeExporter.js new file mode 100644 index 0000000000000000000000000000000000000000..74c23e818c53e84adf5a68b21dc2d48efac918d5 --- /dev/null +++ b/js/cam/GCodeExporter.js @@ -0,0 +1,71 @@ +/** + * Created by aghassaei on 3/10/15. + */ + +function GCodeExporter() { +} + +GCodeExporter.prototype.makeHeader = function(){ + var data = ""; + if (dmaGlobals.appState.get("units") == "inches") data += this.addLine("G20", [], "units inches"); + else data += this.addLine("G21", [], "units mm"); + data += this.addLine("G90", [], "absolute positioning"); + data += this.addLine("G54", [], "work offset"); +// data += this.addLine("G49", [], "cancel tool length comp"); + data += this.addLine("G40", [], "cancel tool radius comp"); + data += this.addLine("M09", [], "coolant off"); + + + + data += this.goHome(); + + //set rapid and feed speeds + + data += "\n"; + data += "\n"; + return data; +}; + +GCodeExporter.prototype.addLine = function(command, params, comment){ + var data = ""; + data += command + " "; + _.each(params, function(param){ + if (!param) return; + data += param + " "; + }); + if (comment) data += "(" + comment + ")"; + data += "\n"; + return data; +}; + +GCodeExporter.prototype.rapid3 = function(x, y, z){ + return this.move3(x,y,z); +}; + +GCodeExporter.prototype.move3 = function(x, y, z){ + if (x !== null) x = "X"+x; + if (y !== null) y = "Y"+y; + if (z !== null) z = "Z"+z; + return this.addLine("G01", [x,y,z]); +}; + +GCodeExporter.prototype.goHome = function(){ + return this.move3(0,0,0); +}; + +GCodeExporter.prototype.moveZ = function(z){ + return this.move3(null, null, z); +}; + +GCodeExporter.prototype.makeFooter = function(){ + var data = ""; + data += this.goHome(); + data += this.addLine("M30", [], "program stop"); + + return data; +}; + +GCodeExporter.prototype.save = function(data){ + var blob = new Blob([data], {type: "text/plain;charset=utf-8"}); + saveAs(blob, "GCodeExport" + ".g"); +}; diff --git a/js/cam/ShopbotExporter.js b/js/cam/ShopbotExporter.js index 8c85400c7001b93aa15639f447770764e6fd4325..a3d3ac1d80d54e17d43d7290e1fa909f1c6738d9 100644 --- a/js/cam/ShopbotExporter.js +++ b/js/cam/ShopbotExporter.js @@ -3,30 +3,23 @@ */ function ShopbotExporter() { - } -ShopbotExporter.prototype.processAndSave = function(){ - +ShopbotExporter.prototype.makeHeader = function(){ var data = ""; - - data = this.makeHeader(data); - data = this.moveZ(data, 3); - data = this.jog3(data, 1, 4, 5); - - this.save(data); -}; - -ShopbotExporter.prototype.makeHeader = function(data){ - data = this.addLine(data, "FG", [], "single step mode"); - data = this.goHome(data); - data = this.addLine(data, "SM", [4, 1], "set to move/cut mode"); - data = this.addLine(data, "JS", [4, 1], "jog speed- xy, z inches per sec"); - data = this.addLine(data, "MS", [4, 1], "move speed- xy, z inches per sec"); + data += this.addLine("FG", [], "single step mode"); + data += this.goHome(); + data += this.addLine("SA", [], "absolute distances"); + data += this.addLine("SM", [4, 1], "move/cut mode (as opposed to preview mode)"); + data += this.addLine("JS", [4, 1], "jog speed- xy, z inches per sec"); + data += this.addLine("MS", [4, 1], "move speed- xy, z inches per sec"); + data += "\n"; + data += "\n"; return data; }; -ShopbotExporter.prototype.addLine = function(data, command, params, comment){ +ShopbotExporter.prototype.addLine = function(command, params, comment){ + var data = ""; data += command + " "; _.each(params, function(param){ data += param + ", "; @@ -36,22 +29,27 @@ ShopbotExporter.prototype.addLine = function(data, command, params, comment){ return data; }; -ShopbotExporter.prototype.jog3 = function(data, x, y, z){ - return this.addLine(data, "J3", [x,y,z]); +ShopbotExporter.prototype.rapid3 = function(x, y, z){ + return this.addLine("J3", [x,y,z]); }; -ShopbotExporter.prototype.move3 = function(data, x, y, z){ - return this.addLine(data, "M3", [x,y,z]); +ShopbotExporter.prototype.move3 = function(x, y, z){ + return this.addLine("M3", [x,y,z]); }; -ShopbotExporter.prototype.goHome = function(data){ - return this.addLine(data, "JH", [], "go home"); +ShopbotExporter.prototype.goHome = function(){ + return this.addLine("JH", [], "go home"); }; -ShopbotExporter.prototype.moveZ = function(data, z){ - return this.move3(data, "", "", z); +ShopbotExporter.prototype.moveZ = function(z){ + return this.move3("", "", z); }; +ShopbotExporter.prototype.makeFooter = function(){ + var data = ""; + + return data; +}; ShopbotExporter.prototype.save = function(data){ var blob = new Blob([data], {type: "text/plain;charset=utf-8"}); diff --git a/main.html b/main.html index 132c58601e65a3c4f81f52b5d4bef1501fcf81e4..1a69364505c4596a32b340c21fd18484584b9930 100644 --- a/main.html +++ b/main.html @@ -65,6 +65,7 @@ <script src="js/models/AppState.js"></script> <script src="js/cam/Assembler.js"></script> <script src="js/cam/ShopbotExporter.js"></script> + <script src="js/cam/GCodeExporter.js"></script> <!--views--> <script src="js/menus/MenuWrapperView.js"></script>