Shop OBEX P1 Docs P2 Docs Learn Events
Program assistance requested: Bs2 & Pololu Micro Dual Motor Controller with bum — Parallax Forums

Program assistance requested: Bs2 & Pololu Micro Dual Motor Controller with bum

Johannes BeilmanJohannes Beilman Posts: 4
edited 2005-12-29 19:58 in Robotics
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.
600 x 384 - 25K
2272 x 1704 - 842K

Comments

  • Steve JoblinSteve Joblin Posts: 784
    edited 2005-12-27 21:52
    I'm no the best at analyzing code, but one thing I noticed is that you are powering both the Stamp and DSMC (Pololu Dual Serial Motor Controller) off of a single 9v transistor battery. You might be causing the stamp to reset due to the current draw of the DSMC... try using a 9v transistor for powering the Stamp and 4 to 6 AA batteries for the DSMC.... Just remember to tie both the grounds together.
  • Johannes BeilmanJohannes Beilman Posts: 4
    edited 2005-12-29 16:52
    Thanks Steve,

    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.
  • Steve JoblinSteve Joblin Posts: 784
    edited 2005-12-29 19:48
    The first thing I see is that you are constantly sending a command to go forward if the bumpers are not pressed... the idea is that you only need to send a command to the DSMC when you want it to change. Try something like this... (I am using psudo-code, not PBASIC, but you should get the idea)

    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
  • Robert KubichekRobert Kubichek Posts: 343
    edited 2005-12-29 19:58
    Steve Joblin said...
    The first thing I see is that you are constantly sending a command to go forward if the bumpers are not pressed... the idea is that you only need to send a command to the DSMC when you want it to change. Try something like this... (I am using psudo-code, not PBASIC, but you should get the idea)

    Start-up:
    loop until a bumper is pushed

    main:
    go forward

    sense_bumper:
    if left bumper pressed, drive_Left
    if right 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 scool.gif
Sign In or Register to comment.