Shop OBEX P1 Docs P2 Docs Learn Events
Can someone help me figure out what is wrong with my code? (newbie) — Parallax Forums

Can someone help me figure out what is wrong with my code? (newbie)

mlpnkomlpnko Posts: 1
edited 2011-06-29 15:19 in General Discussion
So, I need my boe bot to both follow a black line and turn when it reaches a hatch mark, then sense objects. My line following is having issues. Here is the code-

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

rawDist VAR Word ' raw measurement
inches VAR Word
cm VAR Word
x VAR Word
qtis VAR Nib

OUTB = %1111




top:
DO

SELECT qtis

CASE %1000
PULSOUT 13, 650
PULSOUT 12, 650
CASE %1100
PULSOUT 13, 750
PULSOUT 12, 650
CASE %0100
PULSOUT 13, 800
PULSOUT 12, 650
CASE %0110
PULSOUT 13, 850
PULSOUT 12, 650
CASE %0010
PULSOUT 13, 850
PULSOUT 12, 700
CASE %0011
PULSOUT 13, 850
PULSOUT 12, 750
CASE %0001
PULSOUT 13, 850
PULSOUT 12, 850
CASE %1111
GOSUB Hash


CASE ELSE
PULSOUT 13, 850
PULSOUT 12, 650
ENDSELECT

DEBUG BIN4 ? qtis, CRSRUP

LOOP

Hash:
FOR x = 0 TO 100
PULSOUT 13, 650
PULSOUT 12, 850
NEXT

FOR x = 0 TO 2000

Ping PIN 10

#SELECT $STAMP
#CASE BS2, BS2E
Trigger CON 5 ' trigger pulse = 10 uS
Scale CON $200 ' raw x 2.00 = uS
#CASE BS2SX, BS2P, BS2PX
Trigger CON 13
Scale CON $0CD ' raw x 0.80 = uS
#CASE BS2PE
Trigger CON 5
Scale CON $1E1 ' raw x 1.88 = uS
#ENDSELECT
RawToIn CON 889 ' 1 / 73.746 (with **)
RawToCm CON 2257 ' 1 / 29.034 (with **)
IsHigh CON 1 ' for PULSOUT
IsLow CON 0


Reset:
DEBUG CLS,
"Parallax PING))) Sonar", CR, ' setup report screen
"======================", CR,
CR,
"Time (uS)..... ", CR,
"Inches........ ", CR,
"Centimeters... "

Main:
DO
GOSUB Get_Sonar ' get sensor value
inches = rawDist ** RawToIn ' convert to inches
cm = rawDist ** RawToCm ' convert to centimeters
DEBUG CRSRXY, 15, 3, ' update report screen
DEC rawDist, CLREOL,
CRSRXY, 15, 4,
DEC inches, CLREOL,
CRSRXY, 15, 5,
DEC cm, CLREOL
PAUSE 100
IF inches > 9 THEN ' basketball
HIGH 15
LOW 14
LOW 13
ENDIF
IF 5 = inches OR inches = 4 OR inches = 3 THEN ' cone
HIGH 13
LOW 15
LOW 14
ENDIF
IF inches = 6 OR 7 OR 8 THEN ' football
HIGH 14
LOW 15
LOW 13
ENDIF
LOOP




Get_Sonar:
Ping = IsLow ' make trigger 0-1-0
PULSOUT Ping, Trigger ' activate sensor
PULSIN Ping, IsHigh, rawDist ' measure echo pulse
rawDist = rawDist */ Scale ' convert to uS
rawDist = rawDist / 2 ' remove return trip
RETURN





DEBUG CRSRX, 8, "FMMF", CR, 'Display bit positions
CRSRX, 8, "LLRR", CR
NEXT




RETURN





GOTO top


THANK YOU(:

Comments

  • ercoerco Posts: 20,259
    edited 2011-06-29 13:18
    "Having issues" is purposefully vague, counselor! So what specifically is the problem you're having? We can only help if you give us more info.

    Where did you get that code come from? Did you read whatever article came with the code for details? Are you using a stock BoeBot with stock servos? Are your batteries fresh? Are your servos centered (stopped) at 750? Is your bot overshooting or undershooting? You may have to tweak the pulsout values.
  • FranklinFranklin Posts: 4,747
    edited 2011-06-29 15:19
    It also helps if you wrap your code with "CODE" tags available if you "Go Advanced" in your post. You can also go back and edit your code.
Sign In or Register to comment.