Help with pbasic robot programming

Thread Starter

dean93

Joined Mar 1, 2015
2
I hate to say that I'm not much of a programer don't really have the vision for it i guess but i need help because i need to develop a program for a boe bot that finds an empty parking space and park in it, then it must back out and reverse into the parking space. The code I'm providing is only for IR and whisker sensors not really sure where to go from here. Any help is gladly appreciated thank you.

' {$STAMP BS2}
' {$PBASIC 2.5}

irDetectLeft VAR Bit
irDetectRight VAR Bit
pulseCount VAR Byte

FREQOUT 4, 2000, 3000 ' Signal program start/reset.

DO

FREQOUT 8, 1, 38500 ' Store IR detection values in
irDetectLeft = IN9 ' bit variables.

FREQOUT 2, 1, 38500
irDetectRight = IN0

IF(irDetectLeft = 0) AND (irDetectRight = 0) AND (IN5 = 0) AND (IN7 = 0) THEN
GOSUB BACKUP ' Both IR pairs detect obstacle
GOSUB LEFT ' Back up & U-turn (left twice)
GOSUB LEFT
ELSEIF (irDetectLeft = 0) THEN ' Left IR pair detects
GOSUB BACKUP ' Back up & turn right
GOSUB RIGHT
ELSEIF (irDetectRight = 0) THEN ' Right IR pair detects
GOSUB BACKUP ' Back up & turn left
GOSUB LEFT
ELSE ' Both IR pairs 1, no detects
GOSUB FORWARD ' Apply a forward pulse and check again
ENDIF
LOOP

FORWARD:
PULSOUT 13, 850 ' FORWARD
PULSOUT 12, 650
PAUSE 200

RETURN

BACKUP:
FOR pulseCount = 0 TO 20 ' BACKWARDS
PULSOUT 13, 650
PULSOUT 12, 850
PAUSE 200
NEXT
RETURN

LEFT:
FOR pulseCount = 0 TO 20 ' LEFT ABOUT 90 DEGREES
PULSOUT 13, 650
PULSOUT 12, 650
PAUSE 200
NEXT
RETURN

RIGHT:
FOR pulseCount = 0 TO 20 ' RIGHT ABOUT 90 DEGREE
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 200
NEXT
RETURN
 

Thread Starter

dean93

Joined Mar 1, 2015
2
I hate to say that I'm not much of a programer don't really have the vision for it i guess but i need help because i need to develop a program for a boe bot that finds an empty parking space and park in it, then it must back out and reverse into the parking space. The code I'm providing is only for IR and whisker sensors not really sure where to go from here. Any help is gladly appreciated thank you.

' {$STAMP BS2}
' {$PBASIC 2.5}

irDetectLeft VAR Bit
irDetectRight VAR Bit
pulseCount VAR Byte

FREQOUT 4, 2000, 3000 ' Signal program start/reset.

DO

FREQOUT 8, 1, 38500 ' Store IR detection values in
irDetectLeft = IN9 ' bit variables.

FREQOUT 2, 1, 38500
irDetectRight = IN0

IF(irDetectLeft = 0) AND (irDetectRight = 0) OR (IN5 = 0) AND (IN7 = 0) THEN
GOSUB BACKUP ' Both IR pairs detect obstacle
GOSUB LEFT ' Back up & U-turn (left twice)
GOSUB LEFT
ELSEIF (irDetectLeft = 0)OR(IN5 = 0) THEN ' Left IR pair detects
GOSUB BACKUP ' Back up & turn right
GOSUB RIGHT
ELSEIF (irDetectRight = 0)OR(IN7 = 0) THEN ' Right IR pair detects
GOSUB BACKUP ' Back up & turn left
GOSUB LEFT
ELSE ' Both IR pairs 1, no detects
GOSUB FORWARD ' Apply a forward pulse and check again
ENDIF
LOOP

FORWARD:
PULSOUT 13, 850 ' FORWARD
PULSOUT 12, 650
PAUSE 200

RETURN

BACKUP:
FOR pulseCount = 0 TO 20 ' BACKWARDS
PULSOUT 13, 650
PULSOUT 12, 850
PAUSE 200
NEXT
RETURN

LEFT:
FOR pulseCount = 0 TO 20 ' LEFT ABOUT 90 DEGREES
PULSOUT 13, 650
PULSOUT 12, 650
PAUSE 200
NEXT
RETURN

RIGHT:
FOR pulseCount = 0 TO 20 ' RIGHT ABOUT 90 DEGREE
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 200
NEXT
RETURN
 
Top