Shop OBEX P1 Docs P2 Docs Learn Events
BoeBot doing the OPPOSITE — Parallax Forums

BoeBot doing the OPPOSITE

USMCinfinityUSMCinfinity Posts: 150
edited 2010-08-31 08:38 in BASIC Stamp
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

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-29 20:04
    So what do you think is going wrong? Have you used DEBUG statements to see what's going on? If the BoeBot is doing exactly the opposite from what you want, where do you think you should look?
  • USMCinfinityUSMCinfinity Posts: 150
    edited 2010-08-29 20:11
    Well, the circuit design is good, maybe the constant definition is wrong? it said to replace those (textbook) with the ones I got from "calibrating" the photoresistors...which I didn't do :-D
  • TinkersALotTinkersALot Posts: 535
    edited 2010-08-29 20:34
    What if left is right, will forward be back?
  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-29 20:52
    "what if the constant definition is wrong?"

    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?
  • USMCinfinityUSMCinfinity Posts: 150
    edited 2010-08-30 17:52
    Ok this is the update code with the right constants, but it is still going away from the light, in ambient light it is going in circles (in the same place) how would I go to STOP the servos while in ambient light?

    ' {$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
  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-30 17:58
    If the RCTIME times are both over the thresholds (high resistance = low light level), the servos should stop (according to your program) if they're calibrated as described in Robotics with the BoeBot. So, what RCTIME values are you getting under what circumstances?
  • USMCinfinityUSMCinfinity Posts: 150
    edited 2010-08-30 18:03
    How can I get the RCTIME Values?
  • USMCinfinityUSMCinfinity Posts: 150
    edited 2010-08-30 18:06
    When I'm not pointing the flashlight it starts just circling in the same spot, also its weird, if I point the flaghtlight from behind of the boebot it will follow it..
  • FranklinFranklin Posts: 4,747
    edited 2010-08-30 19:46
    Sounds like left and right servos reversed like tinkersalot said. Have you checked that?
  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-30 22:12
    You monitor values in the program (like the values returned by the RCTIME statements) by using DEBUG statements to display them.
  • USMCinfinityUSMCinfinity Posts: 150
    edited 2010-08-31 08:38
    Wow, that was it, the servos were connected wrongly :(. Thanks for the help guys!
Sign In or Register to comment.