Proportional Servo Control Using PS3 Controller Joystick
Forums:
Hi;
So I have successfully added the code to operate a Servo connected to my UltraBorg using the D Pad Fwd and Back buttons. This lifts an arm fitted to the Robot up and down to predetermined upper and lower positions.
What I am trying to do now is move a servo using the RH Joystick on the PS3 Controller to give more precise movement rather than just all the way up or all the way down.
I know how to identify the Joystick Fwd and Back but I am not sure how to link the Joystick Movement to UB.SetServoPosition1(ServoX)
Any help would be great.
Tks
JonnyAlpha
Thu, 04/19/2018 - 10:39
Permalink
Do I assign the value of the
Do I assign the value of the joystick position to the variable upDown using:
upDown = joystick.get_axis(axisUpDown)
And then apply the value of upDown to the Servo using:
servo1 = upDown
UB.SetServoPosition1(servo1)
piborg
Fri, 04/20/2018 - 09:49
Permalink
Moving a servo from the Joystick
The code you have above should work fine, the servo will move between the limits set over the range of the joystick movement, setting the position to 0 when the joystick is centred.
If the movement goes the wrong direction you can swap it by adding a
-
sign like this:JonnyAlpha
Fri, 04/20/2018 - 23:02
Permalink
It worked but the servor is
It worked but the servor is moving to fast. How do I slow it down?
piborg
Sat, 04/21/2018 - 07:50
Permalink
Speed control of the servo
You can get the joystick to control the speed of the servo instead of the position by increasing / decreasing the servo value based on the joystick value. This will mean that when the joystick is released the servo will stay put.
All you need to do is add to the
servo1
value each time like this:The
servo1Speed
value controls the maximum speed the servo changes at when the joystick is at full. Larger numbers will move faster and smaller numbers will move slower.