Thread: Look Up Tables
View Single Post
  #2   Spotlight this post!  
Unread 28-02-2005, 18:39
ace123's Avatar
ace123 ace123 is offline
Registered User
AKA: Patrick Horn
FRC #0008 (Paly Robotics - http://robotics.paly.net/)
Team Role: Programmer
 
Join Date: Feb 2005
Rookie Year: 2004
Location: Palo Alto, CA
Posts: 50
ace123 has a spectacular aura aboutace123 has a spectacular aura about
Send a message via AIM to ace123
Re: Look Up Tables

To search for an object in an array, do a small for loop:
Code:
int search_in_table_x(int lookfor)
    int i;
    for (i=0;i<table_length;++i) {
        if (x[i]==lookfor) {
            return i;
        }
    }
    return -1;
}
function Default_Routine(void) {
    int ind, x, y;
    // ...
    ind=search_in_table_x(135);
    if (ind!=-1) {
        x=x[ind];
        y=y[ind];
        pwm03=x; // then do something using those numbers?
        pwm04=y;
    }
}
(Check for -1 after using the function.)

I'm not sure exactly why you need a lookup table.

I'm pretty sure that whatever you are trying to do could be approximated faster and better with a small divide by 16 or something.

One thing to remember is that you shouldn't overcomplicate things like this. Something that can be solved with some complex math function with sines and powers or a lookup table could often be solved just as easily with a simple divide by 8 or scaling and adding without a noticable loss in accuracy.

Imagine if you are at the competition and your robot goes crazy. You would not want to debug through loads of complex math functions. It wouldn't be possible except for an extremely obvious error.
You would end up either wasting all of your precious practice day debugging it and getting nowhere or else giving up and making it simple.
__________________
-Patrick Horn, Paly Robotics

Check out the space simulator called Vega Strike, modelled after the space simulator games Elite and Wing Commander. It's Open Source too!
If you have ever played Wing Commander, or especially Privateer, and had a feeling of nostalga derived from the you will enjoy these two Vega Strike mods: Privateer Gemini Gold and Privateer Remake!
I'm working on adding multiplayer support this year...