-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathucbot.py
87 lines (76 loc) · 1.84 KB
/
ucbot.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
import RPi.GPIO as gpio
import time
import sys
import Tkinter as tk
from sensor import distance
import random
# Setting up the BOARD
def init():
gpio.setmode(gpio.BOARD)
gpio.setup(7, gpio.OUT)
gpio.setup(11, gpio.OUT)
gpio.setup(13, gpio.OUT)
gpio.setup(15, gpio.OUT)
#Setting up the output pins
def forward(tf):
gpio.output(7, False)
gpio.output(11, True)
gpio.output(13, True)
gpio.output(15, False)
time.sleep(tf)
gpio.cleanup()
def reverse(tf):
gpio.output(7, True)
gpio.output(11, False)
gpio.output(13, False)
gpio.output(15, True)
time.sleep(tf)
gpio.cleanup()
def turn_left(tf):
gpio.output(7, True)
gpio.output(11, True)
gpio.output(13, True)
gpio.output(15, False)
time.sleep(tf)
gpio.cleanup()
def turn_right(tf):
gpio.output(7, False)
gpio.output(11, True)
gpio.output(13, False)
gpio.output(15, False)
time.sleep(tf)
gpio.cleanup()
def pivot_left(tf):
gpio.output(7, True)
gpio.output(11, False)
gpio.output(13, True)
gpio.output(15, False)
time.sleep(tf)
gpio.cleanup()
def pivot_right(tf):
gpio.output(7, False)
gpio.output(11, True)
gpio.output(13, False)
gpio.output(15, True)
time.sleep(tf)
gpio.cleanup()
def key_input (event):
init()
print 'Key:', event.char
key_press = event.char
sleep_time = 0.030
if key_press.lower() == 'w':
forward(sleep_time)
elif key_press.lower() == 's':
reverse(sleep_time)
elif key_press.lower() == 'a':
turn_left(sleep_time)
elif key_press(sleep_time) == 'd':
turn_right(sleep_time)
elif key_press.lower() == 'q':
pivot_left(sleep_time)
elif key_press.lower() == 'e':
pivot_right(sleep_time)
command = tk.Tk()
command.blind('<KeyPress>', key_input)
command.mainloop()