-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontrol_script.py
63 lines (50 loc) · 1.29 KB
/
control_script.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
# To establish I2C communication between Arduino
import smbus
# for RPI version 1, use ?bus = smbus.SMBus(0)?
bus = smbus.SMBus(1)
# This is the address we setup in the Arduino Program
address = 0x04
def writeNumber(value):
bus.write_byte(address, value)
# bus.write_byte_data(address, 0, value)
return -1
def readNumber():
number = bus.read_byte(address)
# number = bus.read_byte_data(address, 1)
return number
from time import sleep
import motor
m1 = motor.Motor([18, 21, 13]) # physical 12, 40, 33
m2 = motor.Motor([8, 19, 26])
motor.stop(m1, m2)
print "Commands"
print "E --> Exit"
print "F --> Forward"
print "L --> Left"
print "R --> Right"
print "B --> Back"
print "S --> Set Speed"
while True:
inp = raw_input("Enter Command: ").strip()
inp_p = inp.lower()
if inp_p == 'E':
break
elif inp_p == "B":
motor.back(m1, m2)
sleep(2)
motor.stop(m1, m2)
elif inp_p == "F":
motor.front(m1, m2)
sleep(2)
motor.stop(m1, m2)
elif inp_p == "L":
motor.turnLeft(m1, m2)
sleep(2)
motor.stop(m1, m2)
elif inp_p == "R":
motor.turnRight(m1, m2)
sleep(2)
motor.stop(m1, m2)
elif inp_p == "S":
speed = input("Enter Speed: ")
writeNumber(speed)