-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogic
178 lines (153 loc) · 3.98 KB
/
logic
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
checkRow(robotRowNum, withinRow, data, video_capture) {
if robotRowNum in data and withinRow is false
redDetails = getRedDetails()
while red is still found
laneDetails = getLaneDetails(ignore the blue side where the red is found)
if laneCheck(laneDetails) is true
moveforward
else
stop moving
redDetails = getRedDetails()
}
laneCheck(laneDetails) {
if lane dimensions are ok
if centroid of lane not within bounds
while not within bounds
stop moving
laneDetails = getLaneDetails()
if centroid_x < left bound limit
rotate to left
else
rotate to right
return True
else
return False
}
redCheck(redDetails) {
if saw red and dimensions ok
foundRed = true
if red within bounds
stop moving
#check what it is for and do action
if withinRow == false
robotRowNum++
withinRow = checkRow(robotRowNum, withinRow, data, video_capture);
else
currDot++
checkDot(robotRowNum, withinRow, data);
else:
foundRed = false
}
foundRed = false
withinRow = false
robotRowNum = 0
while true
laneDetails = getLaneDetails()
laneFound = laneCheck(laneDetails)
if there is lane
start moving
redDetails = getRedDetails()
redFound = redCheck(redDetails)
else
stop moving
=============================================================================================================================================================================
flags:
- arguments
-- Total Number of Stops
-- Stops per Rows
- sawTrueRed
- sawLane
- masterOff
- movementOverride
- lastMovement
- inLane
- currentRow
- currentDot
- numberOfStopsForRow
- returning
files structure
main
redChecking
laneChecking
movement
=============================================================================================================================================================================
:::MOVING FORWARD LOGIC::::
:::::::::::::::::::::::::::::::::::::::::
while true
laneDetails = getLaneDetails()
if centroid is out of bounds
movementOverride set to LANE
stop moving
while centroid is out of bounds
if centroid < left limit
rotate to left
else
rotate to right
movementOverride set to null
else
move forward
=============================================================================================================================================================================
:::RED CHECK::::
:::::::::::::::::::::::::::::::::::::::::
findLaneRotateBasedOnRed() {
while no green found {
move forward
}
while found lane {
rotate based on the placement of red
}
while no lane found {
rotate based on the placement of red
}
}
while true
redDetails = getRedDetails()
if red meets required dimensions
movementOverride set to RED
stop the movement
if inLane is true
if returning is True
decrement currentDot
if currentDot < 1 {
if totalNumberOfStops < 1 {
findLaneRotateBasedOnRed()
inLane = False
}
}
else {
move forward until red is not found
set returning to False
}
else
increment currentDot
if currentDot is in the list to go to based on the currentRow
decrement totalNumberOfStops
while green not found {
move forward
}
trigger the paper dispenser
decrement numberOfStopsForRow
while the paper dispenser is still running
pass
if numberOfStopsForRow = 0 {
perform findLaneRotateBasedOnRed process
set returning to True
}
else
while green not found {
move forward
}
else
if returning is True
decrement currentRow
keep moving forward until red is gone
else
increment currentRow
if currentRow is in the list to go to
perform findLaneRotateBasedOnRed process
set inLane to true
set currentDot to 0
set numberOfStopsForRow to the value of the places in the respective row
else
move forward until you find the green ignoring the blue where the red is located
movementOverride set to null