Commit 0b2f8621 authored by Amanda Ghassaei's avatar Amanda Ghassaei

eod

parent 196f34dd
......@@ -40,6 +40,11 @@ define(['jquery', 'underscore', 'backbone', 'text!PositionControlPanelView.html'
this.model.send("!");
},
_pause: function(e){
e.preventDefault();
this.model.pauseStream();
},
_makeTemplateJSON: function(){
return {};
},
......
......@@ -275,41 +275,47 @@ define(['underscore', 'three', 'backbone', 'appState', 'latticeCAM', 'threeModel
resetSimulation: function(){
this.set("simLineNumber", 0, {silent:true});
appState.set("stockSimulationPlaying", false);
//todo isStreaming = false;
three.stopAnimationLoop();
lattice.showCells("cells");
},
_stockSimulation: function(){
if (appState.get("stockSimulationPlaying")){
three.startAnimationLoop();
var currentLine = this.get("simLineNumber");
if (currentLine == 0) lattice.hideCells("cells");
var allLines = this.get("dataOut").split("\n");
if(currentLine<allLines.length){
var self = this;
var scale = lattice.get("scale");
var scaledSettings = {
scale: scale,
originPosition: this.get("originPosition").clone().divideScalar(scale),
stockPosition: this.get("stockPosition").clone().divideScalar(scale),
};
this.get("exporter").simulate(allLines[currentLine], this.get("assembler"),
scaledSettings, function(){
currentLine++;
self.set("simLineNumber", currentLine);
self._stockSimulation();
});
} else {
//finished simulation
this.resetSimulation();
}
var currentLineNum = this.get("simLineNumber");
var self = this;
this.simulateCurrentLine(function(){
currentLineNum++;
self.set("simLineNumber", currentLineNum);
self._stockSimulation();
});
} else {
three.stopAnimationLoop();
this.get("assembler").pause();
}
},
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");
if(lineNum < allLines.length){
var scale = lattice.get("scale");
var scaledSettings = {
scale: scale,
originPosition: this.get("originPosition").clone().divideScalar(scale),
stockPosition: this.get("stockPosition").clone().divideScalar(scale)
};
this.get("exporter").simulate(allLines[lineNum], this.get("assembler"),
scaledSettings, callback);
} else {
//finished simulation
this.resetSimulation();
}
},
......
......@@ -239,7 +239,7 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', '
function sketchyCallback(){
totalThreads -= 1;
if (totalThreads > 0) return;
callback();
if (callback) callback();
}
var startingPos = this.components.xAxis.getPosition().add(this.components.yAxis.getPosition().add(this.components.zAxis.getPosition()));//this.components.zAxis.getAbsolutePosition();//get position of end effector
......
......@@ -123,20 +123,24 @@ define(['underscore', 'cam', 'lattice', 'three'], function(_, cam, lattice, THRE
var json = line.substr(1,line.length-2);
json = JSON.parse(json);
machine.releaseStock(json, settings);
return callback();
if (callback) callback();
return;
}
if (line[0] == "F"){//speed
this.animationSpeed = line.split("F")[1] / settings.scale;
return callback();
if (callback) callback();
return;
}
if (line == "" || line[0] == "(" || !this._isMoveCommand(line)){
return callback();
if (callback) callback();
return;
}
if (this._isMoveCommand(line)){
return this._simulateMove(line, this.animationSpeed, machine, settings, callback);
} else {
console.warn("problem parsing gcode: " + line);
return callback();
if (callback) callback();
return;
}
};
......
......@@ -29,19 +29,16 @@ define(['jquery', 'underscore', 'menuParent', 'serialComm', 'commPlist', 'text!s
_startStream: function(e){
e.preventDefault();
this.model.set("stockSimulationPlaying", true);
serialComm.startStream();
},
_pauseStream: function(e){
e.preventDefault();
this.model.set("stockSimulationPlaying", false);
serialComm.pauseStream();
},
_stopMachine: function(e){
e.preventDefault();
this.model.set("stockSimulationPlaying", false);
serialComm.stopStream();
},
......
......@@ -25,7 +25,7 @@ define(['underscore', 'backbone'], function(_, Backbone){
});
if (data.stat !== null && data.stat !== undefined) {
this.set("status", data.stat);
if (data.stat == 1 || data.stat == 3 || data.stat == 4) this._triggerNextCommand();
if (this.isReadyStatus(data.stat)) this._triggerNextCommand();
}
},
......@@ -36,6 +36,11 @@ define(['underscore', 'backbone'], function(_, Backbone){
} else this.set("status", 10);
},
isReadyStatus: function(status){
if (status == undefined) status = this.get("status");
return status == 1 || status == 3 || status == 4;
},
_triggerNextCommand: function(){
this.trigger("readyForNextCommand");
},
......
......@@ -2,7 +2,8 @@
* Created by aghassaei on 6/17/15.
*/
define(['underscore', 'backbone', 'socketio', 'machineState'], function(_, Backbone, io, machineState){
define(['underscore', 'backbone', 'socketio', 'machineState'],
function(_, Backbone, io, machineState){
var SerialComm = Backbone.Model.extend({
......@@ -60,6 +61,33 @@ define(['underscore', 'backbone', 'socketio', 'machineState'], function(_, Backb
this.socket.emit("stopStream");
},
sendGCode: function(){
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);
}
}
});
},
refreshMachineState: function(){//when updating connection, create a new instance of machine state
this.machineState.refresh();
},
......@@ -119,6 +147,7 @@ define(['underscore', 'backbone', 'socketio', 'machineState'], function(_, Backb
socket.on('isStreaming', function(data){
serialComm.set("isStreaming", data);
if (data == true) serialComm.sendGCode();
});
socket.on('portConnected', function(data){
......
......@@ -171,6 +171,7 @@ io.on('connection', function(socket){
function onPortOpen(name, baud){
io.emit("portConnected", {baudRate:baud, portName:name});
setIsStreaming(false);
}
function onPortData(data){
......
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