Help with stripe following program
lucky luciano
Posts: 2
There are a few problems with this program.
·- I would like to have the boe-bot do a 360 scan to look for the stripe before just taking off in a random direction, but I haven't been able to get that to work.
·- In one part of the course, there is an incline. The boe-bot has trouble detecting the stripe while having the strength to make its way up the incline.
·- Part of the program has the boe bot signal when it readjusts itself, but right now only one LED is lighting, and it pauses for too long every time.
·- There is also a very sharp turn in the course which the boe bot repeatedly gets stuck on.
'---- [noparse][[/noparse] Constants ]
Kpl·············· CON······ 35··················· ' Change from -35 to 35
Kpr·············· CON······ -35·················· ' Change from 35 to -35
SetPoint········· CON······ 3···················· ' Change from 2 to 3
CenterPulse······ CON······ 750
'---- [noparse][[/noparse] Variables ]
freqSelect······· VAR·· Nib
irFrequency······ VAR·· Word
irDetectLeft····· VAR·· Bit
irDetectRight···· VAR·· Bit
distanceLeft····· VAR·· Nib
distanceRight···· VAR·· Nib
pulseLeft········ VAR·· Word
pulseRight······· VAR·· Word
pulseCount······· VAR·· Byte
timer············ VAR·· Byte
counter·········· VAR·· Nib
old7············· VAR·· Bit
old5············· VAR·· Bit
'---- [noparse][[/noparse] Initialization ]
FREQOUT 4, 2000, 3000
counter = 1
old7 = 0
old5 = 1
' ---- [noparse][[/noparse] Stripe Following Routine ]
DO
· GOSUB Get_Ir_Distances
· FOR timer = 0 TO 100
····· timer = timer+1
· NEXT
· pulseLeft = SetPoint - distanceLeft * Kpl + CenterPulse
· pulseRight = SetPoint - distanceRight * Kpr + CenterPulse
· GOSUB Send_Pulse
' ---- [noparse][[/noparse] IR Detection ]
· IF (irDetectLeft = 0) THEN
··· LOW 10
· ELSE
··· HIGH 10
··· FREQOUT 4, 10, 2000
· ENDIF
· IF (irDetectRight = 0) THEN
··· LOW 10
· ELSE
··· HIGH 10
··· FREQOUT 4, 10, 2000
· ENDIF
' ---- [noparse][[/noparse] Corner Escaping Routine ]
· IF (IN7 <> IN5) THEN
··· IF (old7 <> IN7) AND (old5 <> IN5) THEN
····· counter = counter + 1
····· old7 = IN7
····· old5 = IN5
····· IF (counter > 4) THEN
······· counter = 1
······· GOSUB Back_Up
······· GOSUB Turn_Right
······· GOSUB Turn_Right
····· ENDIF
··· ELSE
····· counter = 1
··· ENDIF
· ENDIF
' whiskers
· IF (IN5 = 0) AND (IN7 = 0) THEN··············· ' Both whiskers detect obstacle
··· GOSUB Back_up······························· ' Back up and U turn, left twice
··· GOSUB Turn_Left
· ELSEIF (IN5 = 0) THEN
··· GOSUB Back_Up
··· GOSUB Turn_Right
· ELSEIF (IN7 = 0) THEN
··· GOSUB Back_Up
··· GOSUB Turn_Right
· ELSE
··· GOSUB Forward_Pulse
· ENDIF
LOOP
' GET INFRARED DISTANCES
Get_Ir_Distances:
· distanceLeft = 0
· distanceRight = 0
· FOR freqSelect = 0 TO 4
··· LOOKUP freqSelect, [noparse][[/noparse]37500,38250,39500,40500,41500], irFrequency
··· FREQOUT 8,1,irFrequency
··· irDetectLeft = IN9
··· distanceLeft = distanceLeft + irDetectLeft
··· FREQOUT 2,1,irFrequency
··· irDetectRight = IN0
··· distanceRight = distanceRight + irDetectRight
··· PAUSE 5
· NEXT
· RETURN
' SEND PULSE
Send_Pulse:
· PULSOUT 13,pulseLeft
· PULSOUT 12,pulseRight
· PAUSE 5
· RETURN
' WHISKER SUBS
Forward_Pulse:
· PULSOUT 13, 850
· PULSOUT 12, 650
· PAUSE 20
· RETURN
Turn_left:
· FOR pulseCount = 0 TO 20
··· PULSOUT 13, 650
··· PULSOUT 12, 650
··· PAUSE 20
· NEXT
· RETURN
Turn_Right:
· FOR pulseCount = 0 TO 20
··· PULSOUT 13, 850
··· PULSOUT 12, 850
··· PAUSE 20
· NEXT
· RETURN
Back_up:
· FOR pulseCount = 0 TO 10
··· PULSOUT 13, 650
··· PULSOUT 12, 850
··· PAUSE 20
· NEXT
· RETURN
·- I would like to have the boe-bot do a 360 scan to look for the stripe before just taking off in a random direction, but I haven't been able to get that to work.
·- In one part of the course, there is an incline. The boe-bot has trouble detecting the stripe while having the strength to make its way up the incline.
·- Part of the program has the boe bot signal when it readjusts itself, but right now only one LED is lighting, and it pauses for too long every time.
·- There is also a very sharp turn in the course which the boe bot repeatedly gets stuck on.
'---- [noparse][[/noparse] Constants ]
Kpl·············· CON······ 35··················· ' Change from -35 to 35
Kpr·············· CON······ -35·················· ' Change from 35 to -35
SetPoint········· CON······ 3···················· ' Change from 2 to 3
CenterPulse······ CON······ 750
'---- [noparse][[/noparse] Variables ]
freqSelect······· VAR·· Nib
irFrequency······ VAR·· Word
irDetectLeft····· VAR·· Bit
irDetectRight···· VAR·· Bit
distanceLeft····· VAR·· Nib
distanceRight···· VAR·· Nib
pulseLeft········ VAR·· Word
pulseRight······· VAR·· Word
pulseCount······· VAR·· Byte
timer············ VAR·· Byte
counter·········· VAR·· Nib
old7············· VAR·· Bit
old5············· VAR·· Bit
'---- [noparse][[/noparse] Initialization ]
FREQOUT 4, 2000, 3000
counter = 1
old7 = 0
old5 = 1
' ---- [noparse][[/noparse] Stripe Following Routine ]
DO
· GOSUB Get_Ir_Distances
· FOR timer = 0 TO 100
····· timer = timer+1
· NEXT
· pulseLeft = SetPoint - distanceLeft * Kpl + CenterPulse
· pulseRight = SetPoint - distanceRight * Kpr + CenterPulse
· GOSUB Send_Pulse
' ---- [noparse][[/noparse] IR Detection ]
· IF (irDetectLeft = 0) THEN
··· LOW 10
· ELSE
··· HIGH 10
··· FREQOUT 4, 10, 2000
· ENDIF
· IF (irDetectRight = 0) THEN
··· LOW 10
· ELSE
··· HIGH 10
··· FREQOUT 4, 10, 2000
· ENDIF
' ---- [noparse][[/noparse] Corner Escaping Routine ]
· IF (IN7 <> IN5) THEN
··· IF (old7 <> IN7) AND (old5 <> IN5) THEN
····· counter = counter + 1
····· old7 = IN7
····· old5 = IN5
····· IF (counter > 4) THEN
······· counter = 1
······· GOSUB Back_Up
······· GOSUB Turn_Right
······· GOSUB Turn_Right
····· ENDIF
··· ELSE
····· counter = 1
··· ENDIF
· ENDIF
' whiskers
· IF (IN5 = 0) AND (IN7 = 0) THEN··············· ' Both whiskers detect obstacle
··· GOSUB Back_up······························· ' Back up and U turn, left twice
··· GOSUB Turn_Left
· ELSEIF (IN5 = 0) THEN
··· GOSUB Back_Up
··· GOSUB Turn_Right
· ELSEIF (IN7 = 0) THEN
··· GOSUB Back_Up
··· GOSUB Turn_Right
· ELSE
··· GOSUB Forward_Pulse
· ENDIF
LOOP
' GET INFRARED DISTANCES
Get_Ir_Distances:
· distanceLeft = 0
· distanceRight = 0
· FOR freqSelect = 0 TO 4
··· LOOKUP freqSelect, [noparse][[/noparse]37500,38250,39500,40500,41500], irFrequency
··· FREQOUT 8,1,irFrequency
··· irDetectLeft = IN9
··· distanceLeft = distanceLeft + irDetectLeft
··· FREQOUT 2,1,irFrequency
··· irDetectRight = IN0
··· distanceRight = distanceRight + irDetectRight
··· PAUSE 5
· NEXT
· RETURN
' SEND PULSE
Send_Pulse:
· PULSOUT 13,pulseLeft
· PULSOUT 12,pulseRight
· PAUSE 5
· RETURN
' WHISKER SUBS
Forward_Pulse:
· PULSOUT 13, 850
· PULSOUT 12, 650
· PAUSE 20
· RETURN
Turn_left:
· FOR pulseCount = 0 TO 20
··· PULSOUT 13, 650
··· PULSOUT 12, 650
··· PAUSE 20
· NEXT
· RETURN
Turn_Right:
· FOR pulseCount = 0 TO 20
··· PULSOUT 13, 850
··· PULSOUT 12, 850
··· PAUSE 20
· NEXT
· RETURN
Back_up:
· FOR pulseCount = 0 TO 10
··· PULSOUT 13, 650
··· PULSOUT 12, 850
··· PAUSE 20
· NEXT
· RETURN
Comments
PULSOUT 13, 790
PULSOUT 12, 790
LOOP UNTIL (irdetectleft = 0) OR (irdetectright = 0)
·