|
|
|
@ -45,8 +45,10 @@ class Joystick: |
|
|
|
|
# TODO: find a way to get this from API or detect gamepad/PC, perhaps "inputs" doesn't support it |
|
|
|
|
# TODO: the mapping can also be wrong on PC depending on the driver |
|
|
|
|
self.cancel_button = 'BTN_NORTH' # BTN_NORTH=X/triangle |
|
|
|
|
accel_axis = 'ABS_Y' |
|
|
|
|
accel_axis = 'ABS_RX' |
|
|
|
|
steer_axis = 'ABS_Z' |
|
|
|
|
# TODO: once the longcontrol API is finalized, we can replace this with outputting gas/brake and steering |
|
|
|
|
self.flip_map = {'ABS_RY': accel_axis} |
|
|
|
|
self.min_axis_value = {accel_axis: 0., steer_axis: 0.} |
|
|
|
|
self.max_axis_value = {accel_axis: 255., steer_axis: 255.} |
|
|
|
|
self.axes_values = {accel_axis: 0., steer_axis: 0.} |
|
|
|
@ -56,6 +58,11 @@ class Joystick: |
|
|
|
|
def update(self): |
|
|
|
|
joystick_event = get_gamepad()[0] |
|
|
|
|
event = (joystick_event.code, joystick_event.state) |
|
|
|
|
|
|
|
|
|
# flip left trigger to negative accel |
|
|
|
|
if event[0] in self.flip_map: |
|
|
|
|
event = (self.flip_map[event[0]], -event[1]) |
|
|
|
|
|
|
|
|
|
if event[0] == self.cancel_button: |
|
|
|
|
if event[1] == 1: |
|
|
|
|
self.cancel = True |
|
|
|
@ -66,7 +73,7 @@ class Joystick: |
|
|
|
|
self.min_axis_value[event[0]] = min(event[1], self.min_axis_value[event[0]]) |
|
|
|
|
|
|
|
|
|
norm = -interp(event[1], [self.min_axis_value[event[0]], self.max_axis_value[event[0]]], [-1., 1.]) |
|
|
|
|
norm = norm if abs(norm) > 0.02 else 0. # center can be noisy, deadzone of 2% |
|
|
|
|
norm = norm if abs(norm) > 0.03 else 0. # center can be noisy, deadzone of 3% |
|
|
|
|
self.axes_values[event[0]] = JS_EXPO * norm ** 3 + (1 - JS_EXPO) * norm # less action near center for fine control |
|
|
|
|
else: |
|
|
|
|
return False |
|
|
|
|