-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRpi_navigation.py
More file actions
executable file
·38 lines (37 loc) · 977 Bytes
/
Rpi_navigation.py
File metadata and controls
executable file
·38 lines (37 loc) · 977 Bytes
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
#!/usr/bin/python
import smbus
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(26,GPIO.IN,pull_up_down=GPIO.PUD_UP)
bus=smbus.SMBus(1)
address=0x04
cmd={'b':0,'w':1,'s':2,'d':3,'a':4,'x':-1}
class ACKStatus:
def __init__(self):
self.ACK=False
def interruptHandler(self):
self.ACK=True
ACK=ACKStatus()
def writeCMD(value):
bus.write_byte(address,value)
def my_callback(channel):
ACK.interruptHandler()
GPIO.add_event_detect(26,GPIO.RISING,callback=my_callback)
if __name__=="__main__":
f=open('seq.txt','w')
key='b'
while cmd[key]!=-1:
key=raw_input('b:STOP,w:FORWARD,s:BACKWARD,d:RIGHT,a:LEFT,x:END')
if key not in cmd:
print "Please enter a valid key !"
key='b'
continue
ACK.ACK=False
writeCMD(cmd[key])
time.sleep(1)
if key=='x':
f.write(key)
else:
f.write(key+',')
f.close()