35Views5Replies

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.

5 Replies

user
Bhabeshr (author)2018-03-16

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.

Select as Best AnswerUndo Best Answer

user
PS118 (author)2018-03-12

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

Select as Best AnswerUndo Best Answer

user
iceng (author)PS1182018-03-12

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

Select as Best AnswerUndo Best Answer

user
iceng (author)2018-03-12

.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

Select as Best AnswerUndo Best Answer

user
randofo (author)2018-03-12

Assuming that you are using Arduino, you want to check out the map function:
https://www.arduino.cc/reference/en/language/funct...

Select as Best AnswerUndo Best Answer