Shop OBEX P1 Docs P2 Docs Learn Events
'basic competition program' for sumobot modified for use with step genie/stepper moto — Parallax Forums

'basic competition program' for sumobot modified for use with step genie/stepper moto

circuitbobcircuitbob Posts: 5
edited 2014-01-10 08:36 in BASIC Stamp
Hello, I teach a high school level robotics class. We use the sumobot and the basic competition program for a lot of robots. Now I have some students that want to use stepper motors instead of servos, controlling them with the step genie or UCN- 5804 (which require three inputs: enable, direction and step pulse) has anyone out there modified the basic competition program to use a motor control like this instead of servos, or have any advice on how to do so? im not an expert stamp programmer yet and am a little foggy on where exactly to start.

Comments

  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-12-16 15:30
    I did a search and came up with several threads that pertain to stepper motors as I was not cleasr exactly what you were looking for. Maybe something here can help.
  • circuitbobcircuitbob Posts: 5
    edited 2013-12-18 07:20
    Thanks, but that link is not what we are looking for. all the messy business of pulsing the coils in the correct order, etc is handled by the stepper motor driver chip. all we have to do is tell it to turn on, which direction and how fast. our problem is not the hardware, but rather modifying the existing parallax 'basic competition program'. Currently it uses one output pin of the basic stamp for each servo, and changes the pulse width on that pin to tell the servo what to do (go forward or reverse fast or slow) .... now with this driver chip we need to dedicate two or possibly three pins to each motor and get the same information to the driver chip but in a different way. Instead of varying the pulse width to tell speed AND direction, now we need to toggle a one pin to tell direction, and vary the pulse frequency on a second pin to tell the desired speed.. To be honest I don't even know if the stock program can be modified to do this, it may be more difficult than rewriting the program from scratch, which unfortunately is waaaaay beyond any weak programming skills I may have, to be honest, the modification route may even be beyond me. (I am a hardware guy by nature, and break out in a cold sweat near complex programming challenges) that's why I am hoping that this forum can give us some help. im sure this whole thing is childs play to someone Really versed in stamp programming. My hope is to find one of those individuals that is willing to give us a little advice.
  • FranklinFranklin Posts: 4,747
    edited 2013-12-18 12:53
    Could you supply a link to the controller you are using and perhaps a link to the code you want to modify?
  • circuitbobcircuitbob Posts: 5
    edited 2013-12-19 10:10
    We are using the stock sumo bot board (which has a surface mount BS2); http://parallax.com/product/27400 The program we are starting with is the parallax basic competition program which is supplied with the mini sumobot kit ; http://parallax.com/downloads/sumobot-manual-basic-stamp-example-code This download is a packet of stuff, but the program is the last item 'sumobot 5.1 basic competition program'
  • circuitbobcircuitbob Posts: 5
    edited 2013-12-19 10:18
    '
    [ Title]

    ' Mini Sumo 5.1 : Basic Competition Program
    ' {$STAMP BS2}

    '
    [ I/O Definitions]


    LMotor CON 13 ' left servo motor
    RMotor CON 12 ' right servo motor

    LLineSnsPwr CON 10 ' left line sensor power
    LLineSnsIn CON 9 ' left line sensor input
    RLineSnsPwr CON 7 ' right line sensor power
    RLineSnsIn CON 8 ' right line sensor input

    LfIrOut CON 4 ' left IR LED output
    LfIrIn VAR IN11 ' left IR sensor input
    RtIrOut CON 15 ' right IR LED output
    RtIrIn VAR IN14 ' right IR sensor input

    Speaker CON 1 ' piezo speaker
    StartLED CON 0 ' display start delay

    '
    [ Constants]


    LFwdFast CON 1000 ' left motor forward; fast
    LFwdSlow CON 800 ' left motor forward; slow
    LStop CON 750 ' left motor stop
    LRevSlow CON 700 ' left motor reverse; slow
    LRevFast CON 500 ' left motor reverse; fast

    RFwdFast CON 500 ' right motor forward; fast
    RFwdSlow CON 700 ' right motor forward; slow
    RStop CON 750 ' right motor stop
    RRevSlow CON 800 ' right motor reverse; slow
    RRevFast CON 1000 ' right motor reverse; fast

    '
    [ Variables]


    leftSense VAR Word ' left sensor raw reading
    rightSense VAR Word ' right sensor raw reading
    blackThresh VAR Word ' QTI black thresholdsetting
    lineBits VAR Nib ' decoded sensors value
    lineLeft VAR lineBits.BIT1
    lineRight VAR lineBits.BIT0

    irBits VAR Nib ' storage for IR targetdata
    irLeft VAR irBits.BIT1
    irRight VAR irBits.BIT0
    lastIr VAR Nib ' info from last reading

    pulses VAR Byte ' counter for motor control
    temp VAR Byte

    '
    [ EEPROM Data]


    RunStatus DATA $00 ' runstatus

    '
    [ Initialization]


    Run_Check: ' userReset button as On-Off
    READ RunStatus,temp ' read current status
    temp = ~temp ' invertstatus
    WRITE RunStatus,temp ' savestatus for next reset
    IF (temp = 0) THENSet_Threshold ' run now?
    END ' -- no ... next time

    ' Sets black threshold to 1/4 the average of the two sensorreadings.
    ' SumoBot must be placed over black playing surface beforethis code runs.

    Set_Threshold: ' set QTIblack threshold
    GOSUBRead_Line_Sensors
    blackThresh =(leftSense / 8) + (rightSense / 8)

    Start_Delay: ' mandatoryfive second delay
    FOR temp = 1 TO 5
    HIGH StartLED ' show active
    PAUSE 900
    INPUTStartLED 'blink each second
    FREQOUT Speaker,100, 2500, 3000 ' beep eachsecond
    NEXT

    GOTO Lunge ' startaggressive!

    '
    [ Main Code ]


    Main:
    GOSUBRead_Line_Sensors

    ' If not on theShikiri line (border), continue to look for opponent,
    ' otherwise, spinback toward center and resume search

    BRANCH lineBits,[Search_For_Opponent, Spin_Left, Spin_Right, About_Face]

    ' --[ Border Avoidance ]--

    Spin_Left: ' rightsensor was active
    FOR pulses = 1 TO 20
    PULSOUT LMotor,LRevFast
    PULSOUT RMotor,RFwdFast
    PAUSE 20
    NEXT
    lastIr = %00 ' clear scan direction
    GOTO Lunge

    Spin_Right: ' leftsensor was active
    FOR pulses = 1 TO 20
    PULSOUT LMotor,LFwdFast
    PULSOUT RMotor,RRevFast
    PAUSE 20
    NEXT
    lastIr = %00
    GOTO Lunge

    About_Face: ' both sensors onShikiri line
    FOR pulses = 1 TO10 ' back upfrom edge
    PULSOUT LMotor,LRevFast
    PULSOUT RMotor,RRevFast
    PAUSE 20
    NEXT
    FOR pulses = 1 TO30 ' turn around
    PULSOUT LMotor,LFwdFast
    PULSOUT RMotor,RRevFast
    PAUSE 20
    NEXT
    lastIr = %00
    GOTO Lunge

    ' --[ IR Processing ]--

    Search_For_Opponent:
    GOSUBRead_IR_Sensors

    ' If opponent is notin view, scan last known direction. Turntoward
    ' opponent if seenby one "eye" -- if both, lunge forward

    BRANCH irBits,[Scan, Follow_Right, Follow_Left, Lunge]

    Scan:
    BRANCH lastIR,[Move_Fwd, Scan_Right, Scan_Left]

    Move_Fwd:
    GOSUB Creep_Forward
    GOTO Main

    Scan_Right: ' spinright, slow
    FOR pulses = 1 TO 5
    PULSOUT LMotor,LFwdSlow
    PULSOUT RMotor,RRevSlow
    PAUSE 20
    NEXT
    GOSUBCreep_Forward 'keep moving
    GOTO Main

    Scan_Left: ' spinleft, slow
    FOR pulses = 1 TO 5
    PULSOUT LMotor,LRevSlow
    PULSOUT RMotor,RFwdSlow
    PAUSE 20
    NEXT
    GOSUB Creep_Forward
    GOTO Main

    Follow_Right: ' spin right, fast
    PULSOUT LMotor,LFwdFast
    PULSOUT RMotor,RRevSlow
    lastIR = irBits ' save lastdirection found
    GOTO Main

    Follow_Left: ' spinleft, fast
    PULSOUT LMotor, LRevSlow
    PULSOUT RMotor,RFwdFast
    lastIR = irBits
    GOTO Main

    Lunge: 'locked on -- go get him!
    FOR pulses = 1 TO 15
    PULSOUT LMotor,LFwdFast
    PULSOUT RMotor,RFwdFast
    GOSUBRead_Line_Sensors
    IF (lineBits =%11) THEN Match_Over ' in sightand we're on the line
    NEXT
    GOTO Main

    ' If SumoBot can see the opponent with both "eyes"and both QTIs are
    ' detecting the border, we must have pushed the opponentout.

    Match_Over:
    FOR pulses = 1 TO10 ' stop motors
    PULSOUT LMotor,LStop
    PULSOUT RMotor,RStop
    PAUSE 20
    NEXT
    INPUT LMotor
    INPUT RMotor

    FOR temp = 1 TO10 ' make somenoise
    HIGH StartLED
    FREQOUT Speaker,100, 2500, 3000 ' beep
    INPUTStartLED 'blink LED
    PAUSE 100
    NEXT

    DIRS = $0000 ' disable alloutputs
    GOTO Run_Check ' reset fornext round

    '
    [ Subroutines]


    Read_Line_Sensors:
    HIGHLLineSnsPwr ' activate sensors
    HIGH RLineSnsPwr
    HIGH LLineSnsIn ' discharge QTIcaps
    HIGH RLineSnsIn
    PAUSE 1
    RCTIME LLineSnsIn,1, leftSense ' read leftsensor
    RCTIME RLineSnsIn,1, rightSense ' read rightsensor
    LOW LLineSnsPwr ' deactivatesensors
    LOW RLineSnsPwr

    ' convert readingsto bits
    lineBits = %00
    LOOKDOWN leftSense,>=[blackThresh, 0], lineLeft
    LOOKDOWN rightSense,>=[blackThresh, 0], lineRight
    RETURN

    Read_IR_Sensors:
    FREQOUT LfIrOut, 1,38500 ' modulate leftIR LED
    irLeft = ~LfIrIn ' read input (1 =target)
    FREQOUT RtIrOut, 1,38500 ' modulateright IR LED
    irRight =~RtIrIn 'read input (1 = target)
    RETURN

    Creep_Forward:
    FOR pulses = 1 TO 10
    PULSOUT LMotor,LFwdSlow
    PULSOUT RMotor,RFwdSlow
    PAUSE 20
    NEXT
    RETURN
  • FranklinFranklin Posts: 4,747
    edited 2013-12-19 21:42
    When you include code please use the [code] tags and the link I was looking for is the controller for the steppers as the sumobot can't drive steppers the way you describe without help from some other hardware. attachment.php?attachmentid=78421&d=1297987572
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-12-19 22:22
    For those unaware of the way many stepper controllers work, there's the three pins circuit bobmentioned, enable, direction and step.

    I imagine enable could probably be tied high. Direction is held high when the motor is to turn 'forward"(we'll call it for now) and the direction pin is held low to reverse the motor. Instead of having to output the individual sequence of bits the stepper needs the step pin just needs to pulsed and the driver takes care of the rest.

    Now the problem I see with trying to use a stepper with a BS2 is the stepper, even with the added controller, will require a lot of step pulses to get the motor to move. Instead of a pulse once every 20ms, you'll need to send however many pulses you want the stepper motor to take steps. You'll also need to send the pulses at the correct intervals. I think this soon becomes too much for the BS2 (though I'm not positive about this).

    In general one doesn't want to use a stepper with a BS2 if you want the BS2 to do anything other than pulse the stepper.

    So the short answer is I really doubt you'll be able to use steppers instead of servos in the sumobots.
  • ercoerco Posts: 20,256
    edited 2013-12-20 07:39
    Sounds like Duane wants to rumble! :)

    You can certainly check a few sensors while moving. You might have to slow down the pulse rate to the stepper a bit, but as I'm wont to say, you can do ANYTHING with a BS2.

    I don't think Chris Savage ever believed the quad encoder speeds I achieved on the BS2, but Tracy Allen did. :)
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-12-20 08:31
    As I think about this a bit more, I think the steppers wouldn't be as bad as I initially thought.

    Since the "PAUSE 20" command is likely taking most of the time in a loop, this time could be spent pulsing the stepper. So I maybe the steppers wouldn't be so bad after all. I'm not sure how the bot will behave with interruptions to the steps as sensors are checked and decisions are made.

    Steppers are certainly not a drop in replacement for CR servos.

    @erco, I'm trying to remember. Was that quad encoder video before or after the video showing how you can unlock your car with a tennis ball?
  • ercoerco Posts: 20,256
    edited 2013-12-20 14:02
    Duane Degn wrote: »
    @erco, I'm trying to remember. Was that quad encoder video before or after the video showing how you can unlock your car with a tennis ball?

    Actually, my prior video was Bigfoot riding a unicycle while juggling Roswell aliens.
    Duane Degn wrote: »
    Steppers are certainly not a drop in replacement for CR servos.

    And thus beginneth my quest for 2014!

    Let's face it, driving servos and pausing 20 in nested loops is nearly as much of a PITA as driving stepper motors. So Servopal saved the day. Seems like "Stepperpal" should be on the docket as well. IIRC there was Motormind or Microstepper(?) in the past, but there's nothing available now, at least not from Mother Parallax.

    Since I like robotics and general motion control so much, maybe this is my call to action! Perfect app for a serial-input PIC daughterboard, maybe with an onboard ULN2803 for two bipolar steppers. Could double as a 8-servo driver. Maybe I'll make my first PCB and get filthy stinking rich!

    Nah...

    Well maybe...
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-12-20 18:52
    there's nothing available now, at least not from Mother Parallax.
    What about this?
  • ercoerco Posts: 20,256
    edited 2013-12-20 23:14
    That's it, the Little Step U controller ( I mistakenly called it Microstepper above). OK, still for sale, but pricey at $70. Gotta be a cheaper option.

    Heck, a ULN5804 dedicated IC driver IC is just $2.59: http://www.ebay.com/itm/1PCS-UCN5804B-UCN5804-Stepper-Motor-Transl-EQ13-/360718744837
  • circuitbobcircuitbob Posts: 5
    edited 2014-01-08 07:14
    Well, it looks like we have come full circle. The last suggestion was to use the 5804 which as I stated in the beginning is what we are already using. our problem is in modifying the software to work with the 5804. ???? there must be someone out there who has done something like this before. what about driving a dc motor control like the polulu, is the mod required for that in any way similar?
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-01-08 11:27
    circuitbob wrote: »
    there must be someone out there who has done something like this before.

    I'm sure there are examples of controlling a stepper with a BS2 but I'm not so sure if there are examples of BS2/stepper controlled robots.
    circuitbob wrote: »
    what about driving a dc motor control like the polulu, is the mod required for that in any way similar?

    In some ways this could be easier than using a servo but it would only be easier it you didn't need to control the speed of the robot.

    The motor could be turned on with a "HIGH" command to the pin or pins controlling the h-bridge/motor. One the motor is turned on the program can continue with other tasks. However if you want to control the speed of the motor you'd need to send a PWM output to the h-bridge. The program can't send a PWM signal and do anything else at the same time. I also think the PWM would be limited to one motor at a time.

    Another concern with using PWM and a h-bridge to control a DC motor is the BS2's PWM frequency is very high (IIRC). I'm not sure how well the PWM output from a BS2 would work with many (most?) h-bridge chips/circuits. I think the BS2 really needs some sort of smart driver to use DC motors, hence the use of CR servos.

    The BS2 can only do one thing at a time. IMO, this imposes a severe limitation when using it to drive multiple motors.

    Pololu sells a variety of smart motor controllers. These take care of driving the motors and the BS2 would just send it commands to indicate how fast to drive which motor. I haven't used these myself but I believe this is one way of overcoming the limitations of the BS2.
  • ercoerco Posts: 20,256
    edited 2014-01-08 15:18
    I just received some 5804's from Ebay, but haven't tried them out yet, might take me a while to get to them. But I have made two bots with steppers; they are easy and reliable for simple navigation. Just using a BS1 here: http://www.youtube.com/watch?v=TLdkKKMfUP0 and http://www.youtube.com/watch?v=SYi0Cs8jJqM

    And later I retrofitted those steppers into a BS2-based Boebot with a ULN2803 driver: http://forums.parallax.com/showthread.php/144427-Stepper-BoeBot

    Using nothing but a BS2/2803 might require stopping the steppers briefly occasionally to monitor various sensors for a Sumobot.
  • ercoerco Posts: 20,256
    edited 2014-01-09 09:11
    @circuitbob: Have your students selected the stepper motors yet? Bipolar or unipolar? There are cheap bipolar steppers available for just a few dollars on Ebay (see http://forums.parallax.com/showthread.php/141149-3-Stepper-Motor-amp-Board) but IMO they would not work well for sumo-style matches. They are slow and fairly weak, plus the tiny internal gears would strip. The Parallax 12V stepper might be more suitable, but I'm not certain: http://www.parallax.com/product/27964

    Some modification and or machining is in order to mount the motors to the chassis, and more to mount the wheels to the motors. You would need better batteries to run stepper motors, for sure. Probably li-po or li-ion. Certainly more time and $$$, is all of this in the budget? If so, I have some interesting thoughts for you.
  • ercoerco Posts: 20,256
    edited 2014-01-10 08:36
    One aspect I like about a stepper motor robot for begining students is that speed is constant, not dependent on battery voltage. A stepper bot should go exactly the same distance in 2 seconds every time, uphill, downhill, new or used batteries. The inability to do that is the bane of CR servo-based bots.
Sign In or Register to comment.