Commit 464ffb3e authored by Amanda Ghassaei's avatar Amanda Ghassaei

comm is nearly there

parent 0b2f8621
...@@ -30,7 +30,7 @@ define(['jquery', 'underscore', 'backbone', 'text!PositionControlPanelView.html' ...@@ -30,7 +30,7 @@ define(['jquery', 'underscore', 'backbone', 'text!PositionControlPanelView.html'
$("#positionData").html(_.template(positionTemplate)(machineState.toJSON())); $("#positionData").html(_.template(positionTemplate)(machineState.toJSON()));
}, },
_askForPosition: function(e){ _askForPosition: function(e){//todo should be in machine state init
if (e) e.preventDefault(); if (e) e.preventDefault();
this.model.send('{"sr":n}'); this.model.send('{"sr":n}');
}, },
......
/**
* Created by aghassaei on 9/18/15.
*/
define([], function(){
return {
setPosition: function(){}
}
});
\ No newline at end of file
...@@ -22,7 +22,8 @@ require.config({ ...@@ -22,7 +22,8 @@ require.config({
plist: '../plists/PList', plist: '../plists/PList',
commPlist: '../plists/commPlist', commPlist: '../plists/commPlist',
serialComm: '../models/SerialComm', serialComm: '../models/SerialComm',
machineState: '../models/MachineState' machineState: '../models/MachineState',
cam: 'fakeCam'
}, },
......
...@@ -297,7 +297,6 @@ define(['underscore', 'three', 'backbone', 'appState', 'latticeCAM', 'threeModel ...@@ -297,7 +297,6 @@ define(['underscore', 'three', 'backbone', 'appState', 'latticeCAM', 'threeModel
simulateCurrentLine: function(callback){ simulateCurrentLine: function(callback){
var lineNum = this.get("simLineNumber"); var lineNum = this.get("simLineNumber");
console.log(lineNum);
three.startAnimationLoop(); three.startAnimationLoop();
if (lineNum == 0) lattice.hideCells("cells"); if (lineNum == 0) lattice.hideCells("cells");
var allLines = this.get("dataOut").split("\n"); var allLines = this.get("dataOut").split("\n");
...@@ -318,6 +317,19 @@ define(['underscore', 'three', 'backbone', 'appState', 'latticeCAM', 'threeModel ...@@ -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();
},
......
...@@ -232,6 +232,14 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', ' ...@@ -232,6 +232,14 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', '
Assembler.prototype.pause = function(){ 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){ Assembler.prototype.moveTo = function(position, speed, settings, callback){
......
...@@ -171,7 +171,15 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){ ...@@ -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(){ Component.prototype.getObject3D = function(){
return this.object3D; return this.object3D;
......
...@@ -23,8 +23,11 @@ define(['jquery', 'underscore', 'menuParent', 'serialComm', 'commPlist', 'text!s ...@@ -23,8 +23,11 @@ define(['jquery', 'underscore', 'menuParent', 'serialComm', 'commPlist', 'text!s
this.listenTo(this.model, "change:stockSimulationPlaying", this.render); this.listenTo(this.model, "change:stockSimulationPlaying", this.render);
this.listenTo(serialComm, "change:isStreaming", this.render); this.listenTo(serialComm, "change:isStreaming", this.render);
this.listenTo(cam, "change:simLineNumber", this._lineNumChanged); 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){ _startStream: function(e){
...@@ -44,13 +47,13 @@ define(['jquery', 'underscore', 'menuParent', 'serialComm', 'commPlist', 'text!s ...@@ -44,13 +47,13 @@ define(['jquery', 'underscore', 'menuParent', 'serialComm', 'commPlist', 'text!s
_decrementLineNum: function(e){ _decrementLineNum: function(e){
e.preventDefault(); e.preventDefault();
var nextLine = this.nextLine - 1; var nextLine = cam.get("simLineNumber") - 1;
this._setNextLine(nextLine); this._setNextLine(nextLine);
}, },
_incrementLineNum: function(e){ _incrementLineNum: function(e){
e.preventDefault(); e.preventDefault();
var nextLine = this.nextLine + 1; var nextLine = cam.get("simLineNumber") + 1;
this._setNextLine(nextLine); this._setNextLine(nextLine);
}, },
...@@ -58,8 +61,12 @@ define(['jquery', 'underscore', 'menuParent', 'serialComm', 'commPlist', 'text!s ...@@ -58,8 +61,12 @@ define(['jquery', 'underscore', 'menuParent', 'serialComm', 'commPlist', 'text!s
var length = cam.get("dataOut").split("\n").length; var length = cam.get("dataOut").split("\n").length;
if (nextLine < 0) nextLine = length-1; if (nextLine < 0) nextLine = length-1;
if (nextLine > length-1) nextLine = 0; if (nextLine > length-1) nextLine = 0;
this.nextLine = nextLine; cam.set("simLineNumber", nextLine);
$("#nextLine").val(this.nextLine); },
_showNextLine: function(nextLine){
console.log(nextLine);
$("#nextLine").val(nextLine);
this._drawGcodeHighlighter(nextLine); this._drawGcodeHighlighter(nextLine);
}, },
...@@ -70,7 +77,7 @@ define(['jquery', 'underscore', 'menuParent', 'serialComm', 'commPlist', 'text!s ...@@ -70,7 +77,7 @@ define(['jquery', 'underscore', 'menuParent', 'serialComm', 'commPlist', 'text!s
_lineNumChanged: function(){ _lineNumChanged: function(){
var lineNum = cam.get("simLineNumber"); var lineNum = cam.get("simLineNumber");
this._setNextLine(lineNum); this._showNextLine(lineNum);
}, },
_drawGcodeHighlighter: function(lineNum){ _drawGcodeHighlighter: function(lineNum){
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<% } %> <% } %>
<br/> <br/>
<a href="#" id="openSerialMonitor" class="btn btn-block btn-lg btn-default">Open Serial Monitor</a><br/> <a href="#" id="openSerialMonitor" class="btn btn-block btn-lg btn-default">Open Serial Monitor</a><br/>
Next Line: &nbsp;&nbsp;<input id="nextLine" value=<%= nextLine %> placeholder="##" class="intInput form-control unresponsiveInput" type="text"> Next Line: &nbsp;&nbsp;<input id="nextLine" property="simLineNumber" value="<%= nextLine %>" placeholder="##" class="intInput form-control cam" type="text">
&nbsp;&nbsp;<a href="#" id="previousLineButton" class="btn btn-lg btn-default"><span class="fui-triangle-up"></span></a> &nbsp;&nbsp;<a href="#" id="previousLineButton" class="btn btn-lg btn-default"><span class="fui-triangle-up"></span></a>
&nbsp;&nbsp;<a href="#" id="nextLineButton" class="btn btn-lg btn-default"><span class="fui-triangle-down"></span></a><br/><br/> &nbsp;&nbsp;<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/> <div id="gcodeEditor"><%= dataOut %></div><br/>
......
...@@ -29,15 +29,8 @@ define(['underscore', 'backbone'], function(_, Backbone){ ...@@ -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){ isReadyStatus: function(status){
if (status == undefined) status = this.get("status"); if (status === undefined) status = this.get("status");
return status == 1 || status == 3 || status == 4; return status == 1 || status == 3 || status == 4;
}, },
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
* Created by aghassaei on 6/17/15. * Created by aghassaei on 6/17/15.
*/ */
define(['underscore', 'backbone', 'socketio', 'machineState'], define(['underscore', 'backbone', 'socketio', 'machineState', 'cam'],
function(_, Backbone, io, machineState){ function(_, Backbone, io, machineState, cam){
var SerialComm = Backbone.Model.extend({ var SerialComm = Backbone.Model.extend({
...@@ -21,6 +21,7 @@ define(['underscore', 'backbone', 'socketio', 'machineState'], ...@@ -21,6 +21,7 @@ define(['underscore', 'backbone', 'socketio', 'machineState'],
initialize: function(){ initialize: function(){
this.machineState = machineState; this.machineState = machineState;
this.listenTo(machineState, "change", this._updateVirtualMachine);
this.attemptToConnectToNode(); this.attemptToConnectToNode();
}, },
...@@ -61,31 +62,33 @@ define(['underscore', 'backbone', 'socketio', 'machineState'], ...@@ -61,31 +62,33 @@ define(['underscore', 'backbone', 'socketio', 'machineState'],
this.socket.emit("stopStream"); this.socket.emit("stopStream");
}, },
_updateVirtualMachine: function(){
cam.setPosition(this.getMachineState().toJSON());
},
sendGCode: function(){ sendGCode: function(){
if (!this.get("isStreaming")) return;
if (!cam.initialize) return;//don't do this from serial monitor window
var self = this; var self = this;
var machineState = this.getMachineState(); var machineState = this.getMachineState();
require(['cam'], function(cam){ if (machineState && machineState.isReadyStatus()){
if (machineState && machineState.isReadyStatus()){ var lineNum = cam.get("simLineNumber");
var lineNum = cam.get("simLineNumber"); var allLines = cam.get("dataOut").split("\n");
var allLines = cam.get("dataOut").split("\n"); if (lineNum >= 0 && lineNum < allLines.length) {
if (lineNum >= 0 && lineNum < allLines.length) { var line = allLines[lineNum];
var line = allLines[lineNum]; self.listenToOnce(machineState, "readyForNextCommand", function(){
self.listenToOnce(machineState, "readyForNextCommand", function(){ lineNum ++;
lineNum ++; cam.set("simLineNumber", lineNum);
cam.set("simLineNumber", lineNum); self.sendGCode();
self.sendGCode(); });
}); self.send('{"gc":"' + line + '"}');
self.send('{"gc":"' + line + '"}'); } else if (lineNum == allLines.length){
cam.simulateCurrentLine(); self.pauseStream();
} else if (lineNum == allLines.length){ } else {
cam.simulateCurrentLine(); console.warn("invalid line number " + lineNum);
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 refreshMachineState: function(){//when updating connection, create a new instance of machine state
...@@ -135,8 +138,6 @@ define(['underscore', 'backbone', 'socketio', 'machineState'], ...@@ -135,8 +138,6 @@ define(['underscore', 'backbone', 'socketio', 'machineState'],
} else if (json.sr){ } else if (json.sr){
serialComm.getMachineState().setPosition(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) {} } catch(err) {}
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment