raspberry-pijoystickgamepadinput-devices

Convert ABS_X and ABS_Y into meaningful values


I am new to mapping a gaming controller and I am attempting to make sense of the ABX_X and ABS_Y values that return from the joystick. My goal is to take those values and turn them into "move forward", "move back", "turn" etc. I cannot seem to figure out what the formula is for converting the values that come in to actions. Below is my ABSInfo data (from Python InputDevice) and also some sample values. Any help to steer me in the correct direction would be very helpful.

ABS Info Capabilities

('EV_ABS', 3): [(('ABS_X', 0), AbsInfo(value=32768, min=0, max=65535, fuzz=0, flat=4095, resolution=0)), (('ABS_Y', 1), AbsInfo(value=32768, min=0, max=65535, fuzz=0, flat=4095, resolution=0))

Sample Values For Y

Y VALUE: 3101
Y VALUE: 5241
Y VALUE: 6931
Y VALUE: 9597
Y VALUE: 12059
Y VALUE: 14990
Y VALUE: 17467
Y VALUE: 19878
Y VALUE: 32768

Sample values for X:

X VALUE: 23596
X VALUE: 14042
X VALUE: 0
X VALUE: 818
X VALUE: 5943
X VALUE: 17212
X VALUE: 32768

Solution

  • evdev provides axis values exactly as they are received from the device, unscaled. The input_absinfo struct (AbsInfo in python) gives the bounds information to let you normalize joystick inputs.

    (('ABS_X', 0), AbsInfo(value=32768, min=0, max=65535, fuzz=0, flat=4095, resolution=0)),
    

    Supposing you wanted your joystick to give a value of -1 at its minimum and +1 at its maximum, you can normalize ABS_X using the min and max values in AbsInfo:

    normalizedValue = 2.0 * (value - min) / (max - min) - 1.0