Go Down

Topic: Finding an angle from a Joystick (x and y value) (Read 1 time)previous topic - next topic

lpcmen2001

Jun 30, 2010, 12:25 am
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...

Thanks a lot !!

jrraines

#1
Jun 30, 2010, 03:13 am
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

crimony

#2
Jun 30, 2010, 03:40 am
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.

vinceherman

#3
Jun 30, 2010, 04:59 am
+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.

lpcmen2001

#4
Jul 03, 2010, 06:58 pm
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 !

Go Up

Please enter a valid email to subscribe