diff --git a/js/cam/Machine.js b/js/cam/Machine.js index 5ef5d755bcb2d57632d98fac7d8b81525612262e..d0bc0d8ae4fda4e4efe7e85213150c1c61501462 100644 --- a/js/cam/Machine.js +++ b/js/cam/Machine.js @@ -62,6 +62,18 @@ Machine.prototype.releaseStock = function(index){ Machine.prototype.pause = function(){ }; +Machine.prototype.moveTo = function(x, y, z, speed, wcs, callback){ + x = this._makeAbsPosition(x, wcs.x); + y = this._makeAbsPosition(y, wcs.y); + z = this._makeAbsPosition(z, wcs.z); + this._moveTo(x, y, z, speed, wcs, callback); +}; + +Machine.prototype._makeAbsPosition = function(target, wcs){ + if (target == "" || target == null || target === undefined) return null; + return parseFloat(target)+wcs; +}; + Machine.prototype._reorganizeSpeed = function(speed){ var newSpeed = {}; newSpeed.x = speed.xy; @@ -83,37 +95,33 @@ Machine.prototype._normalizeSpeed = function(startingPos, x, y, speed){//xy move return normSpeed; }; -Machine.prototype._animateObjects = function(objects, axis, speed, target, callback){ +Machine.prototype._animateObjects = function(objects, axis, speed, startingPos, target, callback){ var increment = speed/5;//based on 1/10th of sec if (increment == 0) { if (callback) callback(); return; } var direction = 1; - if (target-objects[0].position[axis] < 0) direction = -1; + if (target-startingPos < 0) direction = -1; increment = Math.max(increment, 0.00001)*direction;//need to put a min on the increment - other wise this stall out with floating pt tol var simSpeed = 50/dmaGlobals.assembler.get("simSpeed");//1/10th of sec - this._incrementalMove(objects, axis, increment, target, direction, callback, simSpeed); + this._incrementalMove(objects, axis, increment, startingPos, target, direction, callback, simSpeed); }; -Machine.prototype._incrementalMove = function(objects, axis, increment, target, direction, callback, simSpeed){ +Machine.prototype._incrementalMove = function(objects, axis, increment, currentPos, target, direction, callback, simSpeed){ var self = this; setTimeout(function(){ - if ((target-objects[0].position[axis])*direction <= 0) { + if ((target-currentPos)*direction <= 0) { if (callback) callback(); return; } + var nextPos = currentPos + increment; + if (Math.abs(target-currentPos) < Math.abs(increment)) nextPos = target;//don't overshoot _.each(objects, function(object){ - if (object instanceof DMACell){ - var currentPosition = object.currentPosition(); - if (Math.abs(target-currentPosition[axis]) < Math.abs(increment)) object.moveTo(target, axis);//don't overshoot - else object.moveTo(currentPosition[axis]+increment, axis); - } else { - if (Math.abs(target-object.position[axis]) < Math.abs(increment)) object.position[axis] = target;//don't overshoot - else object.position[axis] += increment; - } + if (object instanceof DMACell) object.moveTo(nextPos, axis); + else object.position[axis] = nextPos; }); - self._incrementalMove(objects, axis, increment, target, direction, callback, simSpeed) + self._incrementalMove(objects, axis, increment, nextPos, target, direction, callback, simSpeed) },simSpeed); }; @@ -151,16 +159,13 @@ Shopbot.prototype._buildMeshes = function(callback){ }); }; -Shopbot.prototype.moveTo = function(x, y, z, speed, wcs, callback){ +Shopbot.prototype._moveTo = function(x, y, z, speed, wcs, callback){ var totalThreads = 3; function sketchyCallback(){ totalThreads -= 1; if (totalThreads > 0) return; callback(); } - x = this._makeAbsPosition(x, wcs.x); - y = this._makeAbsPosition(y, wcs.y); - z = this._makeAbsPosition(z, wcs.z); speed = this._normalizeSpeed(this.meshes[0].position, x, y, this._reorganizeSpeed(speed)); this._moveAxis(x, "x", speed.x, sketchyCallback); this._moveAxis(y, "y", speed.y, sketchyCallback); @@ -168,17 +173,12 @@ Shopbot.prototype.moveTo = function(x, y, z, speed, wcs, callback){ this.cell.updateForScale();//todo why is this here? }; -Shopbot.prototype._makeAbsPosition = function(target, wcs){ - if (target == "" || target == null || target === undefined) return null; - return parseFloat(target)+wcs; -}; - Shopbot.prototype._moveAxis = function(target, axis, speed, callback){ if (target == null || target === undefined) { callback(); return; } - this._animateObjects(this.meshes.concat(this.cell), axis, speed, target, callback); + this._animateObjects(this.meshes.concat(this.cell), axis, speed, this.meshes[0].position[axis], target, callback); }; /////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/js/fea/DmaCell.js b/js/fea/DmaCell.js index 9dd61d384a6c4ba6ca3219400ab9875502835f07..dea48475b8bae118302acf29d012b1fa89daf4a9 100644 --- a/js/fea/DmaCell.js +++ b/js/fea/DmaCell.js @@ -101,10 +101,6 @@ DMACell.prototype.moveTo = function(position, axis){//used for stock simulations //todo update parts too }; -DMACell.prototype.currentPosition = function(){//used for stock simulations - return this.cellMesh.position.clone(); -}; - DMACell.prototype.getType = function(){ return null;//only used in freeform layout };