-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWiRobot_remote.py
executable file
·126 lines (108 loc) · 2.53 KB
/
WiRobot_remote.py
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python3
# -*- coding: utf8 -*-
import socket
import tkinter as tk
up = False
down = False
right = False
left = False
commande = bytes('S', 'mac_roman')
root = tk.Tk()
root.title('Wirobot Remote')
root.geometry('600x200')
label = tk.Label(root, height=200, width=600,background='black', foreground='white', font=('Comic Sans MS', 12), text='WiRobot Controller is connected...\nUse _ArrowKeys_ to control the WiRobot.')
label.pack()
robotSocket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
Hote = '132.208.13.15'
Port = 2323
robotSocket.connect((Hote,Port))
#label.insert('end', 'WiRobot Controller is connected...\n')
#text.insert('end', 'Use <UpKey>, <DownKey>, <RightKey> and <LeftKey> to control the WiRobot.')
#label.insert('end', 'Use _ArrowKeys_ to control the WiRobot.')
def updateCommande():
global commande
if up:
if down:
commande = bytes('S', 'mac_roman')
return
if right:
commande = bytes('D', 'mac_roman')
return
if left:
commande = bytes('H', 'mac_roman')
return
commande = bytes('F', 'mac_roman')
return
if down:
if right:
commande = bytes('G', 'mac_roman')
return
if left:
commande = bytes('J', 'mac_roman')
return
commande = bytes('B', 'mac_roman')
return
if right:
if left:
commande = bytes('S', 'mac_roman')
return
commande = bytes('R', 'mac_roman')
return
if left:
commande = bytes('L', 'mac_roman')
return
commande = bytes('S', 'mac_roman')
return
def pushCommande():
updateCommande()
robotSocket.send(commande)
def upKeyPress(event):
global up
if not up:
up = True
pushCommande()
def upKeyRelease(event):
global up
if up:
up = False
pushCommande()
def downKeyPress(event):
global down
if not down:
down = True
pushCommande()
def downKeyRelease(event):
global down
if down:
down = False
pushCommande()
def rightKeyPress(event):
global right
if not right:
right = True
pushCommande()
def rightKeyRelease(event):
global right
if right:
right = False
pushCommande()
def leftKeyPress(event):
global left
if not left:
left = True
pushCommande()
def leftKeyRelease(event):
global left
if left:
left = False
pushCommande()
root.bind('<KeyPress-Up>', upKeyPress)
root.bind('<KeyRelease-Up>', upKeyRelease)
root.bind('<KeyPress-Down>', downKeyPress)
root.bind('<KeyRelease-Down>', downKeyRelease)
root.bind('<KeyPress-Right>', rightKeyPress)
root.bind('<KeyRelease-Right>', rightKeyRelease)
root.bind('<KeyPress-Left>', leftKeyPress)
root.bind('<KeyRelease-Left>', leftKeyRelease)
root.mainloop()
robotSocket.close()