forked from Ridhwanluthra/NLMS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encoders.py
41 lines (40 loc) · 988 Bytes
/
encoders.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
import RPi.GPIO as gpio
gpio.setmode(gpio.BCM)
leften = 17
righten = 18
dps = 33.800/24.000 #distance per spoke
gpio.setup(leften,gpio.IN)
gpio.setup(righten,gpio.IN)
counter_left = 0
counter_right = 0
c = 0
a = 0
def d_move():
gpio.setmode(gpio.BCM)
while True:
global a
global c
global counter_left
global counter_right
b = a
d = c
a = gpio.input(leften)
c = gpio.input(righten)
if ((a == 1 and b == 0) or (a == 0 and b == 1)):
counter_left += 1
#print "left counter "
#print counter_left*dps/2
if ((c == 1 and d == 0) or (c == 0 and d == 1)):
counter_right += 1
#print "right coutner "
#print counter_right*dps/2
return [counter_left*dps/2, counter_right*dps/2]
def refresh():
global a
global c
global counter_left
global counter_right
counter_left = 0
counter_right = 0
c = 0
a = 0