Need help with son's BS2 robot
dandean
Posts: 3
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
·
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
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
' {$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
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Ω[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
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).
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