adding center off range to joystick control
Greg  [2 posts]
6 years
I am controlling an ROV with a USB Attack 3 Joystick to a Pololu Maestro controller.  I have good control of the sliders but I need to have a small deadband around the center position of 1500 .  The joystick does not return to dead center on release but is somewhere around 50 + or -.  For good control it is critical the motors controlling left, right, forward and back stop on joystick release.  I was thinking that an IF statement for joystick position of 1450 to 1550 to set servo to 1500 (center-off) then use an else statement for anything outside that range to operate normally.  I am very new to programming.  To control the slider position now I am using the following: SetVariable "sfor_back", GetVariable ("jfor_back") + 1500.  Everything I have tried for the if statement has failed to function.  Any help would be greatly appreciated.  
Anonymous 6 years

it may be easier if you post you entire VBScript. It should be something along the lines of:

jforBack = GetVariable("jfor_back")
if jforBack > 1450 and jforBack < 1550 then
  SetVariable "sfor_back", 1500
  SetVariable "sfor_back", jforBack
end if

John Cabrer from United States  [13 posts] 6 years
When implementing a DEADBAND filter for joysticks, you have to consider that any value outside the deadband area (usually a square) has to be scaled back to 1 or 0.

In pseudo-code, assuming that the joystick value ranges for X and Y axis are -32767 to 32767, and a deadband of +/-1500, looks something like this


SCALING_X = 0.9542236328125  //  (32768-1500)/32768
SCALING_Y = 0.9542236328125


// Coerce joystick values inside deadband area, otherwise ignore
if JOYSTICK_X >= -1500 and JOYSTICK_X <= 1500 then
    JOYSTICK_X = 0;

if JOYSTICK_Y >= -1500 and JOYSTICK_Y <= 1500 then
    JOYSTICK_Y = 0;


This should effectively remove a chunk of sensitivity from the joystick near the center position, but still allow you to send the full dynamic range of the joystick without a sudden jerky move when the thing goes from 0 straight to 1500.
Greg  [2 posts] 6 years
I will give both of these options a try, hopefully one will work for me, if not I will post what I have tried previously.  Thanks again for the help

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index