[Semi-Emergency] Line Tracking & Light Finding with BS2
Hi everyone,
This is my first time here, and yet I'm asking for a big favor [noparse]:D[/noparse]. I have two tests tomorrow on Line Tracking and Light Finding using Boebot BS2. My group and I have worked very hard on these two projects in the past two week, and had devised few version of the programs. But sadly, none of them completely work so far. I would really appreciate it if anyone shall take a look at our codes to see what's wrong with them, and perhaps give us some new idea (preferably a easy fix, since time is essential here) [noparse]:)[/noparse]
I thank you all in advance for helping a little kid wanting to learn robotics..
Our Boebot setup:
A photoresistor on IN7.
Code for Finding Light:
OldVal VAR Word
NewVal VAR Word
Counter1 VAR Word
Counter2 VAR Word
forCount VAR Word
forCount = 0
DO
IF (IN7 = 0) THEN
GOSUB Move_Backward
ENDIF
forCount = forCount + 1
IF(forCount > 1000) THEN
GOSUB Move_Backward
forCount = 0
ENDIF
GOSUB Get_Value
GOSUB Move_Forward
GOSUB Move_Forward
GOSUB Get_Value
IF NewVal <= OldVal THEN
Counter1 = 0 'Was missing before
DO UNTIL NewVal > OldVal OR Counter1 >= 20
GOSUB Move_Forward
GOSUB Get_Value
Counter1 = Counter1 + 1
LOOP
ENDIF
IF NewVal > OldVal THEN
Counter1 = 0
GOSUB Move_Backward
GOSUB Get_Value
DO UNTIL NewVal < OldVal OR Counter1 >= 20 'Was "NewVal > OldVal" before
GOSUB Move_Backward
GOSUB Get_Value
Counter1 = Counter1 + 1
LOOP
ENDIF
GOSUB Rotate_Left
GOSUB Get_Value
IF NewVal <= OldVal THEN
Counter1 = 0
DO UNTIL NewVal > OldVal OR Counter1 >= 20
GOSUB Rotate_Left
GOSUB Get_Value
Counter1 = Counter1 + 1
LOOP
ENDIF
IF NewVal > OldVal THEN
Counter1 = 0
GOSUB Rotate_Right
GOSUB Get_Value
DO UNTIL NewVal < OldVal OR Counter1 >= 20 'Was "NewVal > OldVal" before
GOSUB Rotate_Right
GOSUB Get_Value
Counter1 = Counter1 + 1
LOOP
ENDIF
LOOP
Get_Value:
OldVal = NewVal
HIGH 7
PAUSE 2
RCTIME 7, 1, NewVal
RETURN
Move_Forward:
FOR Counter2 = 1 TO 5
PULSOUT 12, 800
PULSOUT 13, 700
NEXT
RETURN
Move_Backward:
FOR Counter2 = 1 TO 5
PULSOUT 12, 700
PULSOUT 13, 800
NEXT
RETURN
Rotate_Left:
FOR Counter2 = 1 TO 5
PULSOUT 12, 700
PULSOUT 13, 700
NEXT
RETURN
Rotate_Right:
FOR Counter2 = 1 TO 5
PULSOUT 12, 800
PULSOUT 13, 800
NEXT
RETURN
Code for Line Tracking:
' {$STAMP BS2}
' {$PBASIC 2.5}
timeLeft VAR Word
timeRight VAR Word
timeMid VAR Word
average VAR Word
difference VAR Word
Counter1 VAR Word
Counter2 VAR Word
degree VAR Word
clear VAR Word
leftRight VAR Word
degree = 0
clear = 0
leftRight = 0
DO
GOSUB Navigate
'GOSUB Move_Forward
LOOP
Navigate:
'Check if it's facing the black tap
IF (IN7 = 0) THEN
GOSUB Move_Forward
PAUSE 20
'If not, start panning
ELSE
clear = 0
leftRight = 0
degree = 0
'Keep on panning, with increasing degree of turning
DO UNTIL (clear = 1)
degree = degree + 1
'Pan left 'degree' times
FOR counter1 = 1 TO degree
GOSUB Rotate_Left
NEXT
IF (IN7 = 0) THEN
clear = 1
RETURN
ENDIF
FOR counter1 = 1 TO degree
GOSUB Rotate_Right
NEXT
'If the black tape isn't found on the pan-left trial
IF (clear = 0) THEN
'Pan right 'degree' times
FOR counter1 = 1 TO degree
GOSUB Rotate_Right
NEXT
IF (IN7 = 0) THEN
clear = 1
RETURN
ENDIF
FOR counter1 = 1 TO degree
GOSUB Rotate_Left
NEXT
ENDIF
LOOP
'Reset values
clear = 0
leftRight = 0
degree = 0
ENDIF
RETURN
Get_Value_Mid:
HIGH 7
PAUSE 2
RCTIME 7, 1, timeMid
RETURN
Get_Value_Left:
GOSUB Rotate_Left
HIGH 7
PAUSE 2
RCTIME 7, 1, timeLeft
GOSUB Rotate_Right
RETURN
Get_Value_Right:
GOSUB Rotate_Right
HIGH 7
PAUSE 2
RCTIME 7, 1, timeRight
GOSUB Rotate_Left
RETURN
Move_Forward:
FOR Counter2 = 1 TO 1
PULSOUT 12, 745
PULSOUT 13, 755
NEXT
RETURN
Move_Backward:
FOR Counter2 = 1 TO 1
PULSOUT 12, 755
PULSOUT 13, 745
NEXT
RETURN
Rotate_Left:
FOR Counter2 = 1 TO 1
PULSOUT 12, 775
PULSOUT 13, 775
NEXT
RETURN
Rotate_Right:
FOR Counter2 = 1 TO 1
PULSOUT 12, 725
PULSOUT 13, 725
NEXT
RETURN
Thank you!
This is my first time here, and yet I'm asking for a big favor [noparse]:D[/noparse]. I have two tests tomorrow on Line Tracking and Light Finding using Boebot BS2. My group and I have worked very hard on these two projects in the past two week, and had devised few version of the programs. But sadly, none of them completely work so far. I would really appreciate it if anyone shall take a look at our codes to see what's wrong with them, and perhaps give us some new idea (preferably a easy fix, since time is essential here) [noparse]:)[/noparse]
I thank you all in advance for helping a little kid wanting to learn robotics..
Our Boebot setup:
A photoresistor on IN7.
Code for Finding Light:
OldVal VAR Word
NewVal VAR Word
Counter1 VAR Word
Counter2 VAR Word
forCount VAR Word
forCount = 0
DO
IF (IN7 = 0) THEN
GOSUB Move_Backward
ENDIF
forCount = forCount + 1
IF(forCount > 1000) THEN
GOSUB Move_Backward
forCount = 0
ENDIF
GOSUB Get_Value
GOSUB Move_Forward
GOSUB Move_Forward
GOSUB Get_Value
IF NewVal <= OldVal THEN
Counter1 = 0 'Was missing before
DO UNTIL NewVal > OldVal OR Counter1 >= 20
GOSUB Move_Forward
GOSUB Get_Value
Counter1 = Counter1 + 1
LOOP
ENDIF
IF NewVal > OldVal THEN
Counter1 = 0
GOSUB Move_Backward
GOSUB Get_Value
DO UNTIL NewVal < OldVal OR Counter1 >= 20 'Was "NewVal > OldVal" before
GOSUB Move_Backward
GOSUB Get_Value
Counter1 = Counter1 + 1
LOOP
ENDIF
GOSUB Rotate_Left
GOSUB Get_Value
IF NewVal <= OldVal THEN
Counter1 = 0
DO UNTIL NewVal > OldVal OR Counter1 >= 20
GOSUB Rotate_Left
GOSUB Get_Value
Counter1 = Counter1 + 1
LOOP
ENDIF
IF NewVal > OldVal THEN
Counter1 = 0
GOSUB Rotate_Right
GOSUB Get_Value
DO UNTIL NewVal < OldVal OR Counter1 >= 20 'Was "NewVal > OldVal" before
GOSUB Rotate_Right
GOSUB Get_Value
Counter1 = Counter1 + 1
LOOP
ENDIF
LOOP
Get_Value:
OldVal = NewVal
HIGH 7
PAUSE 2
RCTIME 7, 1, NewVal
RETURN
Move_Forward:
FOR Counter2 = 1 TO 5
PULSOUT 12, 800
PULSOUT 13, 700
NEXT
RETURN
Move_Backward:
FOR Counter2 = 1 TO 5
PULSOUT 12, 700
PULSOUT 13, 800
NEXT
RETURN
Rotate_Left:
FOR Counter2 = 1 TO 5
PULSOUT 12, 700
PULSOUT 13, 700
NEXT
RETURN
Rotate_Right:
FOR Counter2 = 1 TO 5
PULSOUT 12, 800
PULSOUT 13, 800
NEXT
RETURN
Code for Line Tracking:
' {$STAMP BS2}
' {$PBASIC 2.5}
timeLeft VAR Word
timeRight VAR Word
timeMid VAR Word
average VAR Word
difference VAR Word
Counter1 VAR Word
Counter2 VAR Word
degree VAR Word
clear VAR Word
leftRight VAR Word
degree = 0
clear = 0
leftRight = 0
DO
GOSUB Navigate
'GOSUB Move_Forward
LOOP
Navigate:
'Check if it's facing the black tap
IF (IN7 = 0) THEN
GOSUB Move_Forward
PAUSE 20
'If not, start panning
ELSE
clear = 0
leftRight = 0
degree = 0
'Keep on panning, with increasing degree of turning
DO UNTIL (clear = 1)
degree = degree + 1
'Pan left 'degree' times
FOR counter1 = 1 TO degree
GOSUB Rotate_Left
NEXT
IF (IN7 = 0) THEN
clear = 1
RETURN
ENDIF
FOR counter1 = 1 TO degree
GOSUB Rotate_Right
NEXT
'If the black tape isn't found on the pan-left trial
IF (clear = 0) THEN
'Pan right 'degree' times
FOR counter1 = 1 TO degree
GOSUB Rotate_Right
NEXT
IF (IN7 = 0) THEN
clear = 1
RETURN
ENDIF
FOR counter1 = 1 TO degree
GOSUB Rotate_Left
NEXT
ENDIF
LOOP
'Reset values
clear = 0
leftRight = 0
degree = 0
ENDIF
RETURN
Get_Value_Mid:
HIGH 7
PAUSE 2
RCTIME 7, 1, timeMid
RETURN
Get_Value_Left:
GOSUB Rotate_Left
HIGH 7
PAUSE 2
RCTIME 7, 1, timeLeft
GOSUB Rotate_Right
RETURN
Get_Value_Right:
GOSUB Rotate_Right
HIGH 7
PAUSE 2
RCTIME 7, 1, timeRight
GOSUB Rotate_Left
RETURN
Move_Forward:
FOR Counter2 = 1 TO 1
PULSOUT 12, 745
PULSOUT 13, 755
NEXT
RETURN
Move_Backward:
FOR Counter2 = 1 TO 1
PULSOUT 12, 755
PULSOUT 13, 745
NEXT
RETURN
Rotate_Left:
FOR Counter2 = 1 TO 1
PULSOUT 12, 775
PULSOUT 13, 775
NEXT
RETURN
Rotate_Right:
FOR Counter2 = 1 TO 1
PULSOUT 12, 725
PULSOUT 13, 725
NEXT
RETURN
Thank you!
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Pi Guy