Created
March 19, 2015 23:26
-
-
Save murilopolese/929a317d2e3b23216c1a to your computer and use it in GitHub Desktop.
Strawbees arm servo calculations
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 l = 17; | |
var toDegrees = function( radians ) { | |
return radians * ( 180 / Math.PI ); | |
} | |
var toRadians = function( degrees ) { | |
return degrees * ( Math.PI / 180 ); | |
} | |
// Polar magnitude | |
var d = function( x, y ) { | |
return Math.sqrt( Math.pow( x, 2 ) + Math.pow( y, 2 ) ); | |
} | |
// Polar angle | |
var teta = function( x, y ) { | |
return Math.atan2( y, x ); | |
} | |
// Angle between teta and the arm | |
var alpha = function( x, y ) { | |
var b = Math.sqrt( Math.pow( l, 2 ) - ( ( Math.pow( x, 2 ) + Math.pow( y, 2 ) ) / 4 ) ); | |
return Math.asin( b / l ); | |
} | |
// Angle between the arm and the claw | |
var beta = function( x, y ) { | |
return toRadians( 180 ) - ( 2 * alpha( x, y, l ) ); | |
} | |
// Calculate claw and arm angles for a position x and y | |
var move = function( x, y ) { | |
var claw = toDegrees( beta( x, y, l ) ); | |
var arm = toDegrees( teta( x, y ) + alpha( x, y, l ) ); | |
return { | |
claw: claw, | |
arm: arm | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment