|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Look Up Tables
First, I would like to say thanks to all the people that give support to me and others on these forumns.
Next, since I can't use math functions, it has been suggested that a look-up table be used. I can make the tables, but how to I read data from them? Like on table 1 find this number. Then from that number, goto table 2 with the same row and find that number. const int table_length = 18; rom const int x[]= {0, 15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225, 240, 255}; rom const int y[]= {0, 15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225, 240, 255}; Basically I want something like: Search x(135) a=x postition goto y(a) |
|
#2
|
||||
|
||||
|
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;
}
}
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. |
|
#3
|
||||
|
||||
|
Re: Look Up Tables
Quote:
If you're using these tables for speed control, then use % of the distance traveled (use an encoder) to determine speed. If it's neither, I have no clue. Squirrel |
|
#4
|
|||||
|
|||||
|
Re: Look Up Tables
Quote:
Lookup tables are most easily used as replacements for a simple y=f(x) computation when f() involves lots of multiplication. I don't know what function you're trying to perform with your pair of tables, but what you asked for reduces to a simple f(x) = x. |
|
#5
|
||||
|
||||
|
Re: Look Up Tables
Thanks guys for the help. I know exactly what I am going to do to get what I want accomplished. I speak generally because I am kinda a hermit when it comes to giving away robot secreats.
![]() |
|
#6
|
|||
|
|||
|
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:
|
|
#7
|
||||
|
||||
|
Re: Look Up Tables
The code
Code:
int val = *((&table) + index); Code:
int val=table[index]; This reminds me of an IOCCC entry [hint file] that used index[array] instead of array[index] because the pointer math is in reality the same. |
|
#8
|
|||||
|
|||||
|
Re: Look Up Tables
Quote:
Code:
int val = *(table + index); Code:
int table[]; Code:
int *table; Matt Last edited by Matt Leese : 09-03-2005 at 00:14. Reason: Too much whitespace |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Large Lookup Tables | Mr. Lim | Programming | 5 | 16-02-2004 21:30 |
| New Website | JamesWu | Website Design/Showcase | 56 | 27-12-2003 20:53 |
| Another idea looking for comments | archiver | 1999 | 16 | 23-06-2002 22:01 |