Shop OBEX P1 Docs P2 Docs Learn Events
Find My Error Please — Parallax Forums

Find My Error Please

marcboebotmarcboebot Posts: 5
edited 2013-09-17 09:40 in BASIC Stamp
For school, I am programming a boebot to go through a maze and up a ramp autonomously. I am using an accelerometer sensor to help my boebot go up the ramp. I need my boebot to stop when it gets to the top of the ramp. Right now, I have it programmed so that if y > 2500, gosub foward, and if y < 2500 stop. But I need to add this programming to the programming of the infrared sensors I am using. I don't want the boebot to stop moving until after it goes up the ramp, but with the programming I have right now, it won't begin moving unless it starts at a tilt. Is there a way to use an If Then command so I can say if y > 2500 and then y < 2500 then stop? Or is there another way to program it to only stop once its reached the top of the ramp?

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2013-09-12 18:56
    Make a Flag Bit (that could be a Bit variable) which would be asserted when the tilt is detected.
    Then once you test for a level condition and the Flag Bit has been asserted the inference would be that it's level again (at the top of the ramp).
  • marcboebotmarcboebot Posts: 5
    edited 2013-09-13 05:48
    I am not familiar with the Flag Bit. Could you elaborate a little on how I could program that to work or someplace that explains it?
  • Mike GreenMike Green Posts: 23,101
    edited 2013-09-13 06:40
    PJ wasn't really referring to "The Flag Bit", but meant "a flag bit" ... a variable with a value of 0 or 1 that just remembers a yes / no item for you. You'd declare a variable in your program like this:
    stopMoving   var   bit
    
    Somewhere in your program's initialization, you'd add "stopMoving = 0". When you detect something where you want the BoeBot to stop at the top of the ramp, you'd add "stopMoving = 1". In your code for checking for the top of the ramp, you might have something like
    if y < 2500 and stopMoving = 1 then stop   'we've reached the top
    
  • TinkersALotTinkersALot Posts: 535
    edited 2013-09-13 07:37
    wondering :

    if y < 2500 OR stopMoving = 1 then stop
  • GadgetmanGadgetman Posts: 2,436
    edited 2013-09-17 01:48
    No...

    the OR means it wuld stop as soon as one of the conditions are fulfilled.
  • marcboebotmarcboebot Posts: 5
    edited 2013-09-17 06:15
    For school, we have to create an autonomous boebot that will go through a maze and up a ramp and then stop. Our programming works with only the programming for the infrared sensors but we cannot figure out the coding for the accelarmeter. Here is our programming. Could someone please help us find our flaws as to why it doesn't work. When we plug it in, our robot will go forward about 6 inches and then stop and not do anything.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    
    x VAR Word
    y VAR Word
    stopMoving VAR Bit
    counter VAR Byte
    
    
    DO
    
    
    PULSIN 6, 1, x
    PULSIN 7, 1, y
    stopMoving = 0
    
    
    IF y < 2500 THEN
    GOSUB forward
    ELSEIF y > 2500 AND stopMoving = 1 THEN
    STOP
    ENDIF
    STOP
    LOOP
    
    
    forward:
    FOR counter = 1 TO 30
    PULSOUT 12, 650
    PULSOUT 13, 850
    PAUSE 20
    NEXT
    RETURN
    
    
    backup:
    FOR counter = 1 TO 20
    PULSOUT 12, 850
    PULSOUT 13, 650
    PAUSE 20
    NEXT
    RETURN
    
    
    left:
    FOR counter = 1 TO 15
    PULSOUT 12, 650
    PULSOUT 13, 650
    PAUSE 20
    NEXT
    RETURN
    
    
    right:
    FOR counter = 1 TO 15
    PULSOUT 12, 850
    PULSOUT 13, 850
    PAUSE 20
    NEXT
    RETURN
    
  • Mike GMike G Posts: 2,702
    edited 2013-09-17 07:00
    It looks like the block of code below. The logic STOPs code execution regardless of the IF condition. Plus no call is ever made to backup, left, or right. Only forward is invoked.
    	IF y < 2500 THEN
    		GOSUB forward
    	ELSEIF y > 2500 AND stopMoving = 1 THEN
    		STOP
    	ENDIF
    
    	STOP
    	LOOP
    
    "BS2 wrote:
    STOP prevents the BASIC Stamp from executing any further instructions
    until it is reset. The following actions will reset the BASIC Stamp:
  • marcboebotmarcboebot Posts: 5
    edited 2013-09-17 07:11
    Is there a way for us to redo that portion of the programming so that it works? We need it to stop after it goes up the ramp, but we don't know how to fit that into the Infrared Sensor programming. It has to go through a maze before it goes up the ramp, so it can't stop until after the y has decreased and then increased again.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-09-17 07:55
    First of all, you have to remove the 2nd STOP. That STOP tells the program to stop regardless of the conditions and you don't want that.

    stopMoving is a variable that keeps track of the state of the program. 0 is the initial state. 1 should be the state that y has decreased. The 3rd state is when y has decreased then increased which is caught by the IF statement. Your program doesn't have to remember the state because it stops at that point. Where do you set stopMoving to 1?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-09-17 09:34
    It seems this discussion of going on in two threads now, which may be causing confusion for some.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-09-17 09:40
    The two threads have been merged. Please keep all discussion on this topic to this thread.
Sign In or Register to comment.