Program assistance requested: Bs2 & Pololu Micro Dual Motor Controller with bum
Johannes Beilman
Posts: 4
I was hoping someone could quickly review the program for my bot. I have a robot based on the Homework Board that I have been struggling with for weeks. I have confirmed that my Tamiya 70097 Twin-Motor Gearbox moves forward per the following:
LFWD CON 2
LBAK CON 3
RFWD CON 0
RBAK CON 1
But, when I put all this into a program based on sample code from the Pololu website, I cannot get the robot to function. If I reduce speed to something like 60 (from 127), I get some movement. I have attached a schematic, & a photo of my bot.
Is the program below correct for what I am trying to do?
' {$STAMP BS2}
' {$PBASIC 2.5}
'
***I/O lines
RBUMP VAR IN6 'right front bumper input (0=hit something)
LBUMP VAR IN7 'left front bumper input
MC_RESET CON 8 'Pololu micro dual serial motor controller reset line
MC_SOUT CON 10 'serial line to motor controller
'
***Variables
SPEED VAR Byte 'speed of robot driving straight and of faster wheels when turning
SLOWSPEED VAR Byte 'speed of slower wheels when turning backwards
TURNTIME VAR Byte 'random time to spin in place after backing away from obstacle
'
***Motor numbrs/directns for Pololu micro dual serial motor controller commands
LFWD CON 2
LBAK CON 3
RFWD CON 0
RBAK CON 1
'
***My Less Than Perfect Program
DO
HIGH MC_SOUT
LOW MC_RESET
HIGH MC_RESET
PAUSE 1000
SPEED = 60
SLOWSPEED = 50
TURNTIME = 37
twiddling: 'Press a bumper to get the bot moving
IF RBUMP = 1 THEN go
IF LBUMP = 1 THEN go
GOTO twiddling
go: 'Wait a second so that bumpers aren't pushed when you first enter loop.
PAUSE 1000
run: 'Go forward till bump something
SEROUT MC_SOUT, 84, [noparse][[/noparse]$80, 0, LFWD, SPEED] 'Left and right motors forward at SPEED
SEROUT MC_SOUT, 84, [noparse][[/noparse]$80, 0, RFWD, SPEED]
IF (RBUMP = 1) THEN rbumped 'If bumped, turn backward in appropo direction
IF (LBUMP = 1) THEN lbumped
GOTO run
rbumped: 'Turn backward right, then spin left in place for a random time
SEROUT MC_SOUT, 84, [noparse][[/noparse]$80, 0, LBAK, SPEED] 'Turn backward for 1 sec
SEROUT MC_SOUT, 84, [noparse][[/noparse]$80, 0, RBAK, SLOWSPEED]
PAUSE 1000
SEROUT MC_SOUT, 84, [noparse][[/noparse]$80, 0, LBAK, SPEED] 'Spin in place for random time, TURNTIME
SEROUT MC_SOUT, 84, [noparse][[/noparse]$80, 0, RFWD, SPEED]
RANDOM TURNTIME
PAUSE (TURNTIME*5) + 250 'pause between 0.25 and 1.5 seconds
GOTO run
lbumped: 'Turn backward left, then spin right in place for a random time
SEROUT MC_SOUT, 84, [noparse][[/noparse]$80, 0, LBAK, SLOWSPEED]
SEROUT MC_SOUT, 84, [noparse][[/noparse]$80, 0, RBAK, SPEED]
PAUSE 1000
SEROUT MC_SOUT, 84, [noparse][[/noparse]$80, 0, LFWD, SPEED]
SEROUT MC_SOUT, 84, [noparse][[/noparse]$80, 0, RBAK, SPEED]
RANDOM TURNTIME
PAUSE (TURNTIME*5) + 250
GOTO run
LOOP
The cooperation & efforts put forth in this forum are an inspiration. Thanks to all who reply.
LFWD CON 2
LBAK CON 3
RFWD CON 0
RBAK CON 1
But, when I put all this into a program based on sample code from the Pololu website, I cannot get the robot to function. If I reduce speed to something like 60 (from 127), I get some movement. I have attached a schematic, & a photo of my bot.
Is the program below correct for what I am trying to do?
' {$STAMP BS2}
' {$PBASIC 2.5}
'
***I/O lines
RBUMP VAR IN6 'right front bumper input (0=hit something)
LBUMP VAR IN7 'left front bumper input
MC_RESET CON 8 'Pololu micro dual serial motor controller reset line
MC_SOUT CON 10 'serial line to motor controller
'
***Variables
SPEED VAR Byte 'speed of robot driving straight and of faster wheels when turning
SLOWSPEED VAR Byte 'speed of slower wheels when turning backwards
TURNTIME VAR Byte 'random time to spin in place after backing away from obstacle
'
***Motor numbrs/directns for Pololu micro dual serial motor controller commands
LFWD CON 2
LBAK CON 3
RFWD CON 0
RBAK CON 1
'
***My Less Than Perfect Program
DO
HIGH MC_SOUT
LOW MC_RESET
HIGH MC_RESET
PAUSE 1000
SPEED = 60
SLOWSPEED = 50
TURNTIME = 37
twiddling: 'Press a bumper to get the bot moving
IF RBUMP = 1 THEN go
IF LBUMP = 1 THEN go
GOTO twiddling
go: 'Wait a second so that bumpers aren't pushed when you first enter loop.
PAUSE 1000
run: 'Go forward till bump something
SEROUT MC_SOUT, 84, [noparse][[/noparse]$80, 0, LFWD, SPEED] 'Left and right motors forward at SPEED
SEROUT MC_SOUT, 84, [noparse][[/noparse]$80, 0, RFWD, SPEED]
IF (RBUMP = 1) THEN rbumped 'If bumped, turn backward in appropo direction
IF (LBUMP = 1) THEN lbumped
GOTO run
rbumped: 'Turn backward right, then spin left in place for a random time
SEROUT MC_SOUT, 84, [noparse][[/noparse]$80, 0, LBAK, SPEED] 'Turn backward for 1 sec
SEROUT MC_SOUT, 84, [noparse][[/noparse]$80, 0, RBAK, SLOWSPEED]
PAUSE 1000
SEROUT MC_SOUT, 84, [noparse][[/noparse]$80, 0, LBAK, SPEED] 'Spin in place for random time, TURNTIME
SEROUT MC_SOUT, 84, [noparse][[/noparse]$80, 0, RFWD, SPEED]
RANDOM TURNTIME
PAUSE (TURNTIME*5) + 250 'pause between 0.25 and 1.5 seconds
GOTO run
lbumped: 'Turn backward left, then spin right in place for a random time
SEROUT MC_SOUT, 84, [noparse][[/noparse]$80, 0, LBAK, SLOWSPEED]
SEROUT MC_SOUT, 84, [noparse][[/noparse]$80, 0, RBAK, SPEED]
PAUSE 1000
SEROUT MC_SOUT, 84, [noparse][[/noparse]$80, 0, LFWD, SPEED]
SEROUT MC_SOUT, 84, [noparse][[/noparse]$80, 0, RBAK, SPEED]
RANDOM TURNTIME
PAUSE (TURNTIME*5) + 250
GOTO run
LOOP
The cooperation & efforts put forth in this forum are an inspiration. Thanks to all who reply.
Comments
I have added additional power to the DMSC per your advice. If I could ony get past my program issues I'd be all set.
Start-up:
loop until a bumper is pushed
main:
go forward
sense_bumper:
if left bumper pressed, drive_Left
if righ bumber pressed, drive_right
goto sense_bumper
Drive left:
bla bla bla
goto main
Drive right:
bla bla bla
goto main
Shouldn't that be;
sense_bumper:
if left bumper pressed, drive_right
if right bumber pressed, drive_left
goto sense_bumper
If one was to use your "psudo-code" you would be turning into the bumper that's been triggered..
Bob N9LVU