Commit 45b53205 authored by Amanda Ghassaei's avatar Amanda Ghassaei
Browse files

rotation between layers starting to work

parent c2d7b651
......@@ -223,16 +223,20 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', '
});
};
Assembler.prototype.pickUpStock = function(settings){
Assembler.prototype.pickUpStock = function(index, position, speed, settings, callback){
if (index.z%2 != 0) {//rotate on odd rows
this.components.frame.rotateTo(new THREE.Vector3(0, 0, Math.PI/2), speed, callback);
} else {
this.components.frame.rotateTo(new THREE.Vector3(0, 0, 0), speed, callback);
}
_.each(this.stock, function(stock){
stock.show();
});
callback();
};
Assembler.prototype.releaseStock = function(json, settings){
json = JSON.parse(json);
console.log(json.index);
lattice.showCellAtIndex(json.index);
Assembler.prototype.releaseStock = function(index, position, settings){
lattice.showCellAtIndex(index);
_.each(this.stock, function(stock){
stock.hide();
});
......
......@@ -73,17 +73,66 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){
return this.object3D.position.clone();
};
Component.prototype.getRotation = function(){
return this.object3D.rotation.toVector3();
};
Component.prototype.getObject3D = function(){
return this.object3D;
};
Component.prototype.rotateTo = function(target, speed, callback){
if (target === null){
if (callback) callback();
return;
}
var currentPosition = this.getRotation();
var increment = 0.15;//speed/1500.0*cam.get("simSpeed");
var incrVector = target.clone().sub(currentPosition);
if (increment == 0 || incrVector.length() == 0) {
if (callback) callback();
return;
}
increment = Math.max(increment, 0.00001);//need to put a min on the increment - otherwise this stalls out with floating pt tol
incrVector.normalize().multiplyScalar(increment);
this._incrementalRotation(incrVector, target, callback);
};
Component.prototype._incrementalRotation = function(increment, target, callback){
var self = this;
setTimeout(function(){
var remainingDist = (target.clone().sub(self.getRotation())).length();
var nextPos;
if (remainingDist == 0) {
if (callback) callback();
return;
} else if (remainingDist < increment.length()){
nextPos = target;//don't overshoot
self.object3D.rotation.x = target.x;
self.object3D.rotation.y = target.y;
self.object3D.rotation.z = target.z;
if (callback) callback();
return;
} else {
nextPos = self.getRotation().add(increment);
}
// console.log(target.clone().normalize());
console.log(increment);
self.object3D.rotateOnAxis(target.clone().normalize(), nextPos.z);
self._incrementalRotation(increment, target, callback);
}, 10);
};
Component.prototype.moveTo = function(target, speed, callback){
if (target === null){
if (callback) callback();
return;
}
var currentPosition = this.getPosition();
var increment = speed/25*cam.get("simSpeed");
var increment = speed/1500.0*cam.get("simSpeed");
var incrVector = target.clone().sub(currentPosition);
if (increment == 0 || incrVector.length() == 0) {
......
......@@ -97,12 +97,15 @@ define(['underscore', 'cam', 'lattice'], function(_, cam, lattice){
};
GCodeExporter.prototype.simulate = function(line, machine, settings, callback){
if (line.substr(0,11) == "(get stock)"){
machine.pickUpStock(settings);
return callback();
if (line.substr(0,10) == "(get stock"){
var json = line.substr(11,line.length-12);
json = JSON.parse(json);
return machine.pickUpStock(json.index, json.position, this.animationSpeed, settings, callback);
}
if (line.substr(0,2) == "({"){
machine.releaseStock(line.substr(1,line.length-2), settings);
var json = line.substr(1,line.length-2);
json = JSON.parse(json);
machine.releaseStock(json.index, json.position, settings);
return callback();
}
if (line[0] == "F"){//speed
......
......@@ -56,7 +56,7 @@ Origin (xyz):&nbsp;&nbsp;
Stock Height: &nbsp;&nbsp;<input data-property="stockPosition" data-key="z" value="<%= stockPosition.z %>" placeholder="Z" class="form-control floatInput assembler" type="text"><br/><br/>
<% } %>
Approach Height (<%= units %>): &nbsp;&nbsp;<input data-property="safeHeight" value="<%= safeHeight %>" placeholder="Z" class="form-control floatInput assembler" type="text"><br/><br/>
Speeds (<%= units %> per second):<br/><br/>
Speeds (<%= units %> per min):<br/><br/>
Rapids (xy, z): &nbsp;&nbsp;<input data-property="rapidSpeeds" data-key="xy" value="<%= rapidSpeeds.xy %>" placeholder="XY" class="form-control floatInput assembler" type="text">&nbsp;
<input data-property="rapidSpeeds" data-key="z" value="<%= rapidSpeeds.z %>" placeholder="Z" class="form-control floatInput assembler" type="text"><br/><br/>
Feed Rate (xy, z): &nbsp;&nbsp;<input data-property="feedRate" data-key="xy" value="<%= feedRate.xy %>" placeholder="XY" class="form-control floatInput assembler" type="text">&nbsp;
......
......@@ -142,8 +142,8 @@ define(['three'], function(THREE){
rapidHeightRelative: true,
safeHeight: 0.5,
originPosition: new THREE.Vector3(0,0,0),
rapidSpeeds:{xy: 3, z: 2},
feedRate:{xy: 0.1, z: 0.1}
rapidSpeeds:{xy: 240, z: 120},
feedRate:{xy: 6, z: 6}
}
}
},
......
Supports Markdown
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