Go to Post Sometimes students ask me if MIT wants students who are well-rounded. I usually say I don't care as much if you're well-rounded or pointy, what I care about is evaluating the space enclosed by the shape. - Petey [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
  #16   Spotlight this post!  
Unread 13-02-2007, 18:57
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?

So you should have
EXACTLY as many array values as the number of different PWM values your camera would possibly output.
I would put some bound checking too... because you will crash the program if you give it a bad index value!

You said that your tilt center is 144, and that tilt_max is 194. I'm assuming the robot won't get tall enough tilt the camera down past the center. Is this correct?

Thus your array should contain 51
entries. 194-144 + 1 =51 ... add 1 since the set is inclusive on both sides

So we want a value of 144 to point to array[0] and 194 to point to array[50] so all you need to do is subtract 144 from the PWM value



I'm not sure how you got 67 entries? can you explain.
__________________
Team 701

Last edited by Salik Syed : 13-02-2007 at 19:00.
  #17   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?
  #18   Spotlight this post!  
Unread 14-02-2007, 03:11
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?

Can you try using a different variable ...are you sure pwm07 isn't being overwritten to some other garbage value?
Try println what range outputs.

Is this always true?:
Get_Camera_State() == 1

I am almost certain it is a problem with one of those things, because your table looks perfect.
__________________
Team 701
  #19   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
  #20   Spotlight this post!  
Unread 14-02-2007, 11:27
jdejoannis jdejoannis is offline
Registered User
FRC #1845
 
Join Date: Feb 2006
Location: Atlanta,GA
Posts: 48
jdejoannis will become famous soon enoughjdejoannis will become famous soon enough
Re: Value of degree to calculate range?

Try a simpler version first. Maybe something that just drives forward if the light is in view and stops the motors otherwise. That will help you debug.

What's the purpose of USHRT_MAX? Don't fight with the C arrays, just start from zero. Your code expects a value for targetRange[0] when pwm07 is at its minimum of 144.

Jason
  #21   Spotlight this post!  
Unread 14-02-2007, 15:34
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?

Ok, so I should take out USHRT_MAX.

Also, the purpose of the code I wrote IS to move forward if the camera see's the target, but I guess I could take out the RANGE part for now for debugging. Thanks

Also, I think you are right about Get_Camera_State() == 1 always. before I was trying to make abutton that stopped the camera from tracking and started it to track by calling Camera_Idle() and Restart_Camera() but I changed that so I stopped calling or started calling Servo_Track(), so Get_Camera_State() no longer is changed. Thanks for pointing that out.
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
How to calculate arm angles? SoD Programming 5 31-01-2007 14:17
White Paper Discuss: Spreedsheet to Calculate the Ranking of Teams Joe Johnson Extra Discussion 27 29-03-2005 11:16
How to calculate planetary gear ratios? sanddrag Technical Discussion 2 27-02-2005 11:55
How do you Calculate Belt Length? Gabriel Technical Discussion 7 08-11-2004 14:54
Microbiology Degree? Jillian B. Chit-Chat 1 26-09-2003 20:19


All times are GMT -5. The time now is 06:16.

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