Go to Post My lasting impression of 217 (for years now) has been based on how their robot looks, dynamically. It is poultry in motion. :) - Richard Wallace [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 16-02-2007, 10:53
michniewski michniewski is offline
Registered User
FRC #1353
 
Join Date: Jan 2007
Location: Canada
Posts: 6
michniewski is an unknown quantity at this point
Question Trig Lookup Table

I've seen the trig lookup table function posted by Kevin Watson (this one: http://kevin.org/frc/frc_trig.zip ). I'm just wondering if anybody has an idea on how to implement an inverse cosine function?

My real problem is controlling 2 angles which have to be calculated. I have all the calculations, but they are quite involved (lots of inverse cos, sqrt, and squaring). I've ruled out a lookup table for the various combinations of these two angles. There are two independent variables that are controlled by the robot driver, and two calculated angles (Im pretty sure the lookup table for that would be way too huge).

Thus I return to my original question: how to implement an inverse cosine lookup table function? Perhaps using kevin watson's code posted above?

Thanks,

Michael Michniewski

p.s see my new post below
__________________
- Michael Michniewski
Team 1353, The Spartans



Greater Toronto Regional
- look for the Spartan mascot

Last edited by michniewski : 17-02-2007 at 10:39.
  #2   Spotlight this post!  
Unread 16-02-2007, 10:58
Robo_Coyote's Avatar
Robo_Coyote Robo_Coyote is offline
Cheap_Shot
AKA: Chris Chandler
FRC #1323 (MadTown Robotics )
Team Role: Mechanical
 
Join Date: Sep 2006
Rookie Year: 2005
Location: Madera
Posts: 115
Robo_Coyote is a splendid one to beholdRobo_Coyote is a splendid one to beholdRobo_Coyote is a splendid one to beholdRobo_Coyote is a splendid one to beholdRobo_Coyote is a splendid one to beholdRobo_Coyote is a splendid one to behold
Re: Trig Lookup Table

What are the two angles your looking trying to find for? I know that i had to find a few angles for our Mast on our bot. One for it at 45, one at 90, and then i had to find the two angles for where the Pnuematic ram would be placed and what distance on our mast and frame. This only took me about 15 Min in autocad... Autocad is the best mathmatical cheater. But i dont know what your looking for
__________________
2005- Uc Davis Spirit Award
2006 nationals second highest score thanks to 233, and 1184

We need a longer highlight list....... sigh

"To invent all you need is imagination and a pile of junk" - Thomas Edison
  #3   Spotlight this post!  
Unread 16-02-2007, 11:13
gnirts gnirts is offline
Suspicious pointer conversion
AKA: Robinson Levin
FRC #1648 (The Gearbox Gangstaz)
Team Role: Programmer
 
Join Date: Jan 2006
Rookie Year: 2005
Location: ATL
Posts: 116
gnirts will become famous soon enough
Re: Trig Lookup Table

You can use a similar method to what Kevin uses, but replace the data with the appropriate trig function. If you know your trig identities you might be able to use his functions to get the data you need.

However, depeding on how many calculations you are doing, you should be fine with a call to arccos() from <math.h>. Consider posting the code.

BTW, I don't think squaring is nearly as processor intensive as the other functions.

See also:
http://en.wikipedia.org/wiki/CORDIC
http://en.wikipedia.org/wiki/Generat...ometric_tables
  #4   Spotlight this post!  
Unread 16-02-2007, 14:02
purduephotog purduephotog is offline
Active Defense Design Engineer
AKA: Jason
FRC #3015
Team Role: Leadership
 
Join Date: Jan 2007
Rookie Year: 2004
Location: Rochester, NY
Posts: 162
purduephotog is a jewel in the roughpurduephotog is a jewel in the roughpurduephotog is a jewel in the roughpurduephotog is a jewel in the rough
Send a message via AIM to purduephotog
Re: Trig Lookup Table

Quote:
Originally Posted by michniewski View Post
I've seen the trig lookup table function posted by Kevin Watson (this one: http://kevin.org/frc/frc_trig.zip ). I'm just wondering if anybody has an idea on how to implement an inverse cosine function?

Thanks,

Michael Michniewski
I can't help with the inverse stuff but I did just cobble together a SIN/COS/TAN function lookup table in Java to show one of the students how it could be done. Remember, it's java, so you'll have to adjust the parameters and the data types as appropriate (signed, unsigned, etc).
Code:
/*
 * Main.java
 *
 * Created on February 16, 2007, 12:54 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package triglookup;

/**
 * Table Values provided from: http://www.industrialpress.com/en/tabid/63/default.aspx
 * @author purduePhotog
 */
public class Main {
    //TRIGTAB is x1000 values for added precision.
    private static int[] TRIGTAB = {0,17,35,52,70,87,105,122,139,156,174,191,208,225,242,259,276,292,309,326,342,358,375,391,407,423,438,454,469,485,500,515,530,545,559,574,588,602,616,629,643,656,669,682,695,707,719,731,743,755,766,777,788,799,809,819,829,839,848,857,866,875,883,891,899,906,914,921,927,934,940,946,951,956,961,966,970,974,978,982,985,988,990,993,995,996,997,998,999,1000,1000};
    
    /** Creates a new instance of Main */
    public Main() {
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        //Test the values of each function:
        //int n = -360;
        int n = 0;
        while (n <= 365) {
            System.err.println("Angle Test: " + n + "\tTAN: " + (double) TAN(n*100) / 1000);
            n = n + 5;
        }
    }
    
    //Expects ANG to be x100
    //public signed int SIN( signed long ANG, int SCALE) {
    public static int SIN(long ANG) {
      
       //Get us in the proper range for Sin to work.
        while (ANG > 36000) {
            ANG=ANG - 36000;
        }
        while (ANG < 0) {
            ANG= ANG + 36000;
        }
        
         //if we're from 0-90 (0-9000) then we simply return the lookup value
        if (ANG <= 9000 ) {
            return (TRIGTAB[(int)ANG/100]);
        } else if ((ANG > 9000) && (ANG <= 18000) ) {
            return (TRIGTAB[180 - (int)ANG/100]);
        } else if (( ANG > 18000) && (ANG <= 27000) ) {
            return (-1 * TRIGTAB[(int)ANG/100 - 180]);
        } else {
            return (-1 * TRIGTAB[360 - (int)ANG/100]);
        }
    }

    //Expects ANG to be x100
    public static int COS(long ANG) {
        //Simply offset the SIN by 90 degrees phase
        return (SIN(9000 + ANG));
    }

    //Expects ANG to be x100
    public static int TAN(long ANG) {
        //Simply offset the SIN by 90 degrees phase for COS
        int cosResult = COS(ANG);
        int sinResult = SIN(ANG);
        if (cosResult == 0) {
            cosResult = 1;
        }
        return ( sinResult * 1000 / cosResult );
    }
}
  #5   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.
  #6   Spotlight this post!  
Unread 17-02-2007, 20:28
gnirts gnirts is offline
Suspicious pointer conversion
AKA: Robinson Levin
FRC #1648 (The Gearbox Gangstaz)
Team Role: Programmer
 
Join Date: Jan 2006
Rookie Year: 2005
Location: ATL
Posts: 116
gnirts will become famous soon enough
Re: Trig Lookup Table

Quote:
Originally Posted by michniewski View Post
Code:
l_upper_squared = arm.length_upper^2;
l_lower_squared = arm.length_lower^2;

[...]

temp_R_squared = (arm.height^2) + (temp_o_d^2);
The ^ operator is bitwise XOR, there is no power operator in C. You need to use the pow() function or one of its brothers or just square it manually (which would be better if they are fixed point):
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);
Example of new code:
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;
Be sure you type-cast correctly.

Quote:
I've tried to keep all the trig functions the same (so they're all arccos, or inverse cosine).
This is a good way to keep it fast if you go with the lookup table solution.
Quote:
The arccos in the code should be (and now is) acos, right?
Yes, if you are using <math.h>. But I thought you were going to use a lookup table for inverse cosine, no? In which case you would have to name it to not conflict with the definition in <math.h> which you will need for sqrt(), eg. acos_lookup().

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...
  #7   Spotlight this post!  
Unread 23-02-2007, 20:57
Mike Bortfeldt Mike Bortfeldt is offline
Registered User
FRC #1126 (& 1511)
Team Role: Mentor
 
Join Date: Oct 2004
Rookie Year: 2004
Location: Rochester, NY
Posts: 119
Mike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud of
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
Attached Files
File Type: zip sincos_1126.zip (73.8 KB, 42 views)
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT -5. The time now is 00:30.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi