-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroverctl.py
118 lines (98 loc) · 2.17 KB
/
roverctl.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
import pygame
from pygame.locals import *
import socket
import time
HOST="192.168.2.1"
#HOST="localhost"
PORT=6666
# blah
class Knuebbel:
def __init__(self):
print "Initializing..."
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.s.connect((HOST, PORT))
pygame.init()
window = pygame.display.set_mode((468, 60))
self.state = {"direction": 90, "speed": 90}
#self.go_init()
self.state["direction"] = 90
self.send_it()
print "Ready."
self.loop()
def send_it(self):
tosend = "%003i%003i"%(self.state["speed"],self.state["direction"])
print tosend
self.s.send(tosend)
def go_init(self):
self.state["direction"] = 90
self.send_it()
time.sleep(2)
self.state["direction"] = 90
self.send_it()
time.sleep(2)
self.state["direction"] = 0
self.send_it()
time.sleep(2)
self.state["direction"] = 60
self.send_it()
def go_left(self):
self.state["direction"] = 60+45
self.send_it()
def go_right(self):
self.state["direction"] = 60-45
self.send_it()
def go_ahead(self):
self.state["direction"] = 60
self.send_it()
def go_backwards(self):
self.state["speed"] = 70
self.send_it()
def go_forwards(self):
self.state["speed"] = 110
self.send_it()
def go_stop(self):
self.state["speed"] = 90
self.send_it()
def input(self, events):
for event in events:
if event.type == QUIT:
sys.exit(0)
elif event.type == KEYUP:
print "Keyup",
if event.key == 273:
print "up"
self.go_stop()
elif event.key == 276:
print "left"
self.go_ahead()
elif event.key == 275:
print "right"
self.go_ahead()
elif event.key == 274:
print "down"
self.go_stop()
elif event.type == KEYDOWN:
print "Keydown",
#print event
if event.key == 273:
print "up"
self.go_forwards()
elif event.key == 276:
print "left"
self.go_left()
elif event.key == 275:
print "right"
self.go_right()
elif event.key == 274:
print "down"
self.go_backwards()
elif event.key == 13:
print "init"
self.go_init()
else:
#print event
pass
def loop(self):
while True:
self.input(pygame.event.get())
Knuebbel()