[bs2] [pbasic 2.5] qti program help
Odd_Sam
Posts: 1
Ok so just so you understand what the issue is, I am trying to use qti sensors to detect how many times it finds a black line. I am using a modded version of the default program (LineFollowWithCheckQtis.bs2) here is what the program looks like
For whatever reason, everytime it runs over a black line it turns around regardless of whether the line it's crossed is·the first line·or the second line. (it should ignore the first turn around on the second, and ignore the third turn around on the fourth, etc.)
If you need more information but can help let me know I'll be checking this thread often for responses.
Thanks for any help.
I am trying to make it use a counter so that every other black line it crosses it turns around. (noting that I am doing this when the qti's read 1 all the way across. (%1111)Code:
' LineFollowWithCheckQtis.bs2
' Navigates based on values acquired with the Check_Qtis subroutine.
' {$STAMP BS2}
' {$PBASIC 2.5}
qtis VAR Nib ' qti black/white states
counter VAR Word
counter1 VAR Word
counter1=1
OUTB = %1111 ' Set OUTB bits to 1
DO ' Main DO...LOOP
GOSUB Check_Qtis ' Get QTI states
SELECT qtis ' Control servo speeds/directions
CASE %1000 ' Rotate right
PULSOUT 13, 650
PULSOUT 12, 650
CASE %1100 ' Pivot right
PULSOUT 13, 750
PULSOUT 12, 650
'CASE %1110
CASE %0100 ' Curve right
PULSOUT 13, 800
PULSOUT 12, 650
CASE %0110 ' Straight ahead
PULSOUT 13, 850
PULSOUT 12, 650
CASE %0010 ' Curve left
PULSOUT 13, 850
PULSOUT 12, 700
'CASE %0111
CASE %0011 ' Pivot left
PULSOUT 13, 850
PULSOUT 12, 750
CASE %0001 ' Rotate left
PULSOUT 13, 850
PULSOUT 12, 850
CASE %1111
PULSOUT 13, 850
PULSOUT 12, 650
· IF counter1 = 2 THEN
· GOSUB turn
· counter1 = 0
· END
· ELSEIF counter1 = 1 THEN
· GOSUB straight
· counter1 = counter1 + 1
· ENDIF
ENDSELECT
LOOP
Check_Qtis:' Result -> qtis variable. 0 means white surface, 1 means black surface.
DIRB = %1111 ' P7..P4 -> output
PAUSE 0 ' Delay = 230 us
DIRB = %0000 ' P7..P4 -> input
PAUSE 0 ' Delay = 230 us
' PULSOUT UnusedPin, 0 ' Delays = 208 + (Duration*2) us
qtis = INB ' Store QTI outputs in INB
RETURN
turn:
FOR counter = 1 TO 220
····· PULSOUT 13, 650
····· PULSOUT 12, 850
NEXT
RETURN
straight:
PULSOUT 13, 850
PULSOUT 12, 650
PAUSE 10
RETURN
For whatever reason, everytime it runs over a black line it turns around regardless of whether the line it's crossed is·the first line·or the second line. (it should ignore the first turn around on the second, and ignore the third turn around on the fourth, etc.)
If you need more information but can help let me know I'll be checking this thread often for responses.
Thanks for any help.
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen