Go to Post I told myself I'd stay out of the obsession this year, but I couldn't resist... - Grant Cox [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 28-02-2005, 18:08
amateurrobotguy's Avatar
amateurrobotguy amateurrobotguy is offline
Lead Programmer/Senior Engineer
no team
 
Join Date: Feb 2005
Rookie Year: 2000
Location: ****
Posts: 136
amateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these parts
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)
__________________
I quit FRC over 2 years ago (more if you're reading this past 2010).
  #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...
  #3   Spotlight this post!  
Unread 01-03-2005, 12:02
Squirrelrock's Avatar
Squirrelrock Squirrelrock is offline
I may be teh programmer?
AKA: Keegan
FRC #0414
Team Role: Programmer
 
Join Date: Nov 2004
Rookie Year: 2003
Location: Richmond VA
Posts: 333
Squirrelrock will become famous soon enoughSquirrelrock will become famous soon enough
Send a message via AIM to Squirrelrock
Re: Look Up Tables

Quote:
Originally Posted by amateurrobotguy
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)
If you're trying to have a table for autonomous points to drive to or some such nonsense, make a separate program to handle the tables on another computer that then inputs those cooridinates to the OI to send to the RC to drive to. (Contact Scitobor 617 for details on this program he's writing.)

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
__________________
Look what I did to Dave:
Aaacckkk! Guurrkkk! Sssnorrrrkkkkk! Brain ... explode ... will. AAAArrrrggghhh!! Must ... not ... think ... about ... 2007 ... yet. Uuurrgghh!!! Still ... have .... to ... resolve ... how ... to ... pack ... parachutes ... for ... 2006 ... Ooorrrkkggnn!!
Sweet!

The scientists of today think deeply instead of clearly. One must be sane to think clearly, but one can think deeply and be quite insane.
- Nikola Tesla

Genius might be described as a supreme capacity for getting its possessors into trouble of all kinds.
- Samuel Butler
  #4   Spotlight this post!  
Unread 01-03-2005, 13:09
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Look Up Tables

Quote:
Originally Posted by amateurrobotguy
...Like on table 1 find this number. Then from that number, goto table 2 with the same row and find that number.

Code:
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)
Your example is probably poorly chosen to indicate what you want. The x and y arrays are identical, so whatever you put in as your search is what you get out as the result.

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   Spotlight this post!  
Unread 01-03-2005, 17:19
amateurrobotguy's Avatar
amateurrobotguy amateurrobotguy is offline
Lead Programmer/Senior Engineer
no team
 
Join Date: Feb 2005
Rookie Year: 2000
Location: ****
Posts: 136
amateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these parts
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.
__________________
I quit FRC over 2 years ago (more if you're reading this past 2010).
  #6   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.
  #7   Spotlight this post!  
Unread 09-03-2005, 00:08
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

The code
Code:
int val = *((&table) + index);
is equivalent to
Code:
int val=table[index];
In fact, I think they compile down to the same code at the end.

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.
__________________
-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...
  #8   Spotlight this post!  
Unread 09-03-2005, 00:14
Unsung FIRST Hero
Matt Leese Matt Leese is offline
Been-In-FIRST-Too-Long
FRC #1438 (The Aztechs)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1998
Location: Long Beach, CA
Posts: 937
Matt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond repute
Send a message via AIM to Matt Leese
Re: Look Up Tables

Quote:
Originally Posted by ace123
The code
Code:
int val = *((&table) + index);
is equivalent to
Code:
int val=table[index];
In fact, I think they compile down to the same code at the end.
Technically, that should be
Code:
int val = *(table + index);
because table is a pointer by default. Writing
Code:
int table[];
is just short hand for
Code:
int *table;
Sorry for being pedantic but in programming it can be important.

Matt

Last edited by Matt Leese : 09-03-2005 at 00:14. Reason: Too much whitespace
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
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


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

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