# Getting the angle of the Joystick

tl;dr: How do you read in the value of the angle the joystick is pointing or the “true” value of the joystick

I am currently wondering about how to get the angle the joystick is point. To clarify, if you were to push the joystick up it would give you 90 degrees, if you pushed it to the left it would give you 180 degrees, and if you pushed it to the right it would give you 0 or 360 degrees. This seemed simple, just get the two joystick values and use either sin, cos, or tan to find the angle using SOH CAH TOA but that kept giving me strange readings at times. Upon further inspection I saw something weird; the values of the x and y axis would stop at 127. This meant that if I was slowly pushing the joystick up the values would reach 127 and stop going up even though I could still push the joystick up more. So if I went around the circumference of the circle with the joystick the Y would change but the X would be at 127. This meant that we could not use those values that we were reading from VexRT since they were not in relation to one another. From here I do not know what to do. I have looked for a built in function that gave me the angle but have not found one and I have looked for another way to get values from the Joystick but again did not find a way yet. So now I am asking the forums to see if any one had any ideas.

I am using RobotC

Can you post your code/algorithm/calculation?

The atan2 function is what you want to use. But be careful about dividing by 0. So you will need some if statements around this to protect yourself.

Radians is what is returned, not degrees. So converting from radians to degrees is needed after that.

I did two methods of finding the angle, one using cosine and x^2 + y^2 = r^2 to find the radius so i could do the adjacent over the hypotenuse and I also used tangent with the opposite over adjacent but it still gave me weird values.

``````
//This is what I used when using tangent
//I did use an if statement to stop the divid by zero error