BoeBot doing the OPPOSITE
USMCinfinity
Posts: 150
Ok, so I'm trying to do the light follower with the following code, but he is going AWAY from the light.
' {$STAMP BS2}
' {$PBASIC 2.5}
' Light Follower
DEBUG "PROGRAM RUNNING"
'
[CONSTANTS]
LeftAmbient CON 108
RightAmbient CON 114
LeftBright CON 20
RightBright CON 22
'
[Average]
LeftThreshold CON LeftBright + LeftAmbient / 2 * 5 / 8
RightThreshold CON RightBright + RightAmbient / 2 * 5 / 8
'
[Variables]
timeLeft VAR Word
timeRight VAR Word
'
[Initialization]
FREQOUT 4, 2000, 3000
'
[Main]
DO
GOSUB Test_Photoresistors
GOSUB Navigate
LOOP
'
[subroutine test]
Test_Photoresistors:
HIGH 6
PAUSE 3
RCTIME 6,1,timeLeft
HIGH 3
PAUSE 3
RCTIME 3,1,timeRight
RETURN
'
[subroutine navigate]
Navigate:
IF (timeLeft < LeftThreshold) AND (timeRight < RightThreshold) THEN
PULSOUT 13, 850
PULSOUT 12, 650
ELSEIF (timeLeft < LeftThreshold) THEN
PULSOUT 13, 700
PULSOUT 12, 700
ELSEIF (timeRight < RightThreshold) THEN
PULSOUT 13, 800
PULSOUT 12, 800
ELSE
PULSOUT 13, 750
PULSOUT 12, 750
ENDIF
PAUSE 20
RETURN
' {$STAMP BS2}
' {$PBASIC 2.5}
' Light Follower
DEBUG "PROGRAM RUNNING"
'
[CONSTANTS]
LeftAmbient CON 108
RightAmbient CON 114
LeftBright CON 20
RightBright CON 22
'
[Average]
LeftThreshold CON LeftBright + LeftAmbient / 2 * 5 / 8
RightThreshold CON RightBright + RightAmbient / 2 * 5 / 8
'
[Variables]
timeLeft VAR Word
timeRight VAR Word
'
[Initialization]
FREQOUT 4, 2000, 3000
'
[Main]
DO
GOSUB Test_Photoresistors
GOSUB Navigate
LOOP
'
[subroutine test]
Test_Photoresistors:
HIGH 6
PAUSE 3
RCTIME 6,1,timeLeft
HIGH 3
PAUSE 3
RCTIME 3,1,timeRight
RETURN
'
[subroutine navigate]
Navigate:
IF (timeLeft < LeftThreshold) AND (timeRight < RightThreshold) THEN
PULSOUT 13, 850
PULSOUT 12, 650
ELSEIF (timeLeft < LeftThreshold) THEN
PULSOUT 13, 700
PULSOUT 12, 700
ELSEIF (timeRight < RightThreshold) THEN
PULSOUT 13, 800
PULSOUT 12, 800
ELSE
PULSOUT 13, 750
PULSOUT 12, 750
ENDIF
PAUSE 20
RETURN
Comments
How about doing some debugging? Put in DEBUG statements to show the threshold values and the values you're getting from the photoresistors. See how the values change when you change the amount of light reaching them. Are the values coming out the way you expect them?
' {$STAMP BS2}
' {$PBASIC 2.5}
' Light Follower
DEBUG "PROGRAM RUNNING"
'
[CONSTANTS]
LeftAmbient CON 72
RightAmbient CON 73
LeftBright CON 1
RightBright CON 2
'
[Average]
LeftThreshold CON LeftBright + LeftAmbient / 2 * 5 / 8
RightThreshold CON RightBright + RightAmbient / 2 * 5 / 8
'
[Variables]
timeLeft VAR Word
timeRight VAR Word
'
[Initialization]
FREQOUT 4, 2000, 3000
'
[Main]
DO
GOSUB Test_Photoresistors
GOSUB Navigate
LOOP
'
[subroutine test]
Test_Photoresistors:
HIGH 6
PAUSE 3
RCTIME 6,1,timeLeft
HIGH 3
PAUSE 3
RCTIME 3,1,timeRight
RETURN
'
[subroutine navigate]
Navigate:
IF (timeLeft < LeftThreshold) AND (timeRight < RightThreshold) THEN
PULSOUT 13, 850
PULSOUT 12, 650
ELSEIF (timeLeft < LeftThreshold) THEN
PULSOUT 13, 700
PULSOUT 12, 700
ELSEIF (timeRight < RightThreshold) THEN
PULSOUT 13, 800
PULSOUT 12, 800
ELSE
PULSOUT 13, 750
PULSOUT 12, 750
ENDIF
PAUSE 20
RETURN