Shop OBEX P1 Docs P2 Docs Learn Events
[Semi-Emergency] Line Tracking & Light Finding with BS2 — Parallax Forums

[Semi-Emergency] Line Tracking & Light Finding with BS2

Jimmy HJimmy H Posts: 3
edited 2008-05-28 04:16 in BASIC Stamp
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!

Comments

  • P!-RoP!-Ro Posts: 1,189
    edited 2008-05-28 04:16
    You should add some info on what is wrong with your program and what it does. It makes it much easier to fix for you. I am just quote "a little kid" myself, but I will try to help myself, probably not soon enough for you tomorrow though. If you improve it you are more likely to get a response. Also, if you leave messages in your program telling us of what that section does it will make it much easier. Hope you do well tomorrow, and sorry if I can't provide more help in time, maybe someone smarter than me will give you help before your class.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Pi Guy
Sign In or Register to comment.