Shop OBEX P1 Docs P2 Docs Learn Events
need some help with servo programming — Parallax Forums

need some help with servo programming

b0ib0i07b0ib0i07 Posts: 33
edited 2010-12-20 02:34 in BASIC Stamp
currently using BS2 and hitec HS-815BB servo.

do

pulsout 14, 900

loop

the servo moved. however its so slow....
any way to move it faster?:confused:

Comments

  • ercoerco Posts: 20,256
    edited 2010-10-04 01:52
    a:for b0=1 to 200

    pulsout 14, 900

    pause 20

    next

    for b0=1 to 200

    pulsout 14, 500

    pause 20

    next

    goto a
  • b0ib0i07b0ib0i07 Posts: 33
    edited 2010-10-04 07:07
    erco wrote: »
    a:for b0=1 to 200

    pulsout 14, 900

    pause 20

    next

    for b0=1 to 200

    pulsout 14, 500

    pause 20

    next

    goto a


    thank you for the code you gave me.
    can you explain to me the code please?
  • Mike GreenMike Green Posts: 23,101
    edited 2010-10-04 07:15
    There's a good discussion of servos and how to write programs for them in the "Robotics for the Boe-Bot" tutorial here.

    The problem with your original program fragment is that servos need a control pulse 50 times a second, not faster (it can't respond to it properly) and not slower (it will shut off if it doesn't get a control pulse). The PAUSE 20 provides the timed delay to make this happen.
  • b0ib0i07b0ib0i07 Posts: 33
    edited 2010-10-04 16:57
    ty!
  • b0ib0i07b0ib0i07 Posts: 33
    edited 2010-10-04 17:12
    Control System: +Pulse Width Control 1500usec Neutral
    Required Pulse: 3-5 Volt Peak to Peak Square Wave
    Operating Voltage: 4.8-6.0 Volts
    Operating Temperature Range: -20 to +60 Degree C
    Operating Speed (4.8V): 0.48sec/140° at no load
    Operating Speed (6.0V): 0.38sec/140° at no load
    Stall Torque (4.8V): 274.96 oz/in. (19.8kg.cm)
    Stall Torque (6.0V): 343.01 oz/in. (24.7kg.cm)
    Operating Angle: 70 Deg. one side pulse traveling 400usec
    360 Modifiable: Yes
    Direction: Clockwise/Pulse Traveling 1500 to 1900usec
    Current Drain (4.8V): 8mA/idle and 700mA no load operating
    Current Drain (6.0V): 8.7mA/idle and 830mA no load operating
    Dead Band Width: 8usec
    Motor Type: 3 Pole Ferrite
    Potentiometer Drive: Indirect Drive
    Bearing Type: Dual Ball Bearing
    Gear Type: All Heavy Duty Nylon Gears
    Connector Wire Length: 11.81" (300mm)
    Dimensions: 2.59" x 1.18"x 1.26" (66 x 30 x 57.6mm)
    Weight: 5.6 oz. (152g)

    Above are the info i have on this servo.
    I do have a question.
    Is the board of education able to supply the current needed by using the board Vdd and Vss to power up the servo?
  • ercoerco Posts: 20,256
    edited 2010-10-04 18:47
    You should supply servo power from your external battery pack. A 6V pack can power your servos directly and also power your Stamp through Vin.
  • b0ib0i07b0ib0i07 Posts: 33
    edited 2010-10-04 19:39
    erco wrote: »
    You should supply servo power from your external battery pack. A 6V pack can power your servos directly and also power your Stamp through Vin.

    Meaning i connect the servo red wire to Vin and black wire to Vss?
    But, i am using a 9V battery instead...
  • ercoerco Posts: 20,256
    edited 2010-10-04 20:21
  • b0ib0i07b0ib0i07 Posts: 33
    edited 2010-10-05 00:11
    erco wrote: »
    You should supply servo power from your external battery pack. A 6V pack can power your servos directly and also power your Stamp through Vin.

    By the way, just to ask. How much current can a 6V battery pack supply? :confused:
  • ctdahlectdahle Posts: 29
    edited 2010-10-05 03:28
    b0ib0i07 wrote: »
    By the way, just to ask. How much current can a 6V battery pack supply? :confused:

    Depends on the type of cells you are using. For example, the alkaline AAs from a major manufacturer are rated to deliver about 2800 mAH. That is 2800, milliAmps for one hour. For a few minutes, they can deliver a lot more, but then they wear out much faster.

    Unloaded, your servos draw 830 mA, so if you are running one servo continuously, and nothing else, you'd get about 3 hours of run time (3 x 830 = 2490mAH) and loosely accounting for the current drawn by your board as well. Under load, they would draw more.

    Assuming you are running two continuous rotation servos to drive a robot, they would be under load, so they would draw more current, maybe up to an Amp (1000mA), so estimate an hour of run time on a pack made from four AA alkaline cells before things start to slow down.

    Switch to recharge-ables and you get a little less runtime. NiMH cells deliver between 2000 and 2600 mAH, depending on how much you are willing to pay for them, and how many charge/discharge cycles you expect them to last. They last longer if you study the charge characteristics, track how much of their capacity they have used, don't push them to the limit, and refrain from over-charging, or over-heating them.

    Tracking the performance of rechargeable batteries and better managing them is actually one of the data logging tasks that got me interested in micro controllers in the first place. I wanted to measure and log the current being drawn by all of the devices in a model airplane over the course of a morning at the flying field and then compare the current "consumed" to the factory specifications of the battery, then use this information to optimize battery charging. I wanted to see if there was an appreciable change in the service life of the batteries compared to the standard model airplane practice of "charge them over night before flying and then discard them after they've been used 200 times, or every 2 years, whichever comes first".

    But then I got interested in robotics and haven't flown the planes for a couple of years...
  • b0ib0i07b0ib0i07 Posts: 33
    edited 2010-10-05 05:39
    ctdahle wrote: »
    Depends on the type of cells you are using. For example, the alkaline AAs from a major manufacturer are rated to deliver about 2800 mAH. That is 2800, milliAmps for one hour. For a few minutes, they can deliver a lot more, but then they wear out much faster.

    Unloaded, your servos draw 830 mA, so if you are running one servo continuously, and nothing else, you'd get about 3 hours of run time (3 x 830 = 2490mAH) and loosely accounting for the current drawn by your board as well. Under load, they would draw more.

    Assuming you are running two continuous rotation servos to drive a robot, they would be under load, so they would draw more current, maybe up to an Amp (1000mA), so estimate an hour of run time on a pack made from four AA alkaline cells before things start to slow down.

    Switch to recharge-ables and you get a little less runtime. NiMH cells deliver between 2000 and 2600 mAH, depending on how much you are willing to pay for them, and how many charge/discharge cycles you expect them to last. They last longer if you study the charge characteristics, track how much of their capacity they have used, don't push them to the limit, and refrain from over-charging, or over-heating them.

    Tracking the performance of rechargeable batteries and better managing them is actually one of the data logging tasks that got me interested in micro controllers in the first place. I wanted to measure and log the current being drawn by all of the devices in a model airplane over the course of a morning at the flying field and then compare the current "consumed" to the factory specifications of the battery, then use this information to optimize battery charging. I wanted to see if there was an appreciable change in the service life of the batteries compared to the standard model airplane practice of "charge them over night before flying and then discard them after they've been used 200 times, or every 2 years, whichever comes first".

    But then I got interested in robotics and haven't flown the planes for a couple of years...

    thank you very much for the info :smilewinkgrin:
  • b0ib0i07b0ib0i07 Posts: 33
    edited 2010-12-15 23:23
    I have encountered some problems with servo programming and need help again.

    a:for b0=1 to 200
    pulsout 14, 900
    pause 20
    next

    This above code does allow me to move the servo to my desired position. However, after a while, the servo begins to "jerk" off from my desired position.
    From my knowledge of servo, a continuous pulse is needed to hold the position of the servo. Can i assume that this condition is happening to my servo as it had exited the for-loop?

    If that is so, is that any way to hold the servo in a certain position?
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2010-12-16 03:16
    You have to keep in the loop in order to hold position OR at least refresh the pulse withing 20 milliseconds. R/C servos are not to rigid about the the refresh rate, but the the width of the high pulse decides position. So in theory, you can do two tasks if you get back to refreshing the high pulse in a bit less than 20 MS. Sometimes you can, and other times it is best to have a Servo Controller handle this task while the BasicStamp does other things.

    I am not sure you really have to hold to 20 mS in the above pause - maybe 18-19 mS would be better as the TOTAL pulse cycle is suppose to be 20 mS. Sorry but I disagree with Mike Green.
  • b0ib0i07b0ib0i07 Posts: 33
    edited 2010-12-16 04:01
    Hmmm. Ok. But, if i repeat the pulse to hold the servo position, wont my program be stuck in the pulse "repeating" loop?

    My idea is to move the servo to the position i want then hold the position while my program continue to execute the other command.
    Is this possible?
  • Mike GMike G Posts: 2,702
    edited 2010-12-16 06:35
    @Loopy Byteloose, Mike Green is simply stating that servos requires a pulse at least every 20ms to hold position.

    @b0ib0i7, You're right, you have to loop to hold position just like you have to loop to move. You don't have to pause in the loop, you could always do something else during that time. Maybe poll an input? Did you look at the link provided by Mike Green?

    If the polling logic is too much, I suggest picking up a, Parallax Servo Controller to handle servo control.
  • ercoerco Posts: 20,256
    edited 2010-12-16 17:19
    @b0ib0i7: The challenge here is to write useful code that sends regular servo pulses while still executing your other code. You need to come up with a way to weave your program together so that it does something useful for a while (instead of just a pause 20) then sends a servo pulse, then repeats. It seems a bit complicated at first, but stick with it, you can make it happen. Your "something else" code can check on some sensors or other things. That will take a few milliseconds, maybe 5 (experiment to determine). Then you may need to insert a pause 15 to keep the total time about 20 ms before sending another servo pulse. Takes some trial & error, but you'll do the right thing!
  • b0ib0i07b0ib0i07 Posts: 33
    edited 2010-12-16 18:16
    erco wrote: »
    @b0ib0i7: The challenge here is to write useful code that sends regular servo pulses while still executing your other code. You need to come up with a way to weave your program together so that it does something useful for a while (instead of just a pause 20) then sends a servo pulse, then repeats. It seems a bit complicated at first, but stick with it, you can make it happen. Your "something else" code can check on some sensors or other things. That will take a few milliseconds, maybe 5 (experiment to determine). Then you may need to insert a pause 15 to keep the total time about 20 ms before sending another servo pulse. Takes some trial & error, but you'll do the right thing!

    I got what u meant. Thanks for the help. I will try it out. =]
  • b0ib0i07b0ib0i07 Posts: 33
    edited 2010-12-16 20:03
    Just another enquiry. Lets say i sent a pulse to the servo. It moved to a position. Afterwhich, i stop sending the pulse. What will happen to the servo?
  • Mike GreenMike Green Posts: 23,101
    edited 2010-12-16 20:11
    Eventually the servo will turn itself off. There is no specification of when, but it's probably somewhere between 25ms and 40ms. When the servo is off, the only thing holding the motor and the shaft in position is friction in the gearchain and the motor. When the motor gets another control pulse, it will turn itself on again for 20ms or so and try to go back to the specified position. Remember that it takes longer than 20ms to move more than a small distance.
  • b0ib0i07b0ib0i07 Posts: 33
    edited 2010-12-20 02:34
    Mike Green wrote: »
    Eventually the servo will turn itself off. There is no specification of when, but it's probably somewhere between 25ms and 40ms. When the servo is off, the only thing holding the motor and the shaft in position is friction in the gearchain and the motor. When the motor gets another control pulse, it will turn itself on again for 20ms or so and try to go back to the specified position. Remember that it takes longer than 20ms to move more than a small distance.

    Hi Mike Green

    I would like to clarify something with you as you are more exeperienced with servo. From the above, u told me that the servo wil shut itself off if no pulse is sent. I enter the code as shown below:

    FOR a = 0 to 100

    PULSOUT 14, 600
    PASUE 20

    NEXT

    The servo moved to the specified position. However, after the servo exited the for-loop, the servo begin to jerk clockwise slowly.
    May i know what is causing it to jerk?
Sign In or Register to comment.