Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@murilopolese
Created March 19, 2015 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save murilopolese/929a317d2e3b23216c1a to your computer and use it in GitHub Desktop.
Save murilopolese/929a317d2e3b23216c1a to your computer and use it in GitHub Desktop.
Strawbees arm servo calculations
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