View Single Post
  #15   Spotlight this post!  
Unread 14-02-2007, 10:37
charrisTTI charrisTTI is offline
Ramblin' Wreck
AKA: Charles Harris
FRC #0623
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2003
Location: Vienna, VA
Posts: 106
charrisTTI has a spectacular aura aboutcharrisTTI has a spectacular aura about
Send a message via AIM to charrisTTI
Re: Value of degree to calculate range?

Table should have as many entries as you have pwm values to go from 0 to 90 degrees. Change the spread sheet to reflect your configuration. Camera height, degrees per pwm step, number of steps required to go from 0 to 90.

Then subtract your minimum pwm value from the current pwm value to get your index into the table.

Here is an example with some additional "bullet proofing":

#define MIN_TILT_PWM 144



unsigned int Find_Distance(void)
{
unsigned int returnValue;
// using int here because value could go negative
int distanceIndex = (int)pwm07 - (int)MIN_TILT_PWM;

// check to make sure we have a value that is in range

// are we too small
if( distanceIndex < 0 )
{
returnValue = USHRT_MAX;
}
// are we too big
// note: sizeof an array divided by size of the first element gives size of the array
// array indexing is zero based so a 50 element array is accessed using index values from 0 to 49
else if( distanceIndex >= sizeof(targetRange)/sizeof(targetRange[0]) )
{
returnValue = 0;
}
// we are just right
else
{
// go to the table to get our range value
returnValue = targetRange[ distanceIndex ];
}

return returnValue;
}
__________________
FRC 623 2003,2004,2005,2006,2007,2008, 2009, 2010, 2011
FRC 1900 2007
FVC 60 and 193 2006
FVC 3271 2007
FTC 226 and 369 2008, 2009, 2010, 2011
FTC 3806 2010