Skip to content

Commit

Permalink
Joystick: learn axis min/max (commaai#23377)
Browse files Browse the repository at this point in the history
* Joystick: learn axis min/max

* clean up updating max/min

Co-authored-by: Willem Melching <willem.melching@gmail.com>
  • Loading branch information
incognitojam and pd0wm authored Jan 4, 2022
1 parent 5dbdad3 commit 5a77157
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tools/joystick/joystickd.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def update(self):

class Joystick:
def __init__(self):
self.max_axis_value = 255 # tune based on your joystick, 0 to this
self.min_axis_value = 0
self.max_axis_value = 255
self.cancel_button = 'BTN_TRIGGER'
self.axes_values = {'ABS_Y': 0., 'ABS_RZ': 0.} # gb, steer

Expand All @@ -45,7 +46,10 @@ def update(self):
if event[0] == self.cancel_button and event[1] == 0: # state 0 is falling edge
self.cancel = True
elif event[0] in self.axes_values:
norm = -interp(event[1], [0, self.max_axis_value], [-1., 1.])
self.max_axis_value = max(event[1], self.max_axis_value)
self.min_axis_value = min(event[1], self.min_axis_value)

norm = -interp(event[1], [self.min_axis_value, self.max_axis_value], [-1., 1.])
self.axes_values[event[0]] = norm if abs(norm) > 0.05 else 0. # center can be noisy, deadzone of 5%
else:
return False
Expand Down

0 comments on commit 5a77157

Please sign in to comment.