Pages: [1]   Go Down
Author Topic: Finding an angle from a Joystick (x and y value)  (Read 675 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, I am currently developing a robot with the Wii nunchuck and I am trying to find a way to deduce the angle in degree that forms my x and y value with the center of the joystick. I though of a way using the atan() method but It will only work for angle bigger than 45 degree (since it works with the Pythagorean theorem and the triangle whose 3 angle must be equal 180).

So let's say i have my coord ( 28, 5 ) , I want to be able to find what angle it forms from the point 0,0, clockwise... where point (1,0) would be 0 ,    (1,1) would be 45,    (0,1) would be 90 and so on...

I am really looking forward to your answers...

Thanks a lot !!
Logged

Minnesota USA
Offline Offline
Sr. Member
****
Karma: 1
Posts: 323
Made it mahself outta sand 'n wahr.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I haven't used this and I think some of the data structures will have to be recreated as they don't seem to be online,  but this is a really neat description of how to solve your problem for underpowered 8 bit microprocessors:
www.cypress.com/?docID=2279

maybe someone's done it with an arduino already
Logged

Australia
Offline Offline
Jr. Member
**
Karma: 0
Posts: 99
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Hi, I am currently developing a robot with the Wii nunchuck and I am trying to find a way to deduce the angle in degree that forms my x and y value with the center of the joystick. I though of a way using the atan() method but It will only work for angle bigger than 45 degree

That's exactly what atan2(x, y) is for.
Logged

Ohio
Offline Offline
Full Member
***
Karma: 0
Posts: 227
Arduino Hexapod
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

+1 for using atan2

I used this until I ran short of cycles, then I switched to an approximation of atan2.  Less accurate, but more than accurate enough for the work I was doing.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Works great with atan2() !! Thanks a lot !!

How did you do your approximation of atan2() ? Only curious !! I dont think I am running out of cycle (though I dont really know what this mean... care to explain?).

Thanks a lot for the fast answer !
Logged

Pages: [1]   Go Up
Jump to: