Shop OBEX P1 Docs P2 Docs Learn Events
help with HB25 motor controllers — Parallax Forums

help with HB25 motor controllers

heidikayheidikay Posts: 2
edited 2008-01-17 18:25 in Robotics
I am trying to control two motors with two separate motor controllers (HB25s).
I am using a BS2e, on a MAC using MACBS2 software, on a SuperCarrier Board. I am trying to run 2 separate DC motors.

I have used the sample code they provide and I can get one to run, but cannot get two to run. Also, if i embed DEBUG statements inside some of the sequences, the entire program stops. Does anyone know how to create a loop or something that allows me to know the value of something inside the sequence using a DEBUG statement but NOT pause or halt the entire program?

Is there some issue about servo motors, cables that I don't know about that is causing my code not to work?

thanks,
Heidi

my sample code for two HB25's:

' =========================================================================
' File...... HB-25 Motor Test--HEIDI KUMAO.bs2
' Purpose... USING 2 HB-25's Connected To P15 and P2
' Author.... Heidi Kumao
' E-mail.... hkumao@umich.edu
' Updated... 01-16-2008
'
' {$STAMP BS2e}
' {$PBASIC 2.5}

'
[noparse][[/noparse] Program Description ]

' This program tests TWO HB-25s by waiting for them to power up, then pulsing
' the output to ramp the motors up, wait 3 seconds
' then ramp them back down to a stopped position.

'
[noparse][[/noparse] I/O Definitions ]

HB25 PIN 15 ' I/O Pin For HB-25
'INPUT 3 'PIN 3 'motion sensor on Pin 3
HB25_hip PIN 2 'i/o pin for second H-25
'
[noparse][[/noparse] Variables ]

index VAR WORD ' Counter For Ramping
'R VAR BYTE 'random value generated to determine which move to make


'
[noparse][[/noparse] Initialization ]

DO : LOOP UNTIL HB25 = 1 ' Wait For HB-25 Power Up
LOW HB25 ' Make I/O Pin Output/Low
PAUSE 5 ' Wait For HB-25 To Initialize
PULSOUT HB25, 750 ' Stop Motor 1
'DEBUG CR, "Leg motor initialized and stopped", CR

DO: LOOP UNTIL HB25_hip = 1 ' Wait For HB-25hip Power Up
LOW HB25_hip ' Make I/O Pin Output/Low
PAUSE 5 ' Wait For HB-25 To Initialize
PULSOUT HB25_hip, 750 ' Stop Motor 2
'DEBUG CR, "Hip motor INITIALIZED AND STOPPED", CR

'PAUSE 1 ' 1 mS Delay
'PULSOUT HB25, 750 ' Stop Motor 2 (If Connected)
' The Above 2 Lines May Be Removed
' If You Are Using Single Mode


'
[noparse][[/noparse] Program Code ]
Main:
PAUSE 20 ' Wait 20 mS Before Ramping
FOR index = 0 TO 250 ' Ramp Up To Full Speed
PULSOUT HB25, 750 + index ' Motor 1 Forward
PAUSE 1 ' 1 mS Delay For Motor 2 Pulse

PULSOUT HB25_hip, 750 + index ' Motor 2 Forward?

PAUSE 20 ' 20 mS Smoothing Delay

'DEBUG CR, "index = ", DEC ? index


NEXT
PAUSE 3000 ' Wait 3 Seconds
DEBUG CR, "Leg and hip motors going", CR
FOR index = 250 TO 0 ' Ramp Back Down
PULSOUT HB25, 750 + index ' Motor 1 Forward Slowing
PAUSE 1 ' 1 mS Delay For Motor 2
PULSOUT HB25_hip, 750 + index ' Motor 2 Reverse Slowing
PAUSE 20 ' 20 mS Smoothing Delay
NEXT
STOP ' Use STOP To Prevent State Change

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-01-17 02:08
    I don't see any obvious explanation for what you describe except for a power supply problem when you're trying to run two motors.
    The DEBUG statements will slow down the loops because of the time needed to transmit the debugging information, but they won't
    stop anything. If there's noise on the Stamp's power supply or if the power supply can't support two motors and the Stamp's input
    voltage supply comes from the same source, the Stamp may reset, starting the program over again.

    Unlike conventional servo motors, the HB-25 does not require a control pulse every 20ms, so they're tolerant of the additional
    delay introduced by the DEBUG statements.
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-01-17 16:15
    A common debug technique is to put

    DEBUG "Running", CR

    At the start of your program. Then, whenever you get a 'brown-out reset', you get another "Running" message on your debug screen. Getting a brown-out reset means you need to supply more power (bigger batteries -- AA to C, C to D) for your motors.
  • heidikayheidikay Posts: 2
    edited 2008-01-17 17:33
    thanks for the advice. I have some questions about how to use the code to set the motor's speed for a specific duration.


    1) I understand what the sample code's logic is doing here, but if I wanted to instead make the motor stay a certain speed for 1 second, for example, how would I do that?
    their Sample code:
    FOR index = 0 TO 250 ' Ramp Up To Full Speed
    PULSOUT HB25, 750 + index ' Motor 1 Forward

    I'm not sure I understand how the Pulsout command works. Does the 750+X refer and provide the direction only (above 750 = forward direction) or does it also provide speed information? if I wanted it to stay a certain speed, would I set that with the index value or the pulsout value?
    then, do I just add a Pause 1000?

    so, for example if I wanted the motor to go 1/2 speed for 1 second, do I have to use the index value AND the pulsout, so it might look like:
    index = 125
    pulsout hb25, 750 + index (what does the 750 + index get me besides forward direction?)
    pause 1000

    or
    could I do something with ONLY the pulsout settings---not sure exactly how to do that?

    pulsout hb25, 1025 'pick a mid point number between 750 and 1500?
    pause 1000
  • DgswanerDgswaner Posts: 795
    edited 2008-01-17 18:25
    if you have the HB25's changed in dual mode the first thing that threw me was you have to send commands to both motors even if your not changing one of them. at lest that's how it is with the propeller,

    The pulse provides both the direction and the speed. it's like controlling a continuous servo. 1000 would be full reverse 1500 would be stop and 2000 would be forward full. anywhere in between there would be a slower speed in the same direction. the numbers above are just an example.

    index = 125
    pulsout hb25, 750 + index (what does the 750 + index get me besides forward direction?)
    pause 1000

    all this would do is pulsout at 875 for 1 second

    it would be exactly like:
    pulsout hb25, 875
    pause 1000

    FOR index = 0 TO 250 ' Ramp Up To Full Speed
    PULSOUT HB25, 750 + index ' Motor 1 Forward
    pause 1000

    this however would slowly ramp up the speed of the motors because your adding 250 each time through the loop but this would take 10 seconds to get to full speed.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster

    DGSwaner

    Post Edited (Dgswaner) : 1/17/2008 7:00:41 PM GMT
Sign In or Register to comment.