|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
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 Thanks, Michael Edit: the arccos in the code should be (and now is) acos, right? Last edited by michniewski : 17-02-2007 at 10:43. |
|
#2
|
|||
|
|||
|
Re: Trig Lookup Table
Quote:
Code:
#include <math.h> double pow(double x, double y); long double powl(long double x, long double y); float powf(float x, float y); Code:
temp_R_squared = pow(arm.height,2) + pow(temp_o_d,2); temp_R_squared = arm.height*arm.height + temp_o_d*temp_o_d; Quote:
Quote:
Also, if arm.length_upper, arm.length_lower, arm.offset_front, arm.distance are all constant consider doing the math on them ahead of time. And if all of these are floating point variables (which they need to be if you put them into functions like sqrt() and acos() then you are probably not going to get done quick enough. Consider making a lookup table for the whole operation (if possible) or just casting to floats for the <math.h> calls. Good luck, Robinson Last edited by gnirts : 17-02-2007 at 20:53. Reason: to put this message here... |
|
#3
|
|||
|
|||
|
Re: Trig Lookup Table
I've been meaning to post this for about a week or so, but for some reason never seemed to have any time. This is the type of method we have used for the past couple of years for calculating sine & cosine (and arcsine & arccosine). It uses both a lookup table and linear interpolation to determine the approximate value. It utilizes signed shorts rather than floating point to keep the execution speed decent. I’ve only extracted the sine/cosine routines but the documentation shows some other examples of how you could use some of underlying routines to generate your own non-linear functions.
Mike |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Lookup Table Generator GUI | teh_r4v3 | Programming | 6 | 15-02-2006 22:22 |
| A VERY nice perl script for generating lookup tables. | Validius | Programming | 11 | 31-03-2005 10:15 |
| Large Lookup Tables | Mr. Lim | Programming | 5 | 16-02-2004 21:30 |
| Lookup table generation tool | WillyC | Programming | 12 | 15-02-2004 21:01 |
| Trig | archiver | 2001 | 4 | 23-06-2002 23:14 |