37Views5Replies

Author Options:

Axis value to angle conversion Answered

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.

0
user
PS118

4 months ago

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

I'm sort of sensitive when 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 Pot to

Plot a straight line from x,y from -1,0 to 0,90 to 1,180...

0
user
iceng

4 months 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