View Single Post
  #1   Spotlight this post!  
Unread 17-02-2007, 10:38
michniewski michniewski is offline
Registered User
FRC #1353
 
Join Date: Jan 2007
Location: Canada
Posts: 6
michniewski is an unknown quantity at this point
Re: Trig Lookup Table

Thanks for the replies.

I'm not just looking for a given number of angles (ie set positions), but rather within a range (almost 360 degrees for at least one of two angles).

I'll try the suggestion of replacing the cos function in Kevin's code with the cosine inverse.

Here's the current code. I put things that are used or calculated more than once in a variable, which is called later.

Basically I'm just looking for the quickest way to execute this code, my main idea being using a trig lookup table.

Code:
//
// For Calculations
//
l_upper_squared = arm.length_upper^2;
l_lower_squared = arm.length_lower^2;

// dist. of arm infront of bot + offset of arm from front of bot
temp_o_d = (arm.offset_front + arm.distance); 

temp_R_squared = (arm.height^2) + (temp_o_d^2);
temp_R = sqrt(temp_R_squared);

//
// Calculate Angles
//

// calculate joint1 angle 1
j1_angle1 = acos( arm.distance / temp_R  );

// calculate joint1 angle 2
temp_var = ( (l_upper_squared) - (l_lower_squared) - (temp_R_squared) ) / ( (-2) * (arm.length_lower) * temp_R );
j1_angle2 = acos( temp_var );

// calculate joint2 angle
temp_var =  ( temp_R_squared - (l_lower_squared) - (l_upper_squared) ) / ( (-2) * arm.length_lower * arm.length_upper );
j2_angle = acos( temp_var );

//
// Set Joint Angles
//
arm.j1_set_angle = j1_angle1 + j1_angle2;	// joint1
arm.j2_set_angle = j2_angle;				// joint2

// done
I've tried to keep all the trig functions the same (so they're all arccos, or inverse cosine).

Thanks,

Michael

Edit: the arccos in the code should be (and now is) acos, right?
__________________
- Michael Michniewski
Team 1353, The Spartans



Greater Toronto Regional
- look for the Spartan mascot

Last edited by michniewski : 17-02-2007 at 10:43.