Repository navigation
Expand file tree
/
Copy pathPyRemote.py
More file actions
75 lines (60 loc) · 2.1 KB
/
Copy pathPyRemote.py
File metadata and controls
75 lines (60 loc) · 2.1 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import RemoteAPI_pb2 # the _pb2 suffix here has nothing to do with proto version, god knows why google named it this way lol
import socket
import time
from pynput import keyboard
TritonBot_IP = "127.0.0.1"
RemoteCONN_Port = 6000
RemoteCMD_Port = 6001
# ...
cmd = RemoteAPI_pb2.Commands()
cmd.enable_ball_auto_capture = False
cmd.mode = 3
cmd.is_world_frame = True
cmd.motion_set_point.x, cmd.motion_set_point.y, cmd.motion_set_point.z = 0.0, 0.0, 0.0
cmd.kicker_set_point.x, cmd.kicker_set_point.y = 0, 0
cmd_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
pwr = 80
r_pwr = 15
def on_press(key):
try:
#print(type(key))
if not (type(key) is keyboard.Key):
if key.char == 'w':
cmd.motion_set_point.y = pwr
if key.char == 's':
cmd.motion_set_point.y = -pwr
if key.char == 'a':
cmd.motion_set_point.x = -pwr
if key.char == 'd':
cmd.motion_set_point.x = pwr
else:
if key == keyboard.Key.left:
cmd.motion_set_point.z = r_pwr
if key == keyboard.Key.right:
cmd.motion_set_point.z = -r_pwr
except AttributeError:
# print('special key {0} pressed'.format(key))
pass
def on_release(key):
if not (type(key) is keyboard.Key):
if key.char == 'w':
cmd.motion_set_point.y = 0
if key.char == 's':
cmd.motion_set_point.y = 0
if key.char == 'a':
cmd.motion_set_point.x = 0
if key.char == 'd':
cmd.motion_set_point.x = 0
else:
if key == keyboard.Key.left:
cmd.motion_set_point.z = 0
if key == keyboard.Key.right:
cmd.motion_set_point.z = 0
listener = keyboard.Listener(on_press=on_press, on_release=on_release)
listener.start()
while True:
print("<", cmd.motion_set_point.x, ", ",
cmd.motion_set_point.y, ", ",
cmd.motion_set_point.z, ">")
cmd_socket.sendto(cmd.SerializeToString(), (TritonBot_IP, RemoteCMD_Port))
# ....