diff --git a/js/SerialMonitor/PositionControlPanelView.js b/js/SerialMonitor/PositionControlPanelView.js index dbe11fb94def94a3751c6d74827f0f34af179a23..c55bc85d557d7541ba4d6188ded42fec0261e472 100644 --- a/js/SerialMonitor/PositionControlPanelView.js +++ b/js/SerialMonitor/PositionControlPanelView.js @@ -30,7 +30,7 @@ define(['jquery', 'underscore', 'backbone', 'text!PositionControlPanelView.html' $("#positionData").html(_.template(positionTemplate)(machineState.toJSON())); }, - _askForPosition: function(e){ + _askForPosition: function(e){//todo should be in machine state init if (e) e.preventDefault(); this.model.send('{"sr":n}'); }, diff --git a/js/SerialMonitor/fakeCam.js b/js/SerialMonitor/fakeCam.js new file mode 100644 index 0000000000000000000000000000000000000000..e3452110bd7727f0c794066176931602d90082f8 --- /dev/null +++ b/js/SerialMonitor/fakeCam.js @@ -0,0 +1,12 @@ +/** + * Created by aghassaei on 9/18/15. + */ + + +define([], function(){ + + return { + setPosition: function(){} + } + +}); \ No newline at end of file diff --git a/js/SerialMonitor/main.js b/js/SerialMonitor/main.js index d1bd5e116a578fb9e2be04385c8ceec1044b0f87..e97b76d1b7bacb92f1604bc04ad1e73fad0bf9aa 100644 --- a/js/SerialMonitor/main.js +++ b/js/SerialMonitor/main.js @@ -22,7 +22,8 @@ require.config({ plist: '../plists/PList', commPlist: '../plists/commPlist', serialComm: '../models/SerialComm', - machineState: '../models/MachineState' + machineState: '../models/MachineState', + cam: 'fakeCam' }, diff --git a/js/cam/Cam.js b/js/cam/Cam.js index 76e0d76fba2f9996328b2934d035f21610a1dea5..7b3298c9f2a5a13c1d0a12bbae183457954243f2 100644 --- a/js/cam/Cam.js +++ b/js/cam/Cam.js @@ -297,7 +297,6 @@ define(['underscore', 'three', 'backbone', 'appState', 'latticeCAM', 'threeModel simulateCurrentLine: function(callback){ var lineNum = this.get("simLineNumber"); - console.log(lineNum); three.startAnimationLoop(); if (lineNum == 0) lattice.hideCells("cells"); var allLines = this.get("dataOut").split("\n"); @@ -318,6 +317,19 @@ define(['underscore', 'three', 'backbone', 'appState', 'latticeCAM', 'threeModel } }, + setPosition: function(position){ + var scale = lattice.get("scale"); + + _.each(position, function(val, key){ + position[key] = val/scale; + }); + + this.get("assembler").immediatelyMoveTo(position); + + + three.render(); + }, + diff --git a/js/cam/assemblers/Assembler.js b/js/cam/assemblers/Assembler.js index 665cef16a603e61b4ca18e3b070b6e98cae63f51..c19fbbe249f7a3a629589c635d7a27ad923e7ec7 100644 --- a/js/cam/assemblers/Assembler.js +++ b/js/cam/assemblers/Assembler.js @@ -232,6 +232,14 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', ' Assembler.prototype.pause = function(){ }; + + Assembler.prototype.immediatelyMoveTo = function(data){ + this.components.xAxis.immediatelySetPosition(new THREE.Vector3(data.x, 0, 0)); + this.components.yAxis.immediatelySetPosition(new THREE.Vector3(0, data.y, 0)); + this.components.zAxis.immediatelySetPosition(new THREE.Vector3(0, 0, data.z)); + if (data.a != 0) this.components.substrate.immediatelySetAngle(-Math.PI/2); + else this.components.substrate.immediatelySetAngle(data.a); + }; Assembler.prototype.moveTo = function(position, speed, settings, callback){ diff --git a/js/cam/assemblers/Component.js b/js/cam/assemblers/Component.js index e67e7b0fc9e9f37595079075e2964f2380c232fe..2064ffea180f97cb14f689ab1c85025fed998736 100644 --- a/js/cam/assemblers/Component.js +++ b/js/cam/assemblers/Component.js @@ -171,7 +171,15 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){ - //simulation animation + //simulation + + Component.prototype.immediatelySetAngle = function(angle){ + this.secondWrapper.rotation.z = angle; + }; + + Component.prototype.immediatelySetPosition = function(nextPos){ + this.object3D.position.set(nextPos.x, nextPos.y, nextPos.z); + }; Component.prototype.getObject3D = function(){ return this.object3D; diff --git a/js/menus/SendMenuView.js b/js/menus/SendMenuView.js index ca6fe42b199a999554c8e3539fc22d8ccc4e8715..61a9f6ea78c63be51a0a863d74a194b7a32eb6db 100644 --- a/js/menus/SendMenuView.js +++ b/js/menus/SendMenuView.js @@ -23,8 +23,11 @@ define(['jquery', 'underscore', 'menuParent', 'serialComm', 'commPlist', 'text!s this.listenTo(this.model, "change:stockSimulationPlaying", this.render); this.listenTo(serialComm, "change:isStreaming", this.render); this.listenTo(cam, "change:simLineNumber", this._lineNumChanged); + }, - this.nextLine = cam.get("simLineNumber"); + _getPropertyOwner: function($target){ + if ($target.hasClass("cam")) return cam; + return null; }, _startStream: function(e){ @@ -44,13 +47,13 @@ define(['jquery', 'underscore', 'menuParent', 'serialComm', 'commPlist', 'text!s _decrementLineNum: function(e){ e.preventDefault(); - var nextLine = this.nextLine - 1; + var nextLine = cam.get("simLineNumber") - 1; this._setNextLine(nextLine); }, _incrementLineNum: function(e){ e.preventDefault(); - var nextLine = this.nextLine + 1; + var nextLine = cam.get("simLineNumber") + 1; this._setNextLine(nextLine); }, @@ -58,8 +61,12 @@ define(['jquery', 'underscore', 'menuParent', 'serialComm', 'commPlist', 'text!s var length = cam.get("dataOut").split("\n").length; if (nextLine < 0) nextLine = length-1; if (nextLine > length-1) nextLine = 0; - this.nextLine = nextLine; - $("#nextLine").val(this.nextLine); + cam.set("simLineNumber", nextLine); + }, + + _showNextLine: function(nextLine){ + console.log(nextLine); + $("#nextLine").val(nextLine); this._drawGcodeHighlighter(nextLine); }, @@ -70,7 +77,7 @@ define(['jquery', 'underscore', 'menuParent', 'serialComm', 'commPlist', 'text!s _lineNumChanged: function(){ var lineNum = cam.get("simLineNumber"); - this._setNextLine(lineNum); + this._showNextLine(lineNum); }, _drawGcodeHighlighter: function(lineNum){ diff --git a/js/menus/templates/SendMenuView.html b/js/menus/templates/SendMenuView.html index 66fbb1749c0c4bdef2719ceb61ee79471661ba40..e3243e88cc41bafd9b88463b680914c6587dd5b9 100644 --- a/js/menus/templates/SendMenuView.html +++ b/js/menus/templates/SendMenuView.html @@ -10,7 +10,7 @@ <% } %> <br/> <a href="#" id="openSerialMonitor" class="btn btn-block btn-lg btn-default">Open Serial Monitor</a><br/> - Next Line: <input id="nextLine" value=<%= nextLine %> placeholder="##" class="intInput form-control unresponsiveInput" type="text"> + Next Line: <input id="nextLine" property="simLineNumber" value="<%= nextLine %>" placeholder="##" class="intInput form-control cam" type="text"> <a href="#" id="previousLineButton" class="btn btn-lg btn-default"><span class="fui-triangle-up"></span></a> <a href="#" id="nextLineButton" class="btn btn-lg btn-default"><span class="fui-triangle-down"></span></a><br/><br/> <div id="gcodeEditor"><%= dataOut %></div><br/> diff --git a/js/models/MachineState.js b/js/models/MachineState.js index a6923937828276d40866762cd07ff28e8081b92d..5bfa06f995f8430778f229ebcf334eaff845091c 100644 --- a/js/models/MachineState.js +++ b/js/models/MachineState.js @@ -29,15 +29,8 @@ define(['underscore', 'backbone'], function(_, Backbone){ } }, - setFooterStatus: function(data){ - if (data[1] == 0){//ok status - this.set("status", 3); - this._triggerNextCommand(); - } else this.set("status", 10); - }, - isReadyStatus: function(status){ - if (status == undefined) status = this.get("status"); + if (status === undefined) status = this.get("status"); return status == 1 || status == 3 || status == 4; }, diff --git a/js/models/SerialComm.js b/js/models/SerialComm.js index ba0ff1f76b7f7c02f31150f85f8b149686ee06e9..5c6b3a095c3c1287139a1c613c031cf783fa6d71 100644 --- a/js/models/SerialComm.js +++ b/js/models/SerialComm.js @@ -2,8 +2,8 @@ * Created by aghassaei on 6/17/15. */ -define(['underscore', 'backbone', 'socketio', 'machineState'], - function(_, Backbone, io, machineState){ +define(['underscore', 'backbone', 'socketio', 'machineState', 'cam'], + function(_, Backbone, io, machineState, cam){ var SerialComm = Backbone.Model.extend({ @@ -21,6 +21,7 @@ define(['underscore', 'backbone', 'socketio', 'machineState'], initialize: function(){ this.machineState = machineState; + this.listenTo(machineState, "change", this._updateVirtualMachine); this.attemptToConnectToNode(); }, @@ -61,31 +62,33 @@ define(['underscore', 'backbone', 'socketio', 'machineState'], this.socket.emit("stopStream"); }, + _updateVirtualMachine: function(){ + cam.setPosition(this.getMachineState().toJSON()); + }, + sendGCode: function(){ + if (!this.get("isStreaming")) return; + if (!cam.initialize) return;//don't do this from serial monitor window var self = this; var machineState = this.getMachineState(); - require(['cam'], function(cam){ - if (machineState && machineState.isReadyStatus()){ - var lineNum = cam.get("simLineNumber"); - var allLines = cam.get("dataOut").split("\n"); - if (lineNum >= 0 && lineNum < allLines.length) { - var line = allLines[lineNum]; - self.listenToOnce(machineState, "readyForNextCommand", function(){ - lineNum ++; - cam.set("simLineNumber", lineNum); - self.sendGCode(); - }); - self.send('{"gc":"' + line + '"}'); - cam.simulateCurrentLine(); - } else if (lineNum == allLines.length){ - cam.simulateCurrentLine(); - self.pauseStream(); - } else { - console.warn("invalid line number " + lineNum); - } - + if (machineState && machineState.isReadyStatus()){ + var lineNum = cam.get("simLineNumber"); + var allLines = cam.get("dataOut").split("\n"); + if (lineNum >= 0 && lineNum < allLines.length) { + var line = allLines[lineNum]; + self.listenToOnce(machineState, "readyForNextCommand", function(){ + lineNum ++; + cam.set("simLineNumber", lineNum); + self.sendGCode(); + }); + self.send('{"gc":"' + line + '"}'); + } else if (lineNum == allLines.length){ + self.pauseStream(); + } else { + console.warn("invalid line number " + lineNum); } - }); + + } else console.warn("machine not ready"); }, refreshMachineState: function(){//when updating connection, create a new instance of machine state @@ -135,8 +138,6 @@ define(['underscore', 'backbone', 'socketio', 'machineState'], } else if (json.sr){ serialComm.getMachineState().setPosition(json.sr); } - if (json.f) serialComm.getMachineState().setFooterStatus(json.f); - else if (json.r.f) serialComm.getMachineState().setFooterStatus(json.r.f); } catch(err) {} });