Shop OBEX P1 Docs P2 Docs Learn Events
Obstacle course navigation — Parallax Forums

Obstacle course navigation

dipmdipm Posts: 2
edited 2012-04-23 17:29 in BASIC Stamp
I am making a robot that has to navigate an obstacle course that contains barriers and stays within a tape boundary. I attached the code I am using and I do not know how to make it work. I am using IR dectors for obstacle avoidance and photoresistors to navigate and stay within the boundaries. When I apply the codes individually they both work, but when I try and combine them only the IR obstacle avoidance works and the photoresistors run. PLEASE help me fix this code, I need to race the robot by the end of this week!!

Thanks

Here is the code, I am having trouble adding it as an attachment:



' Robotics with the Boe-Bot - fastIRRoaming.bs2
' {$Stamp BS2}
' {$PBASIC 2.5}



pulseLeft VAR Word
pulseRight VAR Word
irDetectLeft VAR Bit
irDetectRight VAR Bit
timeLeft VAR Word
timeRight VAR Word
LeftFloor CON 17
RightFloor CON 12
LeftTape CON 20
RightTape CON 15
LeftAvg CON leftFloor + LeftTape / 2
RightAvg CON RightFloor + RightTape / 2





FREQOUT 4, 2000, 3000

Main:
DO
GOSUB Check_IRs
LOOP WHILE (irDetectLeft = 0) AND (irDetectRight = 0)
DO

GOSUB IRDetect


LOOP








IRDetect:
DO
FREQOUT 8, 1, 38500
irDetectLeft = IN9
FREQOUT 2, 1, 38500
irDetectRight = IN0

HIGH 6
PAUSE 3
RCTIME 6, 1, timeLeft

HIGH 3
PAUSE 3
RCTIME 3, 1, timeRight
RETURN

IF (irDetectLeft = 0) AND (irDetectRight = 0) AND (timeLeft > LeftAvg) AND (timeRight > RightAvg) THEN
pulseLeft = 650
pulseRight = 850
ELSEIF (irDetectLeft = 0) OR (timeLef
t > LeftAvg)THEN
pulseLeft = 850
pulseRight = 850
ELSEIF (irDetectRight = 0)OR (timeRight >RightAvg) THEN
pulseLeft = 650
pulseRight = 650
ELSE
pulseLeft = 850
pulseRight = 650
ENDIF
PULSOUT 13, pulseLeft
PULSOUT 12, PulseRight
PAUSE 5

GOSUB Check_IRs

LOOP
RETURN

'Check_IRs:
' FREQOUT 8, 1, 38500
' irDetectLeft = IN9
' FREQOUT 2, 1, 38500
' irDetectRight = IN0
' RETURN

Comments

  • ercoerco Posts: 20,256
    edited 2012-04-23 14:53
    You have two syntax errors that the editor will find:

    ELSEIF (irDetectLeft = 0) OR (timeLef

    needs to be joined with the following line.

    Of course you have commented out the whole Check_IRs subroutine, so that's another syntax error.

    Looks like the trouble lies in the following segment, which will never execute; there's no way in. I'm guessing that's your new replacement for the Check_IRs subroutine, so figure out how to use it and get to it.
    IF (irDetectLeft = 0) AND (irDetectRight = 0) AND (timeLeft > LeftAvg) AND (timeRight > RightAvg) THEN
    pulseLeft = 650
    pulseRight = 850
    ELSEIF (irDetectLeft = 0) OR (timeLef
    t > LeftAvg)THEN
    pulseLeft = 850
    pulseRight = 850
    ELSEIF (irDetectRight = 0)OR (timeRight >RightAvg) THEN
    pulseLeft = 650
    pulseRight = 650
    ELSE
    pulseLeft = 850
    pulseRight = 650
    ENDIF
    PULSOUT 13, pulseLeft
    PULSOUT 12, PulseRight
    PAUSE 5
    
    GOSUB Check_IRs
    
    LOOP
    RETURN
    
  • dipmdipm Posts: 2
    edited 2012-04-23 17:29
    Thanks erco, I copied the wrong code, I changed it around and it goes into the Do Loop to roam, but it only goes off of IR sensors and does not use the photoresistor navigation. I tried making the photoresistor lines into ELSEIF lines but that did not work either.


    ' Robotics with the Boe-Bot - fastIRRoaming.bs2
    ' {$Stamp BS2}
    ' {$PBASIC 2.5}



    pulseLeft VAR Word
    pulseRight VAR Word
    irDetectLeft VAR Bit
    irDetectRight VAR Bit
    timeLeft VAR Word
    timeRight VAR Word
    LeftFloor CON 17
    RightFloor CON 12
    LeftTape CON 20
    RightTape CON 15
    LeftAvg CON leftFloor + LeftTape / 2
    RightAvg CON RightFloor + RightTape / 2





    FREQOUT 4, 2000, 3000

    Main:
    DO
    GOSUB Check_IRs
    LOOP WHILE (irDetectLeft = 0) AND (irDetectRight = 0)
    DO

    GOSUB IRDetect
    GOSUB Test_photoresistors

    LOOP





    IRDetect:
    DO
    FREQOUT 8, 1, 38500
    irDetectLeft = IN9
    FREQOUT 2, 1, 38500
    irDetectRight = IN0

    HIGH 6
    PAUSE 3
    RCTIME 6, 1, timeLeft

    HIGH 3
    PAUSE 3
    RCTIME 3, 1, timeRight
    RETURN

    IF (irDetectLeft = 0) AND (irDetectRight = 0) AND (timeLeft > LeftAvg) AND (timeRight > RightAvg) THEN
    pulseLeft = 650
    pulseRight = 850
    ELSEIF (irDetectLeft = 0) OR (timeLeft > LeftAvg)THEN
    pulseLeft = 850
    pulseRight = 850
    ELSEIF (irDetectRight = 0)OR (timeRight >RightAvg) THEN
    pulseLeft = 650
    pulseRight = 650
    ELSE
    pulseLeft = 850
    pulseRight = 650
    ENDIF
    PULSOUT 13, pulseLeft
    PULSOUT 12, PulseRight
    PAUSE 5

    GOSUB Check_IRs
    LOOP
    RETURN

    Check_IRs:
    FREQOUT 8, 1, 38500
    irDetectLeft = IN9
    FREQOUT 2, 1, 38500
    irDetectRight = IN0
    RETURN

    Test_photoresistors:

    HIGH 6
    PAUSE 3
    RCTIME 6, 1, timeLeft

    HIGH 3
    PAUSE 3
    RCTIME 3, 1, timeRight
    RETURN
Sign In or Register to comment.