Commit 6e2823c2 authored by Amanda Ghassaei's avatar Amanda Ghassaei
Browse files

motion vectors in simulation code

parent 8fb43768
...@@ -339,11 +339,12 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', ' ...@@ -339,11 +339,12 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', '
if (totalThreads > 0) return; if (totalThreads > 0) return;
callback(); callback();
} }
var startingPos = {x:this.components.xAxis.getPosition().x, y:this.components.yAxis.getPosition().y, z:this.components.zAxis.getPosition().z};
speed = this._normalizeSpeed(startingPos, position, new THREE.Vector3(speed, speed, speed)); var startingPos = this.components.zAxis.getAbsolutePosition();//get position of end effector
this.components.xAxis.moveTo(this._makeAxisVector(position, "x"), speed.x, sketchyCallback); speed = this._normalizeSpeed(startingPos, position, new THREE.Vector3(speed, speed, speed));//todo fix this
this.components.yAxis.moveTo(this._makeAxisVector(position, "y"), speed.y, sketchyCallback); this.components.xAxis.moveTo(position, speed.x, sketchyCallback);
this.components.zAxis.moveTo(this._makeAxisVector(position, "z"), speed.z, sketchyCallback); this.components.frame.moveTo(position, speed.y, sketchyCallback);
this.components.zAxis.moveTo(position, speed.z, sketchyCallback);
}; };
Assembler.prototype._normalizeSpeed = function(startingPos, position, speed){//todo make this more general Assembler.prototype._normalizeSpeed = function(startingPos, position, speed){//todo make this more general
......
...@@ -84,6 +84,30 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){ ...@@ -84,6 +84,30 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){
return this.object3D.position.clone(); return this.object3D.position.clone();
}; };
Component.prototype.getAbsolutePosition = function(){
if (!this.parent) return this.getPosition();
return this.parentObject.getAbsolutePosition().add(this.parentObject.applyRotation(this.getPosition()));
};
Component.prototype.getOrientation = function(){
return this.object3D.quaternion.clone();
};
Component.prototype.getAbsoluteOrientation = function(){
if (!this.parent) return this.getOrientation();
return this.getOrientation().multiply(this.parentObject.getAbsoluteOrientation());//order matters!
};
Component.prototype.applyRotation = function(vector){//todo local rotation?
vector.applyQuaternion(this.getAbsoluteOrientation());
return vector;
};
Component.prototype.applyAbsoluteRotation = function(vector){
vector.applyQuaternion(this.getAbsoluteOrientation());
return vector;
};
Component.prototype.setTranslucent = function(translucent){ Component.prototype.setTranslucent = function(translucent){
if (this.stl === undefined) return; if (this.stl === undefined) return;
this.stl.material.transparent = translucent; this.stl.material.transparent = translucent;
...@@ -145,10 +169,12 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){ ...@@ -145,10 +169,12 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){
}; };
Component.prototype.moveTo = function(target, speed, callback){ Component.prototype.moveTo = function(target, speed, callback){
var target = this._multiplyVectors(target, this.motionVector);
if (target === null){ if (target === null){
if (callback) callback(); if (callback) callback();
return; return;
} }
var currentPosition = this.getPosition(); var currentPosition = this.getPosition();
var increment = speed/1500.0*cam.get("simSpeed"); var increment = speed/1500.0*cam.get("simSpeed");
var incrVector = target.clone().sub(currentPosition); var incrVector = target.clone().sub(currentPosition);
...@@ -163,6 +189,14 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){ ...@@ -163,6 +189,14 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){
this._incrementalMove(incrVector, target, callback); this._incrementalMove(incrVector, target, callback);
}; };
Component.prototype._multiplyVectors = function(target, motion){
if (target.x === null && motion.x > 0) return null;
if (target.y === null && motion.y > 0) return null;
if (target.z === null && motion.z > 0) return null;
var target = new THREE.Vector3(target.x, target.y, target.z);
return target.multiply(motion);
};
Component.prototype._incrementalMove = function(increment, target, callback){ Component.prototype._incrementalMove = function(increment, target, callback){
var self = this; var self = this;
setTimeout(function(){ setTimeout(function(){
......
...@@ -41,7 +41,6 @@ define(['three'], function(THREE){ ...@@ -41,7 +41,6 @@ define(['three'], function(THREE){
xAxis: { xAxis: {
name: "X Axis", name: "X Axis",
rotary: false, rotary: false,
axisOfMotion: null,
//minBound //minBound
//maxBound //maxBound
parent: "yAxis", parent: "yAxis",
...@@ -56,7 +55,6 @@ define(['three'], function(THREE){ ...@@ -56,7 +55,6 @@ define(['three'], function(THREE){
frame: { frame: {
name: "Y Axis", name: "Y Axis",
rotary: false, rotary: false,
axisOfMotion: null,
//minBound //minBound
//maxBound //maxBound
parent: "substrate", parent: "substrate",
...@@ -68,7 +66,6 @@ define(['three'], function(THREE){ ...@@ -68,7 +66,6 @@ define(['three'], function(THREE){
zAxis: { zAxis: {
name: "Z Axis", name: "Z Axis",
rotary: false, rotary: false,
axisOfMotion: null,
//minBound //minBound
//maxBound //maxBound
parent: "xAxis", parent: "xAxis",
...@@ -80,7 +77,6 @@ define(['three'], function(THREE){ ...@@ -80,7 +77,6 @@ define(['three'], function(THREE){
yAxis: { yAxis: {
name: "Frame", name: "Frame",
rotary: false, rotary: false,
axisOfMotion: null,
//minBound //minBound
//maxBound //maxBound
parent: "frame", parent: "frame",
...@@ -92,8 +88,7 @@ define(['three'], function(THREE){ ...@@ -92,8 +88,7 @@ define(['three'], function(THREE){
substrate: { substrate: {
name: "Substrate", name: "Substrate",
rotary: true, rotary: true,
axisOfMotion: null, centerOfRotation: {x:4,y:4.5,z:0},//(5.08mm, 5.715mm)
centerOfRotation: {x:10,y:10,z:0},//(5.08mm, 5.715mm)
//minBound //minBound
//maxBound //maxBound
parent: null, parent: null,
......
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