-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstick.py
More file actions
47 lines (27 loc) · 706 Bytes
/
Copy pathstick.py
File metadata and controls
47 lines (27 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import pygame
import socket
import struct
#bot 4 legs info
bot_IP= "10.11.12.112"
bot_PORT = 5001
sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
pygame.init()
clock = pygame.time.Clock()
pygame.joystick.init()
print("number of joystick:",pygame.joystick.get_count())
joy = pygame.joystick.Joystick(0)
joy.init()
hats = joy.get_numhats()
print("number of hats",hats)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
break
# get hat value
x , y = joy.get_hat(0)
print("x:",x," y:",y)
clock.tick(5)
packet = struct.pack("hh",x,y)
print("packet:",packet)
sock.sendto(packet,(bot_IP,bot_PORT))
joy.quit()