It goes to show how a FIRST team is not one person but a complex codependence of people who are all striving to meet the same goal. - Bill_Hancoc [more]
 Chief Delphi Servo Values to Degrees... How?
 Team 51 CD-Events CD-Media CD-Swap CD-Spy FRC-Spy Unsung FIRST Heroes WFA
The Chief Delphi Forums are sponsored by Innovation First International, Inc.

#1
01-21-2006, 03:39 AM
 mogunus Registered User AKA: Luciano DiFalcone FRC #1350 (Rambots) Team Role: Programmer Join Date: Jan 2006 Rookie Year: 2003 Location: RI Posts: 19
Servo Values to Degrees... How?

I don't know if this is because it's very early (4AM in RI) or if I'm just dense , I can't for the life of me figure out how to convert from the cmucam servo's values to degrees. I know that in terminal.c keven does what's explained by this comment:

// pan angle = ((current pan PWM) - (pan center PWM)) * degrees/pan PWM step
printf(" Pan Angle (degrees) = %d\r\n", (((int)PAN_SERVO - 124) * 65)/124);

To get the pan angle of the camera. I have no idea how this works, or why.

This is a problem for me, because I just finished implementing a feed-forward-ish style tracking algorithm, based on kevin's original code. I got the idea for it from his post here, and there's another great thread about it here.

I'm definately getting better results from the camera. At least, it looks like it's tracking the light better than before at approx 8 ft. distant in my room, have to test that on the 'bot tomorrow.

But the problem is, my code totally broke going from the servo values to degrees in terminal.c. I know that 128 is the "y-axis." So should I just grab a protracter, and "sv 0 whatever" until it looks like there's a 90 degree difference between the position at 128 and the current position, and divide (current - 128)/90 degrees travelled? And would that give me proper degrees/single servo pwm value?

Sorry if that was all really incoherant. Any help would be greatly appreciated.
#2
01-21-2006, 04:39 AM
 Eldarion Electrical Engineer / Computer Geek AKA: Eldarion Telcontar no team (Teamless Orphan) Team Role: Alumni Join Date: Nov 2005 Rookie Year: 2005 Location: Númenor Posts: 558
Re: Servo Values to Degrees... How?

Quote:
 Originally Posted by mogunus I don't know if this is because it's very early (4AM in RI) or if I'm just dense , I can't for the life of me figure out how to convert from the cmucam servo's values to degrees. I know that in terminal.c keven does what's explained by this comment: // pan angle = ((current pan PWM) - (pan center PWM)) * degrees/pan PWM step printf(" Pan Angle (degrees) = %d\r\n", (((int)PAN_SERVO - 124) * 65)/124); To get the pan angle of the camera. I have no idea how this works, or why. This is a problem for me, because I just finished implementing a feed-forward-ish style tracking algorithm, based on kevin's original code. I got the idea for it from his post here, and there's another great thread about it here. I'm definately getting better results from the camera. At least, it looks like it's tracking the light better than before at approx 8 ft. distant in my room, have to test that on the 'bot tomorrow. But the problem is, my code totally broke going from the servo values to degrees in terminal.c. I know that 128 is the "y-axis." So should I just grab a protracter, and "sv 0 whatever" until it looks like there's a 90 degree difference between the position at 128 and the current position, and divide (current - 128)/90 degrees travelled? And would that give me proper degrees/single servo pwm value? Sorry if that was all really incoherant. Any help would be greatly appreciated.
That's all I did, except I just went to 45°

It works great!
__________________
PM me for more information if you are interested (it's open source!).

Want the FIRST Email blasts? See here: http://www.chiefdelphi.com/forums/sh...ad.php?t=50809

"The harder the conflict, the more glorious the triumph. What we obtain too cheaply, we esteem too lightly; it is dearness only that gives everything its value."
-- Thomas Paine

If it's falling apart it's a mechanical problem. If it's spewing smoke it's a electrical problem.
If it's rampaging around destroying things it's a programming problem.

"All technology is run on 'Magic Smoke' contained within the device. As everyone knows, whenever the magic smoke is released, the device ceases to function."
-- Anonymous

I currently speak: English, some German, Verilog, x86 and 8051 Assembler, C, C++, VB, VB.NET, ASP, PHP, HTML, UNIX and SQL
#3
01-21-2006, 10:57 AM
 Kevin Watson La Cañada High School FRC #2429 Team Role: Mentor Join Date: Jan 2002 Rookie Year: 2001 Location: La Cañada, California Posts: 1,309
Re: Servo Values to Degrees... How?

Quote:
 Originally Posted by mogunus I don't know if this is because it's very early (4AM in RI) or if I'm just dense , I can't for the life of me figure out how to convert from the cmucam servo's values to degrees. I know that in terminal.c keven does what's explained by this comment: // pan angle = ((current pan PWM) - (pan center PWM)) * degrees/pan PWM step printf(" Pan Angle (degrees) = %drn", (((int)PAN_SERVO - 124) * 65)/124); To get the pan angle of the camera. I have no idea how this works, or why. This is a problem for me, because I just finished implementing a feed-forward-ish style tracking algorithm, based on kevin's original code. I got the idea for it from his post here, and there's another great thread about it here. I'm definately getting better results from the camera. At least, it looks like it's tracking the light better than before at approx 8 ft. distant in my room, have to test that on the 'bot tomorrow. But the problem is, my code totally broke going from the servo values to degrees in terminal.c. I know that 128 is the "y-axis." So should I just grab a protracter, and "sv 0 whatever" until it looks like there's a 90 degree difference between the position at 128 and the current position, and divide (current - 128)/90 degrees travelled? And would that give me proper degrees/single servo pwm value? Sorry if that was all really incoherant. Any help would be greatly appreciated.
The first part of the equation, PAN_SERVO - 124, converts the PWM to a signed value where positive PWM values are on one side of the zero point(124) and negative PWM values are on the other side. The second part, * 65/124, converts PWM angular units to degrees. I measured a rotation of 65 degrees when I commanded the servo to rotate from 0 to 124 in PWM units, which means for every PWM unit increase, the servo rotates 65/124 degrees. Because I'm using integer arithmetic, I use the parentheses to tell the compiler the order I want the operations to take place to prevent over/underflow of the variable and maximize precision. Consider what would happen if you took the same expression, but put parentheses around the 65/124 expression (answer below).

-Kevin

Answer: 65/124 when evaluated using integer arithmetic is converted to zero, making the entire expression equal to zero no matter what PWM value is plugged in.
__________________
Kevin Watson
Engineer at Space Exploration Technologies (SpaceX)
http://kevin.org

Last edited by Kevin Watson : 01-21-2006 at 03:17 PM. Reason: Spelling error.
#4
01-21-2006, 02:38 PM
 mogunus Registered User AKA: Luciano DiFalcone FRC #1350 (Rambots) Team Role: Programmer Join Date: Jan 2006 Rookie Year: 2003 Location: RI Posts: 19
Re: Servo Values to Degrees... How?

Ah! Thankyou so much. Everything makes sense now.
__________________
... one of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs.
-- Robert Firth
#5
01-22-2006, 06:06 PM
 Ryan O FRC Eclipse Plug-in Developer no team (FRC Eclipse) Team Role: Programmer Join Date: Jan 2006 Rookie Year: 2005 Location: Plaistow Posts: 111
Re: Servo Values to Degrees... How?

If this helps at all, I did the math and if a 127 servo value to parrelle to the floor 1.4111111 "servo points" (Values in programming) equals one degree
#6
01-20-2007, 01:14 PM
 TJ4nier Professional Stress Monger AKA: TJ FRC #2168 (Fitch CyberFalcons) Team Role: Leadership Join Date: Jan 2007 Rookie Year: 2005 Location: Groton, Connecticut Posts: 15
Re: Servo Values to Degrees... How?

I'm not my team's programmer, but I'm trying to help him with some math that we're not sure needs to be done. He hasn't looked at the camera code yet (We are FAR behind, we know), but I was wondering if it was necessary to come up with some sort of relation between camera angle and distance from the light or something like that. We've done some math, but we really don't know what we're doing with it. Since we won't have access to the camera code until this time Monday, I was wondering if you guys could help me out before I fry my brain with all this trigonometry.

Thank you so much.
__________________
Professional Graciousism?
Gracious Professors?
Profess Graciousness?

No. Listen to the "W-Dawg" Flowers!

It's GRACIOUS PROFESSIONALISM.
#7
01-21-2007, 12:18 AM
 Kevin Watson La Cañada High School FRC #2429 Team Role: Mentor Join Date: Jan 2002 Rookie Year: 2001 Location: La Cañada, California Posts: 1,309
Re: Servo Values to Degrees... How?

Quote:
 Originally Posted by TJ4nier I'm not my team's programmer, but I'm trying to help him with some math that we're not sure needs to be done. He hasn't looked at the camera code yet (We are FAR behind, we know), but I was wondering if it was necessary to come up with some sort of relation between camera angle and distance from the light or something like that. We've done some math, but we really don't know what we're doing with it. Since we won't have access to the camera code until this time Monday, I was wondering if you guys could help me out before I fry my brain with all this trigonometry. Thank you so much.
I've added a document to my website that illustrates the relationship between camera tilt angle and range to the green target light. Here's a link: http://kevin.org/frc.

-Kevin
__________________
Kevin Watson
Engineer at Space Exploration Technologies (SpaceX)
http://kevin.org
#8
02-10-2007, 03:16 PM
 paulcd2000 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
Re: Servo Values to Degrees... How?

but how can you convert tilt servo values into degrees. sorry, i'm kinda tired, so i might be being dense

EDIT: Would this work?
Code:
```				angle= (TILT_SERVO-STOP)*0.75757575;
distance = HEIGHT_DIFF/atan(angle);```
.757575... is the degrees per servo step
__________________
"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."

Last edited by paulcd2000 : 02-10-2007 at 03:29 PM. Reason: wait a minute...
#9
02-10-2007, 07:38 PM
 Ianuser Registered User FRC #0570 Join Date: Feb 2007 Location: new york Posts: 64
Re: Servo Values to Degrees... How?

So, wait a minute. I wrote this:
unsigned float Find_Distance(void)
{
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);
}

I read on another thread that the angle has to be in radians for the Tan() function to take in. Also, I put this in Tracking.c. Does it matter where 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 that was stated earlier in this thread (other than I'm looking for tilt rather than pan) Do I have to subtract my pwm07 by 124 like you did in this one? Sorry if I'm being confusing, but I'm trying to understand all of this at once. I also have questions about why my camera doesn't work PERIOD. It's all hooked up but it seems to not be getting power. Anyway, one thing at a time. Please help me if you can! Thanks

Last edited by Ianuser : 02-10-2007 at 07:41 PM.
#10
02-10-2007, 10:15 PM
 gnirts Suspicious pointer conversion AKA: Robinson Levin FRC #1648 (The Gearbox Gangstaz) Team Role: Programmer Join Date: Jan 2006 Rookie Year: 2005 Location: ATL Posts: 116
Re: Servo Values to Degrees... How?

Quote:
 Originally Posted by paulcd2000 but how can you convert tilt servo values into degrees. sorry, i'm kinda tired, so i might be being dense EDIT: Would this work? Code: ``` angle= (TILT_SERVO-STOP)*0.75757575; distance = HEIGHT_DIFF/atan(angle);``` .757575... is the degrees per servo step
I am pretty sure you want tan() and not atan()

Good luck,
Robinson
#11
02-12-2007, 12:32 PM
 jdejoannis Registered User FRC #1845 Join Date: Feb 2006 Location: Atlanta,GA Posts: 48
Re: Servo Values to Degrees... How?

From "The C Library Reference Guide, 1997, Eric Huss" (available online):
2.7.2.9 tan
Declaration:

double tan(double x);

Returns the tangent of a radian angle x.

Range:

There is no range limit on the argument or return value.
In short - yes, the angle is in radians (and it should be a double).
#12
02-12-2007, 08:22 PM
 Ianuser Registered User FRC #0570 Join Date: Feb 2007 Location: new york Posts: 64
Re: Servo Values to Degrees... How?

This is what I have now, I have no idea if it is going to work. Please help if you can.
My tilt_servo is pwm07, my default MAX for tilt is 194, min is 94, center is 144, step is 50. QUESTION: if I change the step to 25, will it automatically make twice as many steps? will it cut the time in half? how is that programmed. ALSO, DOES THIS MAKE ANY 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]);
}```
Those numbers in the array are the distance for each pwm index all the way up to 127 (90 degrees approximately). How does this relate to my 94 min, 194max for my tilt servo? Don't i have to change those to make this work? I'm a little confused. THanks!
#13
02-13-2007, 10:02 AM
 jdejoannis Registered User FRC #1845 Join Date: Feb 2006 Location: Atlanta,GA Posts: 48
Re: Servo Values to Degrees... How?

Thats an interesting idea. Essentially you prefer to tabulate rather than calculate the tangent. In principle, I have no objections. You can choose whatever step size and range you want for the tracking. Those won't affect the range calculation because they are merely properties of the search algorithm (see tracking.c). You will be taking the pwm value after the search is over and the camera is locked on. I am not sure why you are subtracting 67 from the pwm lookup. Shouldn't it be the tilt min 94?

Jason

Last edited by jdejoannis : 02-13-2007 at 10:07 AM.
#14
04-04-2007, 12:48 AM
 #root: Registered User FRC #1622 (Team Spyder) Team Role: Programmer Join Date: Mar 2007 Rookie Year: 2006 Location: Poway, CA Posts: 3
Re: Servo Values to Degrees... How?

Hey, I've been having a problem setting the correct degrees to a variable, even though it prints to the terminal correctly.

pan_angle = (((int)PAN_SERVO - 124) * 65)/124;
tilt_angle = (((int)TILT_SERVO - 144) * 25)/50;

I have tried making these variables ints, floats, and doubles (they are global static declared in user_routines.h, set in terminal.c, and used in user_routines_fast.c). Would it help if I cast pan_angle and tilt_angle as ints or changed 124 to 124.0? Maybe if I did

(int) pan_angle = (int) (((int)PAN_SERVO - 124) * 0.5242);

Any help would be appreciated. Thanks!
#15
04-10-2007, 03:47 AM
 #root: Registered User FRC #1622 (Team Spyder) Team Role: Programmer Join Date: Mar 2007 Rookie Year: 2006 Location: Poway, CA Posts: 3
Re: Servo Values to Degrees... How?

I would appreciate any help, especially if you had problems using the bells and whistles camera code versus the regular one.

Thanks

 Thread Tools Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 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 User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements     User Announcements FIRST     General Forum         FIRST E-Mail Blast Archive     Rumor Mill     Career     Robot Showcase     Moderated Discussion Technical     Technical Discussion     Robotics Education and Curriculum     Motors     Electrical         CAN     Programming         NI LabVIEW         WindRiver C++         Java         MATLAB & Simulink         Python     intelitek easyC/REC information         easyC v2 for Vex         easyC for FRC         REC/Learnmate         WPILib         easyC PRO     Control System         IFI Control System         FRC Control System         Sensors         USB Chicklet     Pneumatics     Kit & Additional Hardware     CAD         Inventor         SolidWorks         Pro ENGINEER / Creo     IT / Communications         3D Animation and Competition         Website Design/Showcase         Videography and Photography         Computer Graphics     National Instruments LabVIEW and Data Acquisition         LabView and Data Acquisition Competition     Awards         Chairman's Award     Rules/Strategy         Scouting         You Make The Call     Team Organization         Fundraising         Starting New Teams         Finding A Team         College Teams     Championship Event     Regional Competitions     FIRST in Michigan     Mid-Atlantic Robotics     Off-Season Events         Chief Delphi Invitational     Thanks and/or Congrats     FRC Game Design     OCCRA         OCCRA Q&A         OCCRA Programming Other     Unsung FIRST Heroes     Chit-Chat         Games/Trivia             Fantasy FIRST     Car Nack's Corner     College & University Education     Dean Kamen's Inventions     FIRST-related Organizations         Western Region Robotics Forum         Robot Chicks Union (RCU)         Southern California Regional Robotics Forum         Hearing-Impared Network         FIRST Interactive Rural SupporT         freelanceFIRST         FIRST Scouting Network         openFIRST         The Grand FIRST Team         FloridaFIRST         Inspiration Foundation Inc.         South Dakota FIRST         FIRST International Partners         FIRSTwiki         Ultimate Robot Challenge         East Coast Drivers Union         Team San Diego         CollegiateFIRST         Dream FIRST         FIRST Brasil         The Blue Alliance             Video Archives     FIRST Historians     FIRST-A-Holic's Anonymous Mailbox     FIRST In the News...     FIRST Lego League         Lego Mindstorm Discussion     FIRST Tech Challenge         FTC E-Mail Blast Archive     VEX         VEX Robotics Competition     Televised Robotics     Math and Science         NASA Discussion ChiefDelphi.com Website     CD Forum Support         Bulletins and Newsletters     Extra Discussion Old Forum Archives     1999     2000     2001

 Similar Threads Thread Thread Starter Forum Replies Last Post Servo behavior question / advanced servo/PIC programming question DanL Electrical 12 10-18-2005 05:33 PM Servo Compact Design Problems!!! Dominator_Legen Electrical 22 04-07-2005 05:15 PM Servo Values DanDon Motors 8 02-14-2005 02:49 PM Dashboard View of Pan and Tilt Servo Values JoeXIII'007 Programming 1 02-02-2005 09:34 PM

All times are GMT -5. The time now is 05:51 PM.

The Chief Delphi Forums are sponsored by Innovation First, Inc.

 -- English (12 hour) -- English (24 hour) Contact Us - Chief Delphi - Rules - Team Site - Archive - Top