forked from chi-bobolinks-2016/RaspberryDrive
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdriving_server.py
49 lines (45 loc) · 1.33 KB
/
driving_server.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
from socket import *
import run_rc_car as picar
def createPiReceiver():
serversocket = socket(AF_INET, SOCK_STREAM)
port = 9000
new_picar = picar.PiCar()
serversocket.bind(('',port))
serversocket.listen(5)
print "New Server Created, listening on port " + str(port)
while(1):
(clientsocket, address) = serversocket.accept()
print "accepted connection from " + str(address)
while(1):
transfer = clientsocket.recv(20)
if not transfer: break
if (transfer == "quit"):
exit()
else:
transfer = transfer.split(';')
if transfer == ['']: break
print "received: " + str(transfer)
inputParser(transfer[0].strip(),float(transfer[1]),new_picar)
clientsocket.send("true")
def inputParser(command,number,car):
print 'executing ' + command + ' for ' + str(number) +' seconds'
if command == "forward":
car.go_forward(number)
elif command == "backward":
car.go_backward(number)
elif command == "right":
car.go_forward_right(number)
elif command == "left":
car.go_forward_left(number)
elif command == "backward right":
car.go_backward_wheels_right(number)
elif command == "backward left":
car.go_backward_wheels_left(number)
elif command == "wheels right":
car.turn_wheels_right(number)
elif command == "wheels left":
car.turn_wheels_left(number)
else:
car.stop()
createPiReceiver()
exit()