Shop OBEX P1 Docs P2 Docs Learn Events
Need help with son's BS2 robot — Parallax Forums

Need help with son's BS2 robot

dandeandandean Posts: 3
edited 2009-03-20 15:43 in BASIC Stamp
My 10 year old son has been working on a robot with BS2 and we have hit a wall.· He has three servos that turn correctly when he pushes the little·red reset button.··

The problem -
He has push buttons that light up the LED on the BS2 when they are pushed, but his computer program doesn't communicate with them no matter what he tries or changes in the program.·· He wants to program his robot to move depending on which push button is being pushed.·· Any help or suggestions would be greatly appreciated!
Here is the program he is currently trying to use without success:


COUNTER·· VAR·· Word

IF (IN5 = 1) THEN GOSUB FORWARD

FORWARD:

FOR COUNTER 1 TO 10

PULSOUT 15, 2000

PAUSE 20

FOR COUNTER 1 TO 10

PUSOUT 13, 2000

PAUSE 20


·

Comments

  • JDJD Posts: 570
    edited 2009-03-19 20:09
    Dandean,

    It looks like you have only 1 button in your code; looks like PIN 15. For a forward movement you would need to move both servos otherwise it would just go in circles.

    There is a excellent example of how to control the Boe-Bot in the text, Robotics with the Boe-Bot·(chapters 2 and 4); that should help you get started with movement.·For help with programming button control there is What's A Microcontroller?·(chapter 3)

    If you want to post your .BS2 code we can try to suggest some changes, but with these two books you can get a better understanding of how the program operates.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Respectfully,


    Joshua Donelson
    www.parallax.com
  • dandeandandean Posts: 3
    edited 2009-03-19 22:46
    Thanks for your reply. Below is the complete program. We have the servos moving together forward and backward with no problem. We will check out the links you suggested. We are using "What's A Microcontroller" and have done what it says in the book but it isn't helping. We don't know what we are doing wrong. When my son pushes a push button the stamp looks like it is resetting each time (the running light will shut off while the button is being pressed and everything that is running stops. The buttons are not plugged into pin 4.) Can you tell what should be different in the code or what is missing? Thank you very much!!!


    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    counter VAR Word

    main:
    GOSUB forward
    IF IN5 = 1 THEN GOSUB backward
    IF IN6 = 1 THEN GOSUB forward
    GOTO main

    forward:
    FOR COUNTER = 1 TO 10
    PULSOUT 15, 2000
    PAUSE 20
    PULSOUT 13, 700
    PAUSE 10
    NEXT
    RETURN

    backward:
    FOR counter = 1 TO 10
    PULSOUT 13, 2000
    PAUSE 20
    PULSOUT 15, 700
    NEXT
    RETURN

    END
  • JDJD Posts: 570
    edited 2009-03-19 23:03
    dandean,

    If the power shuts off when you press the button, it sounds like the button is wired incorrectly;·shorting the power and ground to reset the BASIC Stamp.

    I checked the code and it looks like the Boe-Bot moves forward, then checks to see if button·5 or·button 6 is pressed; and if not it will continue forward.·However, it seems like you want to wait until a button is pressed before it moves; is that correct? Is no, please see the attached file.

    The attached program program will do those actions. Stand still until a button is pressed, and then move forward or backward.·You would want the buttons to have pull-down resisitors (10 k&#937[noparse];)[/noparse] on the buttons so you dont get a false trigger. The values for the pulses should be between 1 to 2 milliseconds (ms); which for the BASIC Stamp 2 would be between 500 and 1000 for the pulse value.

    I hope this helps, feel free to ask for clarification.





    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Respectfully,


    Joshua Donelson
    www.parallax.com
  • dandeandandean Posts: 3
    edited 2009-03-20 15:28
    Thank you for all of your help! We got it moving!
    The attached file did help.

    We have another quick question:

    Can we put a DO LOOP within a label? I want it to go forward until a button is pushed and then go backwards on its own. The robot is a square robot with six push buttons - one on each corner and one on the front and back. There is also a button that we will push to activate the program (pin 2).
  • JDJD Posts: 570
    edited 2009-03-20 15:43
    dandean,

    As long as you have the routine check for the buttons within the DO...LOOP, then yes you could do that.

    For Example:

    Main:
    ·DO
    ·· PULSOUT...
    ·· PULSOUT...
    ·· PAUSE·15
    ·· *check buttons to see if any are pressed; could be done with IF...THEN command*
    ·LOOP

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Respectfully,


    Joshua Donelson
    www.parallax.com
Sign In or Register to comment.