78Views5Replies

# 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.

## Comments

3 years ago

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.

3 years ago

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

angle=90 + 90*pygame_value

Answer 3 years ago

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...3 years ago

.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

3 years ago

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

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