Shop OBEX P1 Docs P2 Docs Learn Events
Program resets — Parallax Forums

Program resets

onlymortalonlymortal Posts: 2
edited 2010-08-28 19:25 in BASIC Stamp
I modified a boe-bot to use a front axle for steering instead of the two wheel system that came with the kit. The problem is that the program has an error and reset's the program after the turning subroutine. I posted one of the subroutines below but can't find the problem. Does anyone know why the car is reseting?

starboard:
DEBUG "starboard",CR
PULSOUT 14, 615+pi 'turn right subroutine
PULSOUT 13, 650
PULSOUT 12, 830
PAUSE 20
pi=pi+5
IF(IN5=0)AND(IN7=1)THEN
GOSUB starboard
ELSE
GOSUB starboardc
ENDIF
RETURN

starboardc:
DEBUG "starboard counter",CR
FOR delta=1 TO pi STEP 6
PULSOUT 14, 615+pi-delta 'return wheels from right turn subroutine
PULSOUT 13, 650
PULSOUT 12, 830
PAUSE 20
NEXT
RETURN

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-28 16:31
    It's resetting because you have too many GOSUBs without a RETURN or you have a RETURN without a GOSUB. I see that your "starboard" routine calls the "starboard" routine sometimes. That's called recursion and doesn't work very well on the Stamp because the return stack is quite small. I'm not sure what you want to do, but maybe a GOTO will work better than a GOSUB.
  • onlymortalonlymortal Posts: 2
    edited 2010-08-28 17:31
    thank you, I'll try doing that instead.
  • ercoerco Posts: 20,256
    edited 2010-08-28 19:25
    I always learn something new from Professor Green: recursion! Thank you for that, Mike!

    One other possibility is that your servo is pulling too much power, which may be dropping your battery voltage and causing a brownout. Much depends on your mechanical construction and how much force is required to turn your axle. You could isolate this problem by giving the servos their own 6V battery supply, in which case you must connect both batteries negative leads together, but you knew that already. :)
Sign In or Register to comment.