coordination between motors
I need to finish·a project so I would really appreciate help with this. I have two motors attached to two separate BS2s, with an accelerometer, RF Transmitter/Receiver modules, and an HB-25 motor controller·attached to each BS2. I want the motors to alternate turning in this way: once the transmitted accelerometer value from one·BS2·is above a value, the motor receiving the value·turns on until the received value is below a certain value. Then this motor stops and the other one turns until the accelerometer value it receives meets a similar condition. They repeat in this fashion, so it's off,on,off...for one motor and on,off,on...for the other motor. I can't get the motors to coordinate in this way and I know the problem has something to do with timing and delays. Once the accelerometer condition is met, I can see in the debug window that the program is out of the current loop as it should be, but it doesn't enter the next loop. Does anyone see what is wrong with this code? Thank you.
'{$STAMP BS2}
'{$PBASIC 2.5}
y1 VAR Word··· 'accelerometer value from·motor's own·BS2
y2 VAR Word·· 'accelerometer value from other BS2
Main:
SERIN 2, 16468, [noparse][[/noparse]WAIT("!"), y2.HIGHBYTE, y2.LOWBYTE]· 'receive other BS2's accelerometer value
IF y2 >3120 THEN
PULSOUT 3, 1000· 'motor turns
DO UNTIL y2 <1930
SERIN 2, 16468, [noparse][[/noparse]WAIT("!"), y2.HIGHBYTE, y2.LOWBYTE]
LOOP
PULSIN 5, 1, y1 'get accelerometer value from motor's own BS2
PULSOUT 3, 750 'stop turning the motor
DO UNTIL y1 > 3100
SEROUT 15, 16468, [noparse][[/noparse] "!", y1.HIGHBYTE, y1.LOWBYTE]· 'send out accelerometer value so other motor will turn (its code is just like the previous loop)
PULSIN 5, 1, y1
LOOP
'Repeat process:
PULSOUT 3, 1000
DO UNTIL y2 > 3120
SERIN 2, 16468, [noparse][[/noparse]WAIT("!"), y2.HIGHBYTE, y2.LOWBYTE]
LOOP
PULSOUT 3, 750
DO UNTIL y1 < 1880
SEROUT 15, 16468, [noparse][[/noparse] "!", y1.HIGHBYTE, y1.LOWBYTE]
PULSIN 5,1, y1
LOOP
ENDIF
GOTO Main
note: I have put the PULSOUT commands within the DO LOOPs but this hasn't worked well either.
'{$STAMP BS2}
'{$PBASIC 2.5}
y1 VAR Word··· 'accelerometer value from·motor's own·BS2
y2 VAR Word·· 'accelerometer value from other BS2
Main:
SERIN 2, 16468, [noparse][[/noparse]WAIT("!"), y2.HIGHBYTE, y2.LOWBYTE]· 'receive other BS2's accelerometer value
IF y2 >3120 THEN
PULSOUT 3, 1000· 'motor turns
DO UNTIL y2 <1930
SERIN 2, 16468, [noparse][[/noparse]WAIT("!"), y2.HIGHBYTE, y2.LOWBYTE]
LOOP
PULSIN 5, 1, y1 'get accelerometer value from motor's own BS2
PULSOUT 3, 750 'stop turning the motor
DO UNTIL y1 > 3100
SEROUT 15, 16468, [noparse][[/noparse] "!", y1.HIGHBYTE, y1.LOWBYTE]· 'send out accelerometer value so other motor will turn (its code is just like the previous loop)
PULSIN 5, 1, y1
LOOP
'Repeat process:
PULSOUT 3, 1000
DO UNTIL y2 > 3120
SERIN 2, 16468, [noparse][[/noparse]WAIT("!"), y2.HIGHBYTE, y2.LOWBYTE]
LOOP
PULSOUT 3, 750
DO UNTIL y1 < 1880
SEROUT 15, 16468, [noparse][[/noparse] "!", y1.HIGHBYTE, y1.LOWBYTE]
PULSIN 5,1, y1
LOOP
ENDIF
GOTO Main
note: I have put the PULSOUT commands within the DO LOOPs but this hasn't worked well either.
Comments
G'nite.
Rich H
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Servo Boss, a 12 channel servo tester kit from Gadget Gangster.
IF y2 <1920 THEN
GOSUB StopMotor
DO UNTIL y2 > 3120
GOSUB GetOwnValue
GOSUB SendValue
LOOP
GOSUB GetOtherValue
GOSUB RunMotor
DO UNTIL y1 > 3000
DEBUG ? y1
GOSUB GetOtherValue
LOOP
DEBUG "hi"
GOSUB StopMotor
....................
So this code works fine until after the last loop. For some reason when y1 > 3000, it exits the loop and no longer prints the value of y1 in the debug window, which is good,·but it does not print "hi" on the debug screen after this and the motor never stops. Do you know why this would happen?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don't worry. Be happy
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen