Browse Source

gamepad deadzones

split-pipe
Hendrik Langer 4 years ago
parent
commit
43486fdb15
  1. 14
      raspberry/roberto/views/websocket/routes.py

14
raspberry/roberto/views/websocket/routes.py

@ -30,9 +30,9 @@ def gamepad_axes(axes_data):
print('GAMEPAD axes') print('GAMEPAD axes')
print(axes_data) print(axes_data)
from roberto import serial from roberto import serial
x = axes_data['0'] x = applyDeadZone( axes_data['0'], 0.15 )
y = axes_data['1'] y = x = applyDeadZone( axes_data['1'], 0.15 )
r = axes_data['3'] r = x = applyDeadZone( axes_data['3'], 0.15 )
m0 = +y - x - r m0 = +y - x - r
m1 = +y + x - r m1 = +y + x - r
m2 = -y + x - r m2 = -y + x - r
@ -43,3 +43,11 @@ def gamepad_axes(axes_data):
m3 *= 4000 m3 *= 4000
command = 'S '+str(int(m0))+','+str(int(m1))+','+str(int(m2))+','+str(int(m3))+'\n' command = 'S '+str(int(m0))+','+str(int(m1))+','+str(int(m2))+','+str(int(m3))+'\n'
serial.write(bytes(command, "utf8")) serial.write(bytes(command, "utf8"))
def applyDeadZone(value, threshold):
new_value = ( abs(value) - threshold ) / ( 1 - threshold )
if new_value < 0:
return 0
if value < 0:
new_value = new_value * -1
return new_value

Loading…
Cancel
Save