Start / Stop wheel kit test code
mhenyon
Posts: 3
················· '······································································· '
Hello everyone. I am using this piece of test code (below)·to turn my motor wheel kit using my board of ed stamp. It works only when the reset button is pushed.
I have setup a switch using·a button with the button active low, but when the button is pushed high, the·program·doesn't run.
I don't know why it won't run in a loop waiting for a button push to activate the program.
The purpose of this is to use the motor to turn an auger that delivers chemical to rainwater barrel·when a rain gauge bucket magnetic switch momentarily closes (the "button") when the bucket flops.
Thanks, Mike
' {$STAMP BS2}
' {$PBASIC 2.5}
'--- Command Value Constants ---
QPOS········ CON····· $08··········· 'Query Position
QSPD········ CON····· $10··········· 'Query Speed
CHFA········ CON····· $18··········· 'Check for Arrival
TRVL········ CON····· $20··········· 'Travel Number of Positions
CLRP········ CON····· $28··········· 'Clear Position
SREV········ CON····· $30··········· 'Set Orientation as Reversed
STXD········ CON····· $38··········· 'Set TX Delay
SMAX········ CON····· $40··········· 'Set Speed Maximum
SSRR········ CON····· $48··········· 'Set Speed Ramp Rate
'--- User Constants & Variables ---
AllWheels··· CON····· 0
RightWheel·· CON····· 1············· 'ID of the right side Position Controller
LeftWheel··· CON····· 2············· 'ID of the left side Position Controller
CommPin····· CON····· 12············ 'communication bus pin
BaudValue··· CON····· 32············ 'for 19.2kbps
Wheel······· VAR····· Byte·········· 'Specifies which wheel to command for subroutines
Distance···· VAR····· Word·········· 'Used to set the travel distance
RxData······ VAR····· Word·········· 'Used to receive data
'--- Initialization ---
PAUSE 1000
SEROUT CommPin, BaudValue, [noparse][[/noparse]SREV + RightWheel]· 'Reverses the sensor on the right
SEROUT CommPin, BaudValue, [noparse][[/noparse]CLRP]·············· 'Clears any prior position info
'Go forward·10 positions
Wheel = AllWheels
Distance = 10
DO
·· IF IN10=1 THEN
····· GOSUB GoDistance
····· ENDIF
· Wheel = LeftWheel
· DEBUG "L= "
· GOSUB DisplayPosition
· Wheel = RightWheel
· DEBUG "R= "
· GOSUB DisplayPosition
· DEBUG CR
LOOP
'--- Subroutines ---
GoDistance:
· SEROUT CommPin, BaudValue, [noparse][[/noparse]TRVL + Wheel]
· SEROUT CommPin, BaudValue, [noparse][[/noparse]Distance.HIGHBYTE, Distance.LOWBYTE]
RETURN
DisplayPosition:
· SEROUT CommPin, BaudValue, [noparse][[/noparse]QPOS + Wheel]
· SERIN· CommPin, BaudValue, [noparse][[/noparse]RxData.HIGHBYTE, RxData.LOWBYTE]
· DEBUG SDEC RxData
RETURN
Post Edited (mhenyon) : 7/23/2009 3:47:03 PM GMT
Hello everyone. I am using this piece of test code (below)·to turn my motor wheel kit using my board of ed stamp. It works only when the reset button is pushed.
I have setup a switch using·a button with the button active low, but when the button is pushed high, the·program·doesn't run.
I don't know why it won't run in a loop waiting for a button push to activate the program.
The purpose of this is to use the motor to turn an auger that delivers chemical to rainwater barrel·when a rain gauge bucket magnetic switch momentarily closes (the "button") when the bucket flops.
Thanks, Mike
' {$STAMP BS2}
' {$PBASIC 2.5}
'--- Command Value Constants ---
QPOS········ CON····· $08··········· 'Query Position
QSPD········ CON····· $10··········· 'Query Speed
CHFA········ CON····· $18··········· 'Check for Arrival
TRVL········ CON····· $20··········· 'Travel Number of Positions
CLRP········ CON····· $28··········· 'Clear Position
SREV········ CON····· $30··········· 'Set Orientation as Reversed
STXD········ CON····· $38··········· 'Set TX Delay
SMAX········ CON····· $40··········· 'Set Speed Maximum
SSRR········ CON····· $48··········· 'Set Speed Ramp Rate
'--- User Constants & Variables ---
AllWheels··· CON····· 0
RightWheel·· CON····· 1············· 'ID of the right side Position Controller
LeftWheel··· CON····· 2············· 'ID of the left side Position Controller
CommPin····· CON····· 12············ 'communication bus pin
BaudValue··· CON····· 32············ 'for 19.2kbps
Wheel······· VAR····· Byte·········· 'Specifies which wheel to command for subroutines
Distance···· VAR····· Word·········· 'Used to set the travel distance
RxData······ VAR····· Word·········· 'Used to receive data
'--- Initialization ---
PAUSE 1000
SEROUT CommPin, BaudValue, [noparse][[/noparse]SREV + RightWheel]· 'Reverses the sensor on the right
SEROUT CommPin, BaudValue, [noparse][[/noparse]CLRP]·············· 'Clears any prior position info
'Go forward·10 positions
Wheel = AllWheels
Distance = 10
DO
·· IF IN10=1 THEN
····· GOSUB GoDistance
····· ENDIF
· Wheel = LeftWheel
· DEBUG "L= "
· GOSUB DisplayPosition
· Wheel = RightWheel
· DEBUG "R= "
· GOSUB DisplayPosition
· DEBUG CR
LOOP
'--- Subroutines ---
GoDistance:
· SEROUT CommPin, BaudValue, [noparse][[/noparse]TRVL + Wheel]
· SEROUT CommPin, BaudValue, [noparse][[/noparse]Distance.HIGHBYTE, Distance.LOWBYTE]
RETURN
DisplayPosition:
· SEROUT CommPin, BaudValue, [noparse][[/noparse]QPOS + Wheel]
· SERIN· CommPin, BaudValue, [noparse][[/noparse]RxData.HIGHBYTE, RxData.LOWBYTE]
· DEBUG SDEC RxData
RETURN
Post Edited (mhenyon) : 7/23/2009 3:47:03 PM GMT
docx
44K
Comments
Have you tried putting "GOSUB GoDistance" inside the CheckLoop/GOTO CheckLoop, LOOP?
What reset button are you pressing?
There are some other things I see that could cause some issues, But lets start off simple.
_________$WMc%____________
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Truth is out there············································ BoogerWoods, FL. USA
Pin10 ---- 1k ---- BTN --- Vdd
Replace "GOSUB GoDistance" with this code (and remove CheckLoop if you want):
Also, check out the BUTTON command in the Stamp manual which you can download here: www.parallax.com/Portals/0/Downloads/docs/prod/stamps/web-BSM-v2.2.pdf
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don't worry. Be happy
I see you That you see where I was going; So Roll with it....Nice code buy the way.
____$WMc%______
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Truth is out there············································ BoogerWoods, FL. USA
mhenyon you could reduce the PAUSE 1000 to PAUSE 100 to check the button more precisely, but be sure not to hold the button down for more than 1/10 of a second, or the robot will continue walking.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don't worry. Be happy
Change "IF IN10 = 1" to "IF IN10=0" and use this circuit:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don't worry. Be happy
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don't worry. Be happy
I don't fully understand what you are trying to do, but there are several things that I can add. First even though it will not effect how your program runs, you have a comment line that says 'Go forward 350 positions
Two lines down you have Distance = 500. This causes the controller board to have the motor go 500 positions not 350 positions.
Second and more important you tell the controller to 350 positions then check for IN10=1. If IN10=1 you tell the program to
GOSUB GoDistance
What this does is add 500 more positions to the controller board. You must add a the line thats clears the controlller board of commands
SEROUT CommPin, BaudValue, [noparse][[/noparse]CLRP] 'Clears any prior position info
I know this sounds confusing, but once the main program on BS2 sends a SEROUT command to controller board, the controller board run runs on its own.
I have a robot running the Wheel Mount Kit and have worked out alot of programing problems. I have a program code template that helps. If there is enough interest on the Wheel Mount Kit programing from Forum, I can come up with a write up.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
······ Joe Fishback
-Robots are my friends-
You misunderstand his code. He probably just changed 350 to 500 for testing, and didnt comment it.
Distance = 500 just sets a variable. He calls GoDistance later with that value...
His code will work fine.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don't worry. Be happy