diff --git a/js/cam/assemblers/Assembler.js b/js/cam/assemblers/Assembler.js index 78dbf6ccb8bf0e21b792985bf46b950c269f766d..3322393a66887b335467255c9c22497dabd990cf 100644 --- a/js/cam/assemblers/Assembler.js +++ b/js/cam/assemblers/Assembler.js @@ -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(); }); diff --git a/js/cam/assemblers/Component.js b/js/cam/assemblers/Component.js index 56c2902d0c0feb182b808fabcdb8e7eb872a764a..b8f9319a44e3955d0e7f611aae0d39a2a91d4fc3 100644 --- a/js/cam/assemblers/Component.js +++ b/js/cam/assemblers/Component.js @@ -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) { diff --git a/js/cam/processes/GCodeExporter.js b/js/cam/processes/GCodeExporter.js index 9b173600d39e510e8c04e32e2087a8ccb4a835f2..f2e0f9150a30b7b7510c92366d51fd9c8a316a79 100644 --- a/js/cam/processes/GCodeExporter.js +++ b/js/cam/processes/GCodeExporter.js @@ -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 diff --git a/js/menus/templates/CamMenuView.html b/js/menus/templates/CamMenuView.html index abf7b09f12437a6dd18413379260d9502c6006a9..28e38d161da7dc0a0e7a07cf7693d54c1a99ad2f 100644 --- a/js/menus/templates/CamMenuView.html +++ b/js/menus/templates/CamMenuView.html @@ -56,7 +56,7 @@ Origin (xyz): Stock Height: <input data-property="stockPosition" data-key="z" value="<%= stockPosition.z %>" placeholder="Z" class="form-control floatInput assembler" type="text"><br/><br/> <% } %> Approach Height (<%= units %>): <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): <input data-property="rapidSpeeds" data-key="xy" value="<%= rapidSpeeds.xy %>" placeholder="XY" class="form-control floatInput assembler" type="text"> <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): <input data-property="feedRate" data-key="xy" value="<%= feedRate.xy %>" placeholder="XY" class="form-control floatInput assembler" type="text"> diff --git a/js/plists/CamPList.js b/js/plists/CamPList.js index 8c3c587cc8a234bfe1ed40f1a276380e44000438..eb1e62622dd1bd92d915070d5a2df1bf07ce7f66 100644 --- a/js/plists/CamPList.js +++ b/js/plists/CamPList.js @@ -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} } } },