-
Notifications
You must be signed in to change notification settings - Fork 0
/
russell.py
executable file
·156 lines (131 loc) · 4.32 KB
/
russell.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BOARD)
Motor1A = 31
Motor1B = 29
Motor1E = 33
Motor2A = 13
Motor2B = 11
Motor2E = 15
MOTORS = [Motor1A, Motor1B, Motor1E, Motor2A, Motor2B, Motor2E]
GPIO.setup(Motor1A,GPIO.OUT)
GPIO.setup(Motor1B,GPIO.OUT)
GPIO.setup(Motor1E,GPIO.OUT)
GPIO.setup(Motor2A,GPIO.OUT)
GPIO.setup(Motor2B,GPIO.OUT)
GPIO.setup(Motor2E,GPIO.OUT)
def endit():
for pin in MOTORS:
#print(str(pin) + " set to GPIO.LOW")
GPIO.output(pin,GPIO.LOW)
GPIO.cleanup()
exit()
def forward():
print("driving forwards")
GPIO.output(Motor1A,GPIO.HIGH)
GPIO.output(Motor1B,GPIO.LOW)
GPIO.output(Motor1E,GPIO.HIGH)
GPIO.output(Motor2A,GPIO.HIGH)
GPIO.output(Motor2B,GPIO.LOW)
GPIO.output(Motor2E,GPIO.HIGH)
def reverse():
print("reversing")
GPIO.output(Motor1A,GPIO.LOW)
GPIO.output(Motor1B,GPIO.HIGH)
GPIO.output(Motor1E,GPIO.HIGH)
GPIO.output(Motor2A,GPIO.LOW)
GPIO.output(Motor2B,GPIO.HIGH)
GPIO.output(Motor2E,GPIO.HIGH)
def left():
print("turning left")
GPIO.output(Motor1A,GPIO.HIGH)
GPIO.output(Motor1B,GPIO.LOW)
GPIO.output(Motor1E,GPIO.HIGH)
GPIO.output(Motor2E,GPIO.LOW)
def backleft():
print("turning left")
GPIO.output(Motor1A,GPIO.LOW)
GPIO.output(Motor1B,GPIO.HIGH)
GPIO.output(Motor1E,GPIO.HIGH)
GPIO.output(Motor2E,GPIO.LOW)
def right():
print("turning right")
GPIO.output(Motor2A,GPIO.HIGH)
GPIO.output(Motor2B,GPIO.LOW)
GPIO.output(Motor2E,GPIO.HIGH)
GPIO.output(Motor1E,GPIO.LOW)
def backright():
print("turning right")
GPIO.output(Motor2A,GPIO.LOW)
GPIO.output(Motor2B,GPIO.HIGH)
GPIO.output(Motor2E,GPIO.HIGH)
GPIO.output(Motor1E,GPIO.LOW)
def clockwise():
print("turning clockwise")
GPIO.output(Motor1A,GPIO.LOW)
GPIO.output(Motor1B,GPIO.HIGH)
GPIO.output(Motor1E,GPIO.HIGH)
GPIO.output(Motor2A,GPIO.HIGH)
GPIO.output(Motor2B,GPIO.LOW)
GPIO.output(Motor2E,GPIO.HIGH)
def counterclock():
print("turning clockwise")
GPIO.output(Motor1A,GPIO.HIGH)
GPIO.output(Motor1B,GPIO.LOW)
GPIO.output(Motor1E,GPIO.HIGH)
GPIO.output(Motor2A,GPIO.LOW)
GPIO.output(Motor2B,GPIO.HIGH)
GPIO.output(Motor2E,GPIO.HIGH)
def stop():
GPIO.output(MOTORS,GPIO.LOW)
def help():
print ("RUSSELL knows how to:")
print ("\t*drive* and *go* *forward*")
print ("\t*reverse* and *back*")
print ("\tturn *left* or *right* and turn *backleft* or *backright*")
print ("\tspin *clockwise* and *counter*clockwise")
print ("\tand *stop*")
def welcome():
print ("██████╗░██╗░░░██╗░██████╗░██████╗███████╗██╗░░░░░")
print ("██╔══██╗██║░░░██║██╔════╝██╔════╝██╔════╝██║░░░░░")
print ("██████╔╝██║░░░██║╚█████╗░╚█████╗░█████╗░░██║░░░░░")
print ("██╔══██╗██║░░░██║░╚═══██╗░╚═══██╗██╔══╝░░██║░░░░░")
print ("██║░░██║╚██████╔╝██████╔╝██████╔╝███████╗███████╗")
print ("╚═╝░░╚═╝░╚═════╝░╚═════╝░╚═════╝░╚══════╝╚══════╝")
print ("\nRobust Universal Survey System and Experimental Lifeform\nPress 'h' for help\n\n")
welcome()
try:
running = True
while running:
command = input("> ").lower()
if command in ["g", "f", "forward", "drive", "go", "yeet"]:
forward()
elif command in ["reverse", "back"]:
reverse()
elif command in ["l", "left"]:
left()
elif command in ["r","right"]:
right()
elif command in ["bl", "backleft"]:
backleft()
elif command in ["br", "backright"]:
backright()
elif command in ["cl", "clockwise", "clock", "spinr"]:
clockwise()
elif command in ["cc", "counterclock", "counter", "spinl"]:
counterclock()
elif command in ["s", "n", "stop", "no", "bad", "bad russell"]:
if command == "bad russell":
print ("\t:(")
stop()
elif command in ["help", "h"]:
help()
elif command in ["quit", "q", "exit", "bye"]:
if command == "bye":
print("\tbye bye!")
running = False
else:
print ("RUSSELL doesn't know how to '"+command+"'\n")
except:
endit()
endit()