-
Notifications
You must be signed in to change notification settings - Fork 10
/
trackingModule.py
125 lines (104 loc) · 5.08 KB
/
trackingModule.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
#########################################################################
### Date: 2017/10/13
### file name: trackingModule.py
### Purpose: this code has been generated for the five-way tracking sensor
### to perform the decision of direction
###
#########################################################################
# =======================================================================
# import GPIO library and time module
# =======================================================================
import RPi.GPIO as GPIO
from time import sleep
# =======================================================================
# set GPIO warnings as false
# =======================================================================
GPIO.setwarnings(False)
# =======================================================================
# set up GPIO mode as BOARD
# =======================================================================
GPIO.setmode(GPIO.BOARD)
# =======================================================================
# declare the pins of 16, 18, 22, 40, 32 in the Rapberry Pi
# as the control pins of 5-way trackinmg sensor in order to
# control direction
#
# leftmostled leftlessled centerled rightlessled rightmostled
# 16 18 22 40 32
#
# led turns on (1) : trackinmg sensor led detects white playground
# led turns off(0) : trackinmg sensor led detects black line
# leftmostled off : it means that moving object finds black line
# at the position of leftmostled
# black line locates below the leftmostled of the moving object
#
# leftlessled off : it means that moving object finds black line
# at the position of leftlessled
# black line locates below the leftlessled of the moving object
#
# centerled off : it means that moving object finds black line
# at the position of centerled
# black line locates below the centerled of the moving object
#
# rightlessled off : it means that moving object finds black line
# at the position of rightlessled
# black line locates below the rightlessled of the moving object
#
# rightmostled off : it means that moving object finds black line
# at the position of rightmostled
# black line locates below the rightmostled of the moving object
# =======================================================================
leftmostled=16
leftlessled=18
centerled=22
rightlessled=40
rightmostled=32
# =======================================================================
# because the connetions between 5-way tracking sensor and Rapberry Pi has been
# established, the GPIO pins of Rapberry Pi
# such as leftmostled, leftlessled, centerled, rightlessled, and rightmostled
# should be clearly declared whether their roles of pins
# are output pin or input pin
# since the 5-way tracking sensor data has been detected and
# used as the input data, leftmostled, leftlessled, centerled, rightlessled, and rightmostled
# should be clearly declared as input
#
# =======================================================================
GPIO.setup(leftmostled, GPIO.IN)
GPIO.setup(leftlessled, GPIO.IN)
GPIO.setup(centerled, GPIO.IN)
GPIO.setup(rightlessled, GPIO.IN)
GPIO.setup(rightmostled, GPIO.IN)
# =======================================================================
# GPIO.input(leftmostled) method gives the data obtained from leftmostled
# leftmostled returns (1) : leftmostled detects white playground
# leftmostled returns (0) : leftmostled detects black line
#
#
# GPIO.input(leftlessled) method gives the data obtained from leftlessled
# leftlessled returns (1) : leftlessled detects white playground
# leftlessled returns (0) : leftlessled detects black line
#
# GPIO.input(centerled) method gives the data obtained from centerled
# centerled returns (1) : centerled detects white playground
# centerled returns (0) : centerled detects black line
#
# GPIO.input(rightlessled) method gives the data obtained from rightlessled
# rightlessled returns (1) : rightlessled detects white playground
# rightlessled returns (0) : rightlessled detects black line
#
# GPIO.input(rightmostled) method gives the data obtained from rightmostled
# rightmostled returns (1) : rightmostled detects white playground
# rightmostled returns (0) : rightmostled detects black line
#
# =======================================================================
try:
while True:
print("leftmostled detects black line(0) or white ground(1): " + str(GPIO.input(leftmostled)))
print("leftlessled detects black line(0) or white ground(1): " + str(GPIO.input(leftlessled)))
print("centerled detects black line(0) or white ground(1): " + str(GPIO.input(centerled)))
print("rightlessled detects black line(0) or white ground(1): " + str(GPIO.input(rightlessled)))
print("rightmostled detects black line(0) or white ground(1): " + str(GPIO.input(rightmostled)))
sleep(1)
except KeyboardInterrupt:
GPIO.cleanup()