Thread: Look Up Tables
View Single Post
  #3   Spotlight this post!  
Unread 08-03-2005, 21:50
xchezhd xchezhd is offline
Registered User
#0171
 
Join Date: Mar 2005
Location: Platteville,WI
Posts: 2
xchezhd is an unknown quantity at this point
Re: Look Up Tables

you could use a little pointer math once you find the index from the first table.

int* y_ptr = &y; // can't remember if you need the & here,
// check during compile
value_from_y = *(y_ptr + index);



Quote:
Originally Posted by ace123
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.