View Single Post
  #2   Spotlight this post!  
Unread 11-02-2007, 16:54
Salik Syed Salik Syed is offline
Registered User
FRC #0701 (RoboVikes)
Team Role: Alumni
 
Join Date: Jan 2003
Rookie Year: 2001
Location: Stanford CA.
Posts: 514
Salik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud of
Send a message via AIM to Salik Syed
Re: Value of degree to calculate range?

I think it would be more efficient to just create a lookup table which maps PWM values to Range Values, you can do all the pre-calculations in Excel or something.

just create a static const array, it will be stored in read only memory so you don't have to worry too much about the size of the array
Code:
static const int lookup = { 1,2,3....4};
where 1,2,3,4 are your range values

now say you only have a pwm range from 90-150 (61 different values)
lookup[60] would be the range value for pwm 150, so for the look up function you could do something like this:
Code:
int getRange(int pwm)
{
    if(pwm<90) {println("ERROR : unexpected lookup value!"); return -1;}
    return lookup[pwm-90];
}
I'd advise against using a double or a float for storing range in an array
because you really don't need
that much precision (if the range is in inches) and it would just be a waste of memory
__________________
Team 701

Last edited by Salik Syed : 11-02-2007 at 17:02.