Go to Post There are no guarentees in life. Cherish what you have while you have it. None of us knows what tomorrow will bring. - KenWittlief [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 11-02-2007, 13: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
Value of degree to calculate range?

Hi everyone. I'm not sure if what I'm doing to get the degree for the tilt_servo to find the range of the bot to the rack is correct.
I wrote this in tracking.c at the very bottom:

Code:
unsigned float Find_Distance(void)
{
   float radian;
   float range;
   radian = ((((angle I will measure in degrees that the tilt servo has to offer from down to up) / 256) * pi) / 180) * pwm07(which is my tilt_servo pwm);
   range = (116 - (distance I have yet to measure between the floor and my camera because we haven't placed it yet)) / tan(radian);
   return(range);
}
I read on another thread that the angle has to be in radians for the Tan() function to take in. Also, does it matter in which source file I place this function? SO, my real questions are, Does anything about what I wrote make sense? And how does this compare to the:
pan angle = ((current pan PWM) - (pan center PWM)) * degrees/pan PWM step ?(other than I'm looking for tilt rather than pan). Do I have to subtract my pwm07 by something like you did in this one? Sorry if I'm being confusing, but I'm trying to understand all of this at once. (My team is made up of 5 people and I'm the only electrician and the only programmer and I don't have much experience as a junior in high school.)
  #2   Spotlight this post!  
Unread 11-02-2007, 14:34
paulcd2000's Avatar
paulcd2000 paulcd2000 is offline
Accidentally speaks in C
AKA: Paul Dagnelie
FRC #1719 (The Umbrella Corp.)
Team Role: Programmer
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Baltimore
Posts: 368
paulcd2000 is a jewel in the roughpaulcd2000 is a jewel in the roughpaulcd2000 is a jewel in the rough
Send a message via AIM to paulcd2000
Re: Value of degree to calculate range?

i dunno where you learned that you need radians... i use degrees. if you look in tracking.H, you'll see the upper and lower servo limits are (i think) 160 and 94. It also says that that's approximately +25 deg and -25 deg. so degrees per servo step is 25/33. then, you need to find the number of servo steps either up or down. i did something like:
Code:
unsigned float Find_Distance(void)
{
     double angle;
     double range;
     angle = (TILT_SERVO-127)*.757575;
     range = HEIGHT_DIFF /*that's 116- camera height*/ /atan(angle);
     return(range)
}
make sure to double check, but this should do it...
__________________
"People don't say 'It's just a game' when their team is winning!" -- Scott Adams

5.5 students (on average)* $7/h *210 hours/student= $8085 of labor, all volunteered (not counting mentors', who are each that much)

We have blades on our robot?! ***sweeeeeet***

There are 11 types of people in the world. Those who can read binary, those who can't, and those who say this joke is supposed to be, "There are 10 types of people in the world. Those who can read binary and those who have a life."
  #3   Spotlight this post!  
Unread 11-02-2007, 15:54
Bomberofdoom's Avatar
Bomberofdoom Bomberofdoom is offline
Biggest FIRST addict in Israel
AKA: Nir Levanon
FRC #2230 (Zcharia's Angels)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Israel
Posts: 471
Bomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond repute
Send a message via MSN to Bomberofdoom
Re: Value of degree to calculate range?

I wrote like Kevin's suggestion:
Code:
float range_to_target(void)
{
	float range; 
	range = HIGHT_OF_CAMERA - HIGHT_OF_TARGET/tan(TILT_ANGLE);//
	return(range);
}
  #4   Spotlight this post!  
Unread 11-02-2007, 16:00
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?

We are looking for the Tilt_AngleMy tracking.H file says that the tilt min is 94 and the tilt max is 194. So, the center of that would then be 144, right? (It also says that Tilt_Center_Pwm_Default is 144). So, shouldn't the equation then be:

unsigned float Find_Distance(void)
{
float angle;
float range;
angle = (TILT_SERVO-144)*.757575;
range = HEIGHT_DIFF /*that's 116- camera height*/ /tan(angle);
return(range)
}

also, where did you get 25/33 from? where'd the 33 come from? Also, what does this mean?
Code:
#define TILT_SEARCH_STEP_SIZE_DEFAULT 50
wouldn't that mean that each step is 50, not 25? (And also its tan(angle), right? not atan(angle)...
  #5   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.
  #6   Spotlight this post!  
Unread 11-02-2007, 18:46
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?

I dont understand whats wrong with what I did. I'm not using an arraylist or anything of that sort. I just want to know, for the pwm value at which the tiltservo is at NOW, what is its angle? thereafter, what is the range from the bot to the rack?
  #7   Spotlight this post!  
Unread 11-02-2007, 22:38
fallen751 fallen751 is offline
Registered User
FRC #2052
 
Join Date: Jan 2007
Location: Minnesota
Posts: 17
fallen751 is an unknown quantity at this point
Re: Value of degree to calculate range?

the <math.h> header has a tan() function in it. And in the standard header file the function accepts radians as an input. I have it coded this way, and it works reliably for me. The best thing you can do is to set the camera to its centers and then recenter the servos so you know for sure where the center values are.
  #8   Spotlight this post!  
Unread 11-02-2007, 22:46
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,112
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: Value of degree to calculate range?

Quote:
Originally Posted by Ianuser View Post
I dont understand whats wrong with what I did. I'm not using an arraylist or anything of that sort. I just want to know, for the pwm value at which the tiltservo is at NOW, what is its angle? thereafter, what is the range from the bot to the rack?
There's nothing wrong with what you did. Salik was just suggesting another way of doing it -- one which has a couple of very good features, by the way. It lets you turn a tilt servo value directly into a range value just by reading from an array, without doing any time-consuming calculations in the program. It lets you compensate for any nonlinearities in the system, such as vertical parallax from the motion of the camera lens or a changing centroid bias when the size of the target images changes, by giving you a way to manually tweak values for each angle. And it lets you fill in the array without doing any trigonometry at all if you want to, by placing the robot on the field and actually measuring the distance associated with each tilt servo value.
  #9   Spotlight this post!  
Unread 12-02-2007, 00:05
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?

How might I go about doing that then. I see now the advantages of it, but I am a first year programmer and I actually just learned what an array is last week in school. Any hints on how to set that up in the code would be extremely helpful and appreciated!
  #10   Spotlight this post!  
Unread 12-02-2007, 03:43
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?

First off, the way you learn arrays in java probably is at a much higher level (you probably learn about Vectors/ArrayLists and other top level containers)

For robots we are dealing with simple arrays,
So like I mentioned above all you need to do is simply calculate your PWM->Tilt Conversion table (in Excel or manually)

If you want to do it manually you could printf the TILT_ANGLE , then measure how far your robot is from the light.
Collect a few key data points (20-30) then interpolate between them.

Then just create an array which has each range value in it.
__________________
Team 701
  #11   Spotlight this post!  
Unread 12-02-2007, 06:37
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,112
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: Value of degree to calculate range?

Quote:
Originally Posted by Ianuser View Post
Any hints on how to set that up in the code would be extremely helpful and appreciated!
Salik's first post has examples you can follow.
  #12   Spotlight this post!  
Unread 12-02-2007, 10:58
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?

First to clarify: Math functions in the C library work with radians, not degrees.

Here is excerpt from MPLAB C18 libraries manual:

tan
Function: Compute the tangent.
Include: math.h
Prototype: float tan( float x );
Remarks: Computes the tangent of x (in radians). A domain error occurs if the
argument is infinite or NaN. Both cases return NaN.
Return Value: The tangent of x.
File Name: tan.c


Attached is spread sheet for calculating a look-up table. Copy and paste the data from the Range Text column to create your array. See rangelu.c for example of completed array.

When you need to use the array declare as extern in that file.

extern const rom unsigned short targetRange[];


If you use Kevin's changes to increase resolution on the tilt axis. The number of table entries will need to increase and the PWM TO DEGREES factor will need to be changed.
Attached Files
File Type: xls TargetRange.xls (37.0 KB, 30 views)
File Type: c rangelu.c (857 Bytes, 33 views)
__________________
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
  #13   Spotlight this post!  
Unread 12-02-2007, 17:17
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?

So this is what I have so far. My pwmTILT is pwm07. My default center Tilt is 144 because the min is 94 and the max is 194. Also, the tilt_serach_step default is 50, so it makes 3 stops for tilt. Here is my code now, does this make sense?
Code:
const rom unsigned short targetRange[] =
{
    USHRT_MAX,  // zero index is undefined
5519,
2759,
1839,
1102,
918,
787,
688,
611,
549,
499,
457,
421,
390,
364,
340,
320,
302,
285,
270,
257,
234,
223,
214,
205,
197,
189,
182,
176,
169,
163,
158,
153,
148,
143,
139,
134,
130,
127,
123,
119,
116,
110,
107,
104,
101,
99,
96,
94,
91,
89,
87,
85,
82,
80,
78,
76,
75,
73,
71,
69,
68,
66,
64,
63,
61,
60,
58,
57,
55,
54,
53,
51,
50,
49,
48,
46,
45,
44,
43,
42,
40,
39,
38,
37,
36,
35,
34,
33,
32,
31,
30,
29,
28,
27,
26,
25,
24,
23,
22,
21,
20,
19,
18,
18,
17,
16,
15,
14,
13,
12,
11,
11,
10,
9,
8,
7,
6,
5,
5,
4,
3,
2,
1,
0
};

unsigned int Find_Distance(void)
{
	return(targetRange[pwm07-67]);
}
I subtracted the pwm07 by 67 because there is a 67 difference between the max_pwm (194) and the number of items in the array, so that means if the pwm is going at 194, then return the 127th item which is 0. So, does that make sense? Did I miss something or make wrong calculations?

(ALSO, my camera does not function properly. It turns on, everything is dandy, but it does not track the light well. It has only locked onto the light once out of many tries. The camera will often face quite to the left of the actual light and then it will go up and down in short steps very fast. Any suggestions?)
  #14   Spotlight this post!  
Unread 12-02-2007, 21:41
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?

I actually just realized that I have to change the numbers in the array because I have to recalculate the height of my camera, so the numbers will be a little different. Lets say I'm working with this, though. What I'm worried about is this:
Code:
unsigned int Find_Distance(void)
{
	return(targetRange[pwm07-67]);
}
Is it right to subtract 67 from the pwm value? What should I be doing in order to translate the one index number out of 127 pwm indexes, or 90 degrees, into the range that I should have? Thanks
  #15   Spotlight this post!  
Unread 13-02-2007, 17:11
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?

ahh no ones responding and im still confused!

Sorry to be a bother, but we're stuck here. Thanks
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 19:11.

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