Last active
August 29, 2015 14:06
-
-
Save ril3y/9a59fa8c1fe15e2a9a31 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var VELOCITY_ACCURACY = 1 | |
var calcPen = function(zLen){ | |
//Pendulum Movement Equation | |
//T = 2pi*SQRT(L/g) | |
var twoPi = 6.2831926 | |
var gravity = 9.8 | |
var result = twoPi * Math.sqrt(zLen / gravity); | |
return(result.toFixed(4)) | |
} | |
var _calcVelocity = function(xyLen, jerk, zLen, axis, isDoubleMove){ | |
// V = 1 / 3 (3T j v_1 - 3D j - v_1 sqrt(j v_1) sqrt(sqrt(3) 30)) / j | |
// V' = 1 / 3 (-sqrt(j v_1) sqrt(sqrt(3) 30) - 1 / 2 j v_1 sqrt(sqrt(3) 30) / sqrt(j v_1) + 3T j) / j | |
isDoubleMove = isDoubleMove || false | |
var jerk = jerk*1000000; | |
var pendulumPeriod = calcPen(zLen/100); | |
var sqrt_three_thirty = Math.sqrt(Math.sqrt(3)*30); | |
// Guess xyLen/pendulumPeriod, which will get the loop started | |
var v_1 = xyLen/pendulumPeriod; | |
// The previous guess -- lets start it way off | |
var v_1_previous = v_1-100; | |
//console.log("v_1: "+ v_1); | |
while (Math.abs(v_1 - v_1_previous) > VELOCITY_ACCURACY) { | |
v_1_previous = v_1; | |
// V = (3*T*j*v_1 - 3*D*j - v_1*sqrt(j*v_1)*sqrt_three_thirty) / 3*j | |
// V' = (-sqrt(j*v_1)*sqrt_three_thirty - (j*v_1*sqrt_three_thirty)/(2*sqrt(j*v_1)) + 3*T*j) / 3*j | |
var sqrt_j_v = Math.sqrt(jerk*v_1); | |
// V = (3*T*j*v_1 - 3*D*j - v_1*sqrt_j_v*sqrt_three_thirty) / 3*j | |
// V' = (-sqrt_j_v*sqrt_three_thirty - (j*v_1*sqrt_three_thirty)/(2*sqrt_j_v) + 3*T*j) / 3*j | |
var F_v_1 = (3*pendulumPeriod*jerk*v_1 - 3*xyLen*jerk - v_1*sqrt_j_v*sqrt_three_thirty) / 3*jerk; | |
var Fd_v_1 = (-sqrt_j_v*sqrt_three_thirty - (jerk*v_1*sqrt_three_thirty)/(2*sqrt_j_v) + 3*pendulumPeriod*jerk) / 3*jerk; | |
v_1 = v_1 - (F_v_1/Fd_v_1); | |
//console.log("v_1: "+ v_1.toFixed(4) + " F_v_1: " + F_v_1.toFixed(4) + " Fd_v_1: " + Fd_v_1.toFixed(4)); | |
if(isDoubleMove){ | |
console.log("G1 F" + (v_1*60).toFixed(4) + " "+ axis+xyLen + " (Comment: single move)") | |
} | |
} | |
return (v_1*60).toFixed(4); | |
} | |
exports.calcXYmove = function(xlen, ylen, zlen, jerk){ | |
//pythag | |
var totalMovelen = Math.sqrt(Math.pow(xlen, 2) + Math.pow(ylen, 2)) | |
console.log("Total Move Len: " + totalMovelen) | |
var vel = _calcVelocity(totalMovelen, jerk, zlen,"") | |
console.log("G1 F" + (vel) + " X" + xlen + " Y" + ylen + " (Comment: double move)") | |
} | |
exports.calcVelocity = _calcVelocity | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment