View Single Post
  #10   Spotlight this post!  
Unread 13-02-2007, 20:56
Ianuser Ianuser is offline
Registered User
FRC #0570
 
Join Date: Feb 2007
Location: new york
Posts: 64
Ianuser is an unknown quantity at this point
Re: Value of degree to calculate range?

OHHH I get it now. I got 67 from this: it takes ...wait a minute...i have no idea where I got 67 form now that I think about it. When I did it, it made sense. But now that I know how to do it (and it makes A LOT of sense now) I can't think of how to do it incorrectly in order to figure out where I got 67 from. If I think of it I'll certainly let you know.
Here's what I have now:

this segment of code is in User_Routines.c at the top before the functions (at the variable declarations):
Code:
const rom unsigned int targetRange[] =
	{
    USHRT_MAX,  // zero index is undefined
53, //0
51,
50,
49,
47,
46,
45,
44,
42,
41,
40, //10
39,
38, 
37,
35,
34,
33,
32,
31,
30,
29, //20
28, 
27,
26,
25,
24,
23,
22,
21,
20,
19, //30
18, 
17,
16,
15,
14,
13,
12,
11,
10,
10, //40
9, 
8,
7,
6,
5,
4,
3,
2,
1,
0,
};
Then I have this at the very bottom of user_routines.c:

Code:
unsigned int Find_Distance(void)
{	
	return(targetRange[pwm07-144]);
}
Finally, also in User_Routines.c in Process_Data_From_Master_uP() I have this:
Code:
if(Get_Camera_State() == 1)
	{
		if(((Get_Tracking_State() == CAMERA_ON_TARGET) || (Get_Tracking_State() == TARGET_IN_VIEW)) && (Find_Distance() > 20))
		{
			pwm01 = 150; //Desired Forward Velocity
			pwm02 = 150;
			Switch3_LED = 1;
		}
		else if(((Get_Tracking_State() == CAMERA_ON_TARGET) || (Get_Tracking_State() == TARGET_IN_VIEW)) && (Find_Distance() <= 20))
		{
			pwm01 = 127;
			pwm02 = 127;
			I_Want_To_Search = 0; //Stops calling Servo_Track().
			Switch3_LED = 0;
		}
		else
		{
			Switch3_LED = 0;
		}
	}
When I tried this with the robot, it didn't work. The pwm values did not change when the camera was locked onto the green light.
Any suggestions? And is the previous code for calculating the range sufficient?