From 1b45512a64003fa7f785077cf92e667ddce01479 Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Tue, 24 Mar 2015 18:53:35 -0400
Subject: [PATCH] simple animation of one bit bot working

---
 data/users/matt.user    |  2 +-
 js/cam/GCodeExporter.js |  2 +-
 js/cam/Machine.js       | 30 ++++++++++++++++++++++--------
 3 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/data/users/matt.user b/data/users/matt.user
index 5e465ac1..eee69971 100644
--- a/data/users/matt.user
+++ b/data/users/matt.user
@@ -1 +1 @@
-{"lattice":{"units":"inches","scale":2.78388,"cellSeparation":{"xy":0,"z":0},"cellType":"octa","connectionType":"edgeRot","partType":"vox","shouldPreserveCells":true},"assembler":{"camStrategy":"raster","placementOrder":"-X-YZ","camProcess":"gcode","machineName":"oneBitBot","rapidHeight":6.9,"rapidHeightRelative":true,"safeHeight":0.5,"originPosition":{"x":-1.39194,"y":1.39194,"z":0},"stockPosition":{"x":5.6081,"y":1.3919,"z":2},"stockPositionRelative":true,"multipleStockPositions":false,"stockArraySize":{"x":4,"y":4},"stockSeparation":2.78388,"rapidSpeeds":{"xy":6,"z":4},"feedRate":{"xy":0.1,"z":0.1},"simSpeed":4,"simStockNum":0,"stockHeight":0}}
\ No newline at end of file
+{"lattice":{"units":"inches","scale":2.78388,"cellSeparation":{"xy":0,"z":0},"cellType":"octa","connectionType":"edgeRot","partType":"vox","shouldPreserveCells":true},"assembler":{"camStrategy":"raster","placementOrder":"XYZ","camProcess":"gcode","machineName":"oneBitBot","rapidHeight":4.5,"rapidHeightRelative":true,"safeHeight":0.5,"originPosition":{"x":-1.39194,"y":1.39194,"z":0},"stockPosition":{"x":5.6081,"y":1.3919,"z":2},"stockPositionRelative":true,"multipleStockPositions":false,"stockArraySize":{"x":4,"y":4},"stockSeparation":2.78388,"rapidSpeeds":{"xy":6,"z":4},"feedRate":{"xy":0.1,"z":0.1},"simSpeed":"10","simStockNum":0,"stockHeight":0}}
\ No newline at end of file
diff --git a/js/cam/GCodeExporter.js b/js/cam/GCodeExporter.js
index dec78ede..a4bd2960 100644
--- a/js/cam/GCodeExporter.js
+++ b/js/cam/GCodeExporter.js
@@ -97,7 +97,7 @@ GCodeExporter.prototype.simulate = function(line, machine, wcs,  callback){
     }
     if (line.substr(0,3) == "G01"){
         //return this._simulateGetPosition(line, dmaGlobals.assembler.get("feedRate"), machine, wcs, callback);
-        return this._simulateGetPosition(line, dmaGlobals.assembler.get("rapidSpeeds"), machine, wcs, callback);
+        return this._simulateGetPosition(line, dmaGlobals.assembler.get("feedRate"), machine, wcs, callback);
     } else {
         console.warn("problem parsing gcode: " + line);
         return callback();
diff --git a/js/cam/Machine.js b/js/cam/Machine.js
index 13ffba9b..f6dd974b 100644
--- a/js/cam/Machine.js
+++ b/js/cam/Machine.js
@@ -265,7 +265,7 @@ OneBitBot.prototype._buildMeshes = function(callback){
         return geometry;
     }
     function meshPrep(geometry, name){
-        geometry.applyMatrix(new THREE.Matrix4().makeTranslation(-10-1.3919,-12.8,-1.9685));
+        geometry.applyMatrix(new THREE.Matrix4().makeTranslation(-10,-12.8,0));
         var mesh = new THREE.Mesh(geometry, new THREE.MeshLambertMaterial({color:0xaaaaaa, shading: THREE.FlatShading}));
         meshes[name] = mesh;
         if (allLoaded()) callback(meshes);
@@ -273,7 +273,7 @@ OneBitBot.prototype._buildMeshes = function(callback){
     var loader = new THREE.STLLoader();
     loader.load("assets/stls/oneBitBot/zAxis.STL", function(geometry){
         geometryScale(geometry);
-        geometry.applyMatrix(new THREE.Matrix4().makeTranslation(5,-2.4,-0.8));
+        geometry.applyMatrix(new THREE.Matrix4().makeTranslation(5,-2.4,-0.8-1.9685));
         meshPrep(geometry, "zAxis");
     });
     loader.load("assets/stls/oneBitBot/zDrive.STL", function(geometry){
@@ -299,17 +299,31 @@ OneBitBot.prototype._moveTo = function(x, y, z, speed, wcs, callback){
         if (totalThreads > 0) return;
         callback();
     }
-    var startingPos = this.meshes["basePlate"].position.clone();
+    var startingPos = this.meshes["zAxis"].position.clone();
     speed = this._normalizeSpeed(startingPos, x, y, this._reorganizeSpeed(speed));
-    this._moveAxis(startingPos.x, x, "x", speed.x, sketchyCallback);
-    this._moveAxis(startingPos.y, y, "y", speed.y, sketchyCallback);
-    this._moveAxis(startingPos.z, z, "z", speed.z, sketchyCallback);
+    this._moveXAxis(startingPos.x, x, "x", speed.x, sketchyCallback);
+    this._moveYAxis(startingPos.y, y, "y", speed.y, sketchyCallback);
+    this._moveZAxis(startingPos.z, z, "z", speed.z, sketchyCallback);
 };
 
-OneBitBot.prototype._moveAxis = function(startingPos, target, axis, speed, callback){
+OneBitBot.prototype._moveXAxis = function(startingPos, target, axis, speed, callback){
+    if (target == null || target === undefined) {
+        callback();
+        return;
+    }
+    this._animateObjects([this.meshes["zAxis"], this.meshes["zDrive"], this.meshes["yAxisMount"], this.cell], axis, speed, startingPos, target, callback);
+};
+OneBitBot.prototype._moveYAxis = function(startingPos, target, axis, speed, callback){
+    if (target == null || target === undefined) {
+        callback();
+        return;
+    }
+    this._animateObjects([this.meshes["zAxis"], this.meshes["zDrive"],  this.cell], axis, speed, startingPos, target, callback);
+};
+OneBitBot.prototype._moveZAxis = function(startingPos, target, axis, speed, callback){
     if (target == null || target === undefined) {
         callback();
         return;
     }
-    this._animateObjects(_.values(this.meshes).concat(this.cell), axis, speed, startingPos, target, callback);
+    this._animateObjects([this.meshes["zAxis"], this.cell], axis, speed, startingPos, target, callback);
 };
\ No newline at end of file
-- 
GitLab