37Views5Replies

# Axis value to angle conversion

Hello all,

So I have been trying to convert the values obtained from pygame joystick value (ranges from -1 to 1) and convert it to angles between 0 to 180 to drive servo motors. Can someone help me with this cuz I have no idea how to do it.

Thanks in advance

Cheers.

## Discussions

Thanks a lot, everyone. I ended up using the sine inverse function to convert the values into angle values as I was using a single axis for interfacing.

Cheers, and thanks again for all the help.

Well, that's a +/- percent, centered at 90 degrees, so:

angle=90 + 90*pygame_value

I'm sort of

sensitivewhen someone restates my exact equation as their own,after I post first.I also demonstrate using my original Equation Answer for the AXIS at 0.5 to Y angle of 135'..!

And this lets me correct the word

PottoPlota straight line from x,y from -1,0 to 0,90 to 1,180....X _ Y.....X _ Y.....X _ Y....

-1 = 0...0 = 90... 1 = 180....(X * 90 +90 = Y)

Pot a straight line from X,Y...-1,0....0,90...1,180

Try X = 0.5 _ to _Y = 90*0.5 +90 = 45 +90 = 135 = Y

Assuming that you are using Arduino, you want to check out the map function:

https://www.arduino.cc/reference/en/language/funct...