diff --git a/index.html b/index.html index 05a964b9a47bbdcb7c966cbd30c1c86f3f1bb039..5fa4e06a93d540b247730c94dd23878c0829ec2b 100644 --- a/index.html +++ b/index.html @@ -68,6 +68,7 @@ <script src="js/cam/Assembler.js"></script> <script src="js/cam/ShopbotExporter.js"></script> <script src="js/cam/GCodeExporter.js"></script> + <script src="js/cam/TinyGExporter.js"></script> <!--views--> <script src="js/menus/MenuWrapperView.js"></script> diff --git a/js/cam/Assembler.js b/js/cam/Assembler.js index f98c85896a8ad4032e679217114d588047434981..37a02eb9235dc68b75aa319c31eb776e6a597336 100644 --- a/js/cam/Assembler.js +++ b/js/cam/Assembler.js @@ -257,18 +257,25 @@ Assembler = Backbone.Model.extend({ _getExporter: function(){ var currentExporter = this.get("exporter"); - if (this.get("camProcess") == "shopbot") { + var camProcess = this.get("camProcess"); + if (camProcess == "shopbot") { if (currentExporter && currentExporter.constructor == ShopbotExporter){ return currentExporter; } else { return new ShopbotExporter(); } - } else if (this.get("camProcess") == "gcode") { + } else if (camProcess == "gcode") { if (currentExporter && currentExporter.constructor == GCodeExporter){ return currentExporter; } else { return new GCodeExporter(); } + } else if (camProcess == "tinyG"){ + if (currentExporter && currentExporter.constructor == TinyGExporter){ + return TinyGExporter; + } else { + return new TinyGExporter(); + } } console.warn("cam process not supported"); return null; diff --git a/js/cam/Machine.js b/js/cam/Machine.js index 17a1c366e73327bf40af402d7efe7dbd3d0b70d5..67163ee72fae4f370227154604b067a19efd7790 100644 --- a/js/cam/Machine.js +++ b/js/cam/Machine.js @@ -192,16 +192,22 @@ Machine.prototype.postProcess = function(data, exporter){//override in subclasse stockNum += 1; if (stockNum >= stockArraySize.x * stockArraySize.y) stockNum = 0; } + data += self._postMoveXY(exporter, stockPosition.x-wcs.x, stockPosition.y-wcs.y); data += self._postPickUpStock(exporter, thisStockPosition, rapidHeight, wcs, safeHeight); - data += self._postReleaseStock(cell, exporter, rapidHeight, wcs, safeHeight); + var cellPosition = cell.getPosition(); + data += self._postMoveXY(exporter, cellPosition.x-wcs.x, cellPosition.y-wcs.y); + data += self._postReleaseStock(cellPosition, cell, exporter, rapidHeight, wcs, safeHeight); data += "\n"; }); return data; }; +Machine.prototype._postMoveXY = function(exporter, x, y){ + return exporter.rapidXY(x, y); +}; + Machine.prototype._postPickUpStock = function(exporter, stockPosition, rapidHeight, wcs, safeHeight){ var data = ""; - data += exporter.rapidXY(stockPosition.x-wcs.x, stockPosition.y-wcs.y); data += exporter.rapidZ(stockPosition.z-wcs.z+safeHeight); data += exporter.moveZ(stockPosition.z-wcs.z); data += exporter.addComment("get stock"); @@ -210,10 +216,8 @@ Machine.prototype._postPickUpStock = function(exporter, stockPosition, rapidHeig return data; }; -Machine.prototype._postReleaseStock = function(cell, exporter, rapidHeight, wcs, safeHeight){ +Machine.prototype._postReleaseStock = function(cellPosition, cell, exporter, rapidHeight, wcs, safeHeight){ var data = ""; - var cellPosition = cell.getPosition(); - data += exporter.rapidXY(cellPosition.x-wcs.x, cellPosition.y-wcs.y); data += exporter.rapidZ(cellPosition.z-wcs.z+safeHeight); data += exporter.moveZ(cellPosition.z-wcs.z); data += exporter.addComment(JSON.stringify(cell.indices)); diff --git a/js/cam/MachineOneBit.js b/js/cam/MachineOneBit.js index e3d160acadc8cfa3f8279f812a1e0b704f8a03cd..55e0bc964cdc2b72242c22f6cfea0127a4969dff 100644 --- a/js/cam/MachineOneBit.js +++ b/js/cam/MachineOneBit.js @@ -123,4 +123,14 @@ OneBitBot.prototype._moveZAxis = function(startingPos, target, axis, speed, call return; } this._animateObjects([this.meshes["zAxis"], this.cell], axis, speed, startingPos, target, callback); +}; + +OneBitBot.prototype._postPickUpStock = function(exporter, stockPosition, rapidHeight, wcs, safeHeight){ + if (exporter.engageZAxis) return exporter.engageZAxis(); + else return Machine.prototype._postPickUpStock.call(this, exporter, stockPosition, rapidHeight, wcs, safeHeight); +}; + +OneBitBot.prototype._postReleaseStock = function(cellPosition, cell, exporter, rapidHeight, wcs, safeHeight){ + if (exporter.engageZAxis) return exporter.engageZAxis(); + else return Machine.prototype._postReleaseStock.call(this, cellPosition, cell, exporter, rapidHeight, wcs, safeHeight); }; \ No newline at end of file diff --git a/js/cam/TinyGExporter.js b/js/cam/TinyGExporter.js new file mode 100644 index 0000000000000000000000000000000000000000..2b7b73b3ebbcecb10b2bd29c3eb25223241bb1aa --- /dev/null +++ b/js/cam/TinyGExporter.js @@ -0,0 +1,74 @@ +/** + * Created by aghassaei on 3/26/15. + */ + +//M3 M4 spindle direction (z layer bit 0) +//M8 M9 - coolant on/of (z layer bit 1) +//M5 spindle stop (z layer start) + + +//spin - z axis go +//wait 1s +//direction - z axis height +//coolant - legs up down + + + +function TinyGExporter(){ + GCodeExporter.call(this); +} +TinyGExporter.prototype = Object.create(GCodeExporter.prototype); + +TinyGExporter.prototype.makeHeader = function(){ + return ""; +}; + +TinyGExporter.prototype._setSpeed = function(speed){ + return "F"+ speed + "\n"; +}; + +TinyGExporter.prototype.goHome = function(){ + return ""; +}; + +TinyGExporter.prototype.engageZAxis = function(height){ + console.log("z"); +}; + +TinyGExporter.prototype.simulate = function(line, machine, wcs, callback){ + if (line == "(get stock)"){ + machine.pickUpStock(); + return callback(); + } + if (line.substr(0,2) == "({"){ + machine.releaseStock(line.substr(1,line.length-2)); + return callback(); + } + if (line[0] == "F"){//speed + this.animationSpeed = line.split("F")[1]; + return callback(); + } + if (line == "" || line[0] == "(" || line.substr(0,3) != "G01"){ + return callback(); + } + if (line.substr(0,3) == "G01"){ + return this._simulateGetPosition(line, {xy:this.animationSpeed, z:this.animationSpeed}, machine, wcs, callback); + } else { + console.warn("problem parsing gcode: " + line); + return callback(); + } +}; + +TinyGExporter.prototype._simulateGetPosition = function(line, speed, machine, wcs, callback){ + var data = line.split(" "); + var position = {x:"",y:"",z:""}; + if (data.length<2) console.warn("problem parsing gcode " + line); + for (var i=1;i<data.length;i++){ + var item = data[i]; + if (item[0] == "X") position.x = item.substr(1); + if (item[0] == "Y") position.y = item.substr(1); + if (item[0] == "Z") position.z = item.substr(1); + } + machine.moveTo(position.x, position.y, position.z, speed, wcs, callback); +}; + diff --git a/js/models/AppState.js b/js/models/AppState.js index 595c0743052c0eb9fe0a2d23542f637d6882f997..4794e6490ac9621229e9837308f2772febb5afa2 100644 --- a/js/models/AppState.js +++ b/js/models/AppState.js @@ -119,7 +119,10 @@ AppState = Backbone.Model.extend({ gcode: "G-Code" }, handOfGod:{gcode: "G-Code"}, - oneBitBot:{gcode: "G-Code"} + oneBitBot:{ + gcode: "G-Code", + tinyG: "TinyG" + } }, allScripts: {