Problem with Motor Code: please help!!
I am running the Basic Stamp 2sx and I have a slight error in my code somewhere and can't seem to find it. I am running 4 dc motors off of a motor controller that has 2 switches. S1 controls forward and reverse and S2 controls left and right (tank style). Below is a copy of the code.
' {$STAMP BS2sx}
' {$PBASIC 2.5}
'this program tests the servo position
motor PIN 14
turn PIN 15
forward CON 1600
backward CON 2050
break CON 1850
right CON 1600
left CON 2100
turnbreak CON 1875
counter VAR BYTE
pulses VAR WORD
duration VAR WORD
'PULSOUT motor, break
'PULSOUT turn, turnbreak
main:
FOR counter = 1 TO 1
DEBUG "b"
PULSOUT motor, break
PULSOUT turn, turnbreak
PAUSE 2000
NEXT
FOR counter = 1 TO 1
DEBUG "f"
PULSOUT motor, forward
PULSOUT turn, break
PAUSE 4000
NEXT
FOR counter = 1 TO 1
DEBUG "L"
PULSOUT motor, break
PULSOUT turn, left
PAUSE 1000
NEXT
GOTO main
END
I understand that it will never get to the end because its in a never ending loop. That is not my problem. When i download the program to the board, the first break works perfectly. The motors do not move. Every time after that, the break command will not work when it comes back from the first loop. It goes into a turning command. Is there a way to reset the frequency i am sending to the motors after every loop so that is starts fresh again. I need a way to clear out the signal thats being sent so that it will break after the loop. If anyone can help please let me know. Kisses.
' {$STAMP BS2sx}
' {$PBASIC 2.5}
'this program tests the servo position
motor PIN 14
turn PIN 15
forward CON 1600
backward CON 2050
break CON 1850
right CON 1600
left CON 2100
turnbreak CON 1875
counter VAR BYTE
pulses VAR WORD
duration VAR WORD
'PULSOUT motor, break
'PULSOUT turn, turnbreak
main:
FOR counter = 1 TO 1
DEBUG "b"
PULSOUT motor, break
PULSOUT turn, turnbreak
PAUSE 2000
NEXT
FOR counter = 1 TO 1
DEBUG "f"
PULSOUT motor, forward
PULSOUT turn, break
PAUSE 4000
NEXT
FOR counter = 1 TO 1
DEBUG "L"
PULSOUT motor, break
PULSOUT turn, left
PAUSE 1000
NEXT
GOTO main
END
I understand that it will never get to the end because its in a never ending loop. That is not my problem. When i download the program to the board, the first break works perfectly. The motors do not move. Every time after that, the break command will not work when it comes back from the first loop. It goes into a turning command. Is there a way to reset the frequency i am sending to the motors after every loop so that is starts fresh again. I need a way to clear out the signal thats being sent so that it will break after the loop. If anyone can help please let me know. Kisses.
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
high (input pin)
pause (1000 uS to 2000uS)
low (input pin)
is there a way anyone could send a sample code on how that would look in basic. I am not asking anyone to do my work for me but i am just can't seem to get it right. I tried that today but on the Basic Stamp 2sx the timing is all off even though the oscilloscope tells me its sending a 1500 uS pulse but it's not stoping.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
Jax
edit:
never mind, I just seen it at the top post, I'll look it over for you.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If a robot has a screw then it must be romoved and hacked into..
Jax
' {$STAMP BS2sx}
' {$PBASIC 2.5}
'this program tests the servo position
'=====================================================================
' Turn the switches on the sabertooth 2x5 to 1, 2, 3, 4, 5, 6
' off, on, on, on, on, off
'
Motor PIN 14 ' High controls foward and Low controls backwards
Turn PIN 15 ' High controls CC and Low controls CCW
'=====================================================================
' This program should control 2 motors in a mix mode at the same time
' , in the modethe motors do not come to a complete stop or rest or
' rather it will continue to move foward, backward, left and right
' If one wants to control stopping the motors program it the same way
' you would control a SERVO using the PULSOUT command and set switch 6
' to the on possition.
'
Main:
GOSUB Foward
GOSUB Backwards
GOSUB CC
GOSUB CCW
GOTO Main
Foward:
DEBUG CLS, " Forward ", CR
HIGH Motor
PAUSE 2000
RETURN
Backwards:
DEBUG " Backwards ", CR
LOW Motor
PAUSE 2000
RETURN
CC:
DEBUG " CC ", CR
HIGH Turn
PAUSE 2000
RETURN
CCW:
DEBUG " CCW ", CR
LOW Turn
PAUSE 2000
RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If a robot has a screw then it must be romoved and hacked into..
I was also looking at the code and your saying if I want to stop the motor. Just set pin 6 to on and pulsout the 1500 to stop the motors. Would I essentially be changing the whole code to the pulsout commands like the servo or just for the stop routine?
Post Edited (crd15) : 4/11/2009 10:11:32 PM GMT
Jax
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If a robot has a screw then it must be romoved and hacked into..
' {$STAMP BS2sx}
' {$PBASIC 2.5}
left PIN 14 ' controls left motors
right PIN 15 ' controls right motors
counter VAR WORD
Main:
GOSUB Forward
GOSUB CC
GOSUB Forward
GOSUB CC
GOSUB forward
GOSUB cc
GOSUB forward
GOSUB break
GOTO Main
'
'subroutines
'
Forward:
DEBUG " forward ", CR
FOR counter = 1 TO 150
PULSOUT 14, 1500
PULSOUT 15, 1500
PAUSE 20
NEXT
RETURN
Backwards:
DEBUG " Backwards ", CR
FOR counter = 1 TO 150
PULSOUT 14, 2200
PULSOUT 15, 2200
PAUSE 20
NEXT
RETURN
CC:
DEBUG " CC ", CR
FOR counter = 1 TO 75
PULSOUT 14, 1675
PULSOUT 15, 2075
PAUSE 20
NEXT
RETURN
CCW:
DEBUG " CCW ", CR
FOR counter = 1 TO 75
PULSOUT 14, 2075
PULSOUT 15, 1675
PAUSE 20
NEXT
RETURN
break:
DEBUG " stop ", CR
FOR counter = 1 TO 150
PULSOUT 14, 1875
PULSOUT 15, 1875
PAUSE 20
NEXT
PAUSE 2000
RETURN
There are several other routines in there for reverse and ccw turning but i did not include them in the subroutine. Thanks again everyone
Jax
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If a robot has a screw then it must be romoved and hacked into..