Go to Post When the going gets tough, the smart keep their GP. - Libby K [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 10-04-2004, 18:41
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Question Angle from X,Y

How do you find the angle from (X, Y)?

And how do you optimize this for realtime on the FRC?

And One Of Astronouth's Rare Contensts: Why would I care?
  #2   Spotlight this post!  
Unread 10-04-2004, 18:45
Yan Wang's Avatar
Yan Wang Yan Wang is offline
Ithaca is Gorges
AKA: John Wayne
FRC #0639 (Code Red Robotics)
Team Role: Alumni
 
Join Date: Sep 2002
Rookie Year: 2001
Location: Cambridge, MA
Posts: 1,910
Yan Wang has much to be proud ofYan Wang has much to be proud ofYan Wang has much to be proud ofYan Wang has much to be proud ofYan Wang has much to be proud ofYan Wang has much to be proud ofYan Wang has much to be proud ofYan Wang has much to be proud ofYan Wang has much to be proud of
Send a message via ICQ to Yan Wang Send a message via AIM to Yan Wang Send a message via MSN to Yan Wang Send a message via Yahoo to Yan Wang
Re: Angle from X,Y

Angle from (x,y) (I'm assuming on a normal Cartesian Plane) to what in relation to what as a vertex?

ie. angle between (x,y) and x-axis with origin as vertex.
__________________
Code Red Robotics Team 639 Alumnus | www.team639.org
<Patrician|Away> what does your robot do, sam
<bovril> it collects data about the surrounding environment, then discards it and drives into walls
  #3   Spotlight this post!  
Unread 10-04-2004, 18:47
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Re: Angle from X,Y

The angle between (0,0) and (x,y) in relation to the x axis (A horizantal line, y=0)
  #4   Spotlight this post!  
Unread 10-04-2004, 19:04
FotoPlasma FotoPlasma is offline
\: |
no team
 
Join Date: Jul 2001
Rookie Year: 2001
Location: San Jose
Posts: 1,900
FotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond repute
Send a message via AIM to FotoPlasma
Re: Angle from X,Y

The inverse tangent function (arctan) will give you the angle from the origin to a point. For example: given (x,y), arctan(y/x) = the angle from the origin to the point (x,y).

If you search CD for something like "arctan" or "trig" or "trigonometry", you should get a fair amount of results already covering implementation of trigonometric functions on the FRC controller.

I don't have any experience using these, myself, but I've heard that a few teams have had success with using an arbitrary degree Taylor series approximation of trig functions.
__________________
I played hacky sack with Andy Baker.

2001-2004: Team 258, The Sea Dawgs
2005: Team 1693, The Robo Lobos
  #5   Spotlight this post!  
Unread 10-04-2004, 20:28
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Re: Angle from X,Y

Doesn't arc tangent return an angle for a given slope? As in: -90 to 90.
I'm talking about 360 degrees. Like a Rectangular to Polar converter thing.
  #6   Spotlight this post!  
Unread 10-04-2004, 20:40
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,572
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Angle from X,Y

Quote:
Originally Posted by Astronouth7303
Doesn't arc tangent return an angle for a given slope? As in: -90 to 90.
I'm talking about 360 degrees. Like a Rectangular to Polar converter thing.
You then look at the signs of X and Y to see if what quadrant the angle is in.
  #7   Spotlight this post!  
Unread 10-04-2004, 20:58
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Red face Re: Angle from X,Y

:WHAP: Duh
Code:
unsigned int GetAngle(signed int X, signed int Y)
{
   signed int Angle = arctan(Y/abs(X));
 unsigned char OtherSide = IsNegetive(X);
 unsigned int Value = 0;
 
 if (OtherSide)
  Value = 180 - Angle + 360;
 else
  Value = Angle + 360;
 
 Value %= 360;
 return Value;
}
Unfortunately, you have to use a float for Angle because angles between -45 and 45 are as important as the others. I suppose I could flip X and Y around for that.

[Changed that tan to arctan]

Last edited by Astronouth7303 : 10-04-2004 at 21:01. Reason: Big boo-boo
  #8   Spotlight this post!  
Unread 10-04-2004, 22:23
michael_obrien's Avatar
michael_obrien michael_obrien is offline
Registered User
#0972 (LGHS Robotics)
Team Role: Student
 
Join Date: Sep 2003
Location: Los Gatos, CA
Posts: 17
michael_obrien is on a distinguished road
Re: Angle from X,Y

I don't know much about programming, but I screwed around with winamp AVS for a while, and on that there was a function known as "atan2(x,y)" which was the same as atan but it automatically corrected for quadrants... isn't there anything simular in C? I mean, C is much more powerful than that AVS junk from what I understand, it should at least have the same capabilities.
__________________

Michael O'Brien
Student
Los Gatos High School team #972
  #9   Spotlight this post!  
Unread 10-04-2004, 22:51
The Lucas's Avatar
The Lucas The Lucas is offline
CaMOElot, it is a silly place
AKA: My First Name is really "The" (or Brian)
FRC #0365 (The Miracle Workerz); FRC#1495 (AGR); FRC#4342 (Demon)
Team Role: Mentor
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Dela-Where?
Posts: 1,564
The Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond repute
Send a message via AIM to The Lucas
Re: Angle from X,Y

Quote:
Originally Posted by Astronouth7303
:WHAP: Duh

Unfortunately, you have to use a float for Angle because angles between -45 and 45 are as important as the others. I suppose I could flip X and Y around for that.

[Changed that tan to arctan]
You don't need a float to represent (Y/X). Just try ((Y*100)/X) and scale your arctangent function to reflect this. This works well if you are using a lookup table. However, I would use a float if I was using a McLaurin series. Otherwise you are likely to overload a long the when you start getting into the higher powers (100^5 is way too big). Also you might want to check to make sure X is not zero before dividing by it.

Quote:
Originally Posted by michael_obrien
I don't know much about programming, but I screwed around with winamp AVS for a while, and on that there was a function known as "atan2(x,y)" which was the same as atan but it automatically corrected for quadrants... isn't there anything simular in C? I mean, C is much more powerful than that AVS junk from what I understand, it should at least have the same capabilities.
IFI doen not provide us with libraries of functions like this, but C certainly has them. The standard atan function requires more prcessing and floating point math than most FIRST programmers want to put in thier RC
__________________
Electrical & Programming Mentor ---Team #365 "The Miracle Workerz"
Programming Mentor ---Team #4342 "Demon Robotics"
Founding Mentor --- Team #1495 Avon Grove High School
2007 CMP Chairman's Award - Thanks to all MOE members (and others) past and present who made it a reality.
Robot Inspector
"I don't think I'm ever more ''aware'' than I am right after I burn my thumb with a soldering iron"

Last edited by The Lucas : 10-04-2004 at 23:05.
  #10   Spotlight this post!  
Unread 12-04-2004, 16:29
Matt Reiland's Avatar
Matt Reiland Matt Reiland is offline
'The' drive behind the drive
None #0226 (TEC CReW Hammerheads)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1999
Location: Troy Michigan
Posts: 712
Matt Reiland has a reputation beyond reputeMatt Reiland has a reputation beyond reputeMatt Reiland has a reputation beyond reputeMatt Reiland has a reputation beyond reputeMatt Reiland has a reputation beyond reputeMatt Reiland has a reputation beyond reputeMatt Reiland has a reputation beyond reputeMatt Reiland has a reputation beyond reputeMatt Reiland has a reputation beyond reputeMatt Reiland has a reputation beyond reputeMatt Reiland has a reputation beyond repute
Re: Angle from X,Y

This is the formula that LeoM posted a while back to get the angle from rectangular coordinates. Worked extremely well back in 2002

Temp1 was the positive distance in X direction
Temp2 was the positive distance in Y direction
temp3 = (temp2*127) / SQR((temp1*temp1)+(temp2*temp2)) 'Make values on a 127 unit circle

ss_degrees = ((1-(temp3/118))*(((temp3+181)*temp3+744)/769))+((temp3/118)*(((((3*temp3-707)*temp3+42611)/20))+((temp3-115)/3)))

ss_degrees = (ss_degrees*180)/128 'Convert to Degrees
__________________
Robonaut Next Generation Control System Development

2003 GLR Champions (302,67,226)
2003 Buckeye Semi-Finalists(902,494,226)
2002 Nationals QuarterFinalists
2001 West MI QuarterFinalists
2000 GLR Semi-Finalists
  #11   Spotlight this post!  
Unread 13-04-2004, 07:33
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Re: Angle from X,Y

Ay. The problem is I don't get what it's doing.
  #12   Spotlight this post!  
Unread 13-04-2004, 07:34
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Re: Angle from X,Y

My current code is like this:
Code:
#define abs(Num) ( ((Num) < 0) ? (0 - (Num)) : (Num) )
#define IsNegetive(Num) ( ((Num) < 0) ? 255 : 0 )
#define IsPositive(Num) ( ((Num) > 0) ? 255 : 0 )



/* 360 degrees = 256
  0 =   0 (0x00)
 45 =  32 (0x20)
 90 =  64 (0x40)
135 =  96 (0x60)
180 = 128 (0x80)
225 = 160 (0xA0)
270 = 192 (0xC0)
315 = 224 (0xE0) */

unsigned char GetAngle(signed char X, signed char Y)
{
   signed int  Angle = 0;
 unsigned char OtherSide = (X < 0) ? 255 : 0;
 unsigned char Value = 0;
 unsigned char Simple = (X == 0) | (Y == 0) | (X == Y);
 
 //Perform Simple tests
 if (Simple)
 {
  if (X == 0)
   if (Y < 0)
    Angle = 192; // Down
   else if (Y > 0)
    Angle = 64; //Up
   else // Y == 0
    Angle = 0; //None, default
  
  if (Y == 0)
   if (X < 0)
    Angle = 128; // Left
   else if (X > 0)
    Angle = 0; //Right
   else // X == 0
    Angle = 0; //None, default
  
  if (X == Y)
  {
   switch( (IsNegetive(X) & 2) | (IsNegetive(Y) & 1) )
   {
    case 0: //++
     Angle = 32;
     break;
    case 2: //-+
     Angle = 96;
     break;
    case 3: //--
     Angle = 160;
     break;
    case 1: //+-
     Angle = 224;
     break;
   }
  }
 }

 //Again for goto, no braces
 if (Simple) goto Done; //I hope that's right
 
 if (X > Y) //Preserve accuracy
  Angle = 64 - atan(abs(X)/Y);
 else
  Angle = atan(abs(X)/Y);
 
 Angle = OtherSide ? (127 - Angle) : Angle;
 Value = (unsigned char)((Angle + 255) % 255);
 
Done:
 return Value;
}
Nobody's answered the last question!
  #13   Spotlight this post!  
Unread 13-04-2004, 13:35
Greg Ross's Avatar
Greg Ross Greg Ross is offline
Grammar Curmudgeon
AKA: gwross
FRC #0330 (Beach 'Bots)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Hermosa Beach, CA
Posts: 2,245
Greg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond repute
Send a message via AIM to Greg Ross Send a message via Yahoo to Greg Ross
Re: Angle from X,Y

Quote:
Originally Posted by Astronouth7303
Nobody's answered the last question! [regarding optimization]
Jamie,

The best advice I've ever heard about optimization is "Don't -- until you need to." You generally want to get your code working, and only then worry about optimizing -- if necessary.
__________________
Greg Ross (The Grammar Curmudgeon formerly known as gwross)
S/W Engineer, Team 330, the Beach 'Bots
<--The Grammar Curmudgeon loves this cartoon.
“Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" Hunter S. Thompson
"Playing a practical joke means doing something mean and calling it funny." Me
  #14   Spotlight this post!  
Unread 13-04-2004, 21:22
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Re: Angle from X,Y

I was refeing to post 1:
Quote:
Originally Posted by Astronouth7303
And One Of Astronouth's Rare Contensts: Why would I care?
  #15   Spotlight this post!  
Unread 13-04-2004, 21:56
Greg Ross's Avatar
Greg Ross Greg Ross is offline
Grammar Curmudgeon
AKA: gwross
FRC #0330 (Beach 'Bots)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Hermosa Beach, CA
Posts: 2,245
Greg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond repute
Send a message via AIM to Greg Ross Send a message via Yahoo to Greg Ross
Re: Angle from X,Y

Quote:
Originally Posted by Astronouth7303
Quote:
Originally Posted by Astronouth7303
And One Of Astronouth's Rare Contensts: Why would I care?
I was refeing to post 1:
OK. And now I'm confused. I don't understand "And One Of Astronouth's Rare Contensts", so I don't know how to answer "Why would I care?" (I originally thought that line was part of your signature, so I just ignored it.)
__________________
Greg Ross (The Grammar Curmudgeon formerly known as gwross)
S/W Engineer, Team 330, the Beach 'Bots
<--The Grammar Curmudgeon loves this cartoon.
“Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" Hunter S. Thompson
"Playing a practical joke means doing something mean and calling it funny." Me

Last edited by Greg Ross : 13-04-2004 at 22:28.
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
PBASIC ARCTAN function Greg Ross Programming 14 11-05-2003 12:28
The angle of going up the Ramp David Bryan Programming 2 21-01-2003 20:56
Slotted Angle Aluminum hinge87 OCCRA 1 09-10-2002 18:15
Is an angle bracket allowed? archiver 2001 0 24-06-2002 00:58
45 degree PVC angle fittings: which? archiver 2001 2 23-06-2002 22:53


All times are GMT -5. The time now is 13:44.

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