Shop OBEX P1 Docs P2 Docs Learn Events
Controlling a servo — Parallax Forums

Controlling a servo

TinCansAssocTinCansAssoc Posts: 9
edited 2008-03-14 12:59 in Propeller 1
Hi, I'm new at using my propeller and I'm trying a few basic projects to learn more about it. right now I'm trying to control a servo, but I haven't found how to do it. Could someone help me out with so me code for controlling a standard servo. I'm confused on what the best commands are for doing this with the propeller chip. (I'm starting with the propeller education kit, and a servo)
Thanks, this will be much appreciated.

Comments

  • Goska (OSURC)Goska (OSURC) Posts: 3
    edited 2008-03-07 16:30
    I'd recommend looking at the servo32v3 object. It can handle all of the servo control in a new cog and you just send it positions. The documentation within the object is very good. Start there and see if that will work for you. If not, you can always write your own, you just have to send a pulse to the signal line of the servo (for most, analog, servos).
  • deSilvadeSilva Posts: 2,967
    edited 2008-03-07 16:31
    There are zillions of Objects doing this - I think.

    I generally use my own code of a few lines...
    Here a link to some general PWM Tutorial
    propeller.wikispaces.com/PWM
    which will soon lead you back to a tutorial somewhere burried here in this forum...

    I might use your questions to improve some of it..
  • JerryAJerryA Posts: 11
    edited 2008-03-11 07:24
    Hi there:
    I am using the servo32 object to control 3 servos in an insect style robot based on the book Insectronics by
    Karl Williams. My ultimate goal however is to build a homebrew version of a hex crawler similar to the
    Crust Crawler or Nomad. Therein lies my problem with servo32. According to my reading of it's self-documentation
    it is capable of controlling up to 32 servos with a single cog and I do not see how this could be possible for the following
    reason. A servo requires a 1 to 2 msec. pulse at least once every 20 msec. This gives a maximum of 10 servos per
    20 msec. frame. If you try to do more than 10 servos therefore (using a single cog) you will exceed the 20 msec.
    refresh requirement. There are 50 20msec frames in one second which is what gives rise to the ~50 hz refresh rate.
    As nearly as I can see right now my best bet would be to use 2 cogs per 9 servos which would give me the 18 I need
    (6 legs 3 DOF). This leads me to another difficulty with servo32 in that it appears that it launches itself into the next
    available cog when you call its start method. then your program calls it with pin and duration parameters. I am not
    sure how one would go about launching two copies of servo32 and keeping track of which was doing what. I know that
    someone else has successfully written propeller code to control a Crust Crawler but I don't have access to it, and besides
    the whole point of this exercise (aside from having fun) is to learn about the capabilities of the prop. smilewinkgrin.gif
    Any hints tips or help to figure out what I'm missing here would be appreciated. smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    jac {^[noparse]:)[/noparse]}

    Never underestimate the power of human stupidity! (It bites me all the time!)
  • deSilvadeSilva Posts: 2,967
    edited 2008-03-11 07:53
    @Jerry: Read my tutorial - I explain there what the drawbacks are, and give a different method than Beau used. Beau's concept is limited to 32 with his self constrained limitation of 1/1000 resolutions. When you constrain yourself to 1/100 or 1/256 only there is more headroom.

    Follow the links given above.
  • Beau SchwabeBeau Schwabe Posts: 6,560
    edited 2008-03-11 16:08
    Jerry,
    What you’re describing would be true if each servo was activated sequentially, but that's not the case with Servo32.· Servo32 groups the pins into 4 groups of 8 servos.· Each group of 8 servos has an allocated time frame·of 5ms.· Among·each group ALL 8 servos are initiated at the same time or in parallel, so within 3ms or so within each allocated time frame,· ALL 8 servos are done.· 2mS are reserved for program overhead.· As·time elapses for each of the 8 servos, the·pulse signal drops off in accordance to the·set pulse duration you assign to the servo. You could allow ALL 32 servos to operate this way, but the amount of startup current required to simultaneously drive 32 servos can become problematic.· 8 servos is a much friendlier number to work with.· As far as resolution limitations...· This application is geared·toward hobby servos, which simply put... aren't really that accurate.· Anything more than 1/1000 is most likely going to be overkill.· The range of Servo32 is fixed mainly to protect the servo as to not produce a signal capable of going out of bounds.· Typically this out of bounds range is 1ms·to 2ms,·however if you find that an application requires·a signal outside of this range, Servo32 can be adjusted for a pulse up to 2.75ms and down to 0.25mS.· I hope that this clears up any confusion with Servo32.
    ·




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 3/11/2008 4:14:26 PM GMT
  • TinCansAssocTinCansAssoc Posts: 9
    edited 2008-03-14 06:09
    Can someone better explain to me how the user input works for servo32? I hooked up my servo and it just pulls to the left till it stops jitters a bit. I know I'm a bit of a noob so my knowledge of objects is slim. Understand the servo is looking for a pulse width, but it's unclear to me what vales I put into servo32 to get what I need, I don't understand why my servo is only going left since it's an unmodified standard servo. I must be me screwing up the servo32 demo code.
  • Beau SchwabeBeau Schwabe Posts: 6,560
    edited 2008-03-14 06:45
    TinCansAssoc,

    What does your wiring to the servo look like?
    What voltage are you powering the servo with?
    Are you sharing the same ground connection of the servo(Black) with the Propeller (Vss)?... If not,·it should be shared.

    The "Servo32_v3 Demo.spin" should pan a servo back-n-forth on P0 when connected to·the Propeller.· Make sure that
    this program works first before you make any modifications.


    Say for example you have a servo on pin 5 (P5) that you want to initialize·to center position.· The code might look something
    like this:
    CON
        _clkmode = xtal1 + pll16x                           
        _xinfreq = 5_000_000                                'Note Clock Speed for your setup!!
        
    OBJ
      SERVO : "Servo32v3"
    PUB Servo32_DEMO
        SERVO.Set(5,1500)                                   'This initiallizes the Servo handler and indicates that we will be using a servo on pin 5
        SERVO.Start                                         'Start Servo handler
        repeat                                              'Keep the COG alive ; repeat forever
    

    You MUST initially use 'SERVO.Set' to tell the servo handler which pins that you are using for the servo(s).· This needs to be done before you actually start the servo handler with 'SERVO.Start'.
    Once that is done (just two lines of code) you can use the 'SERVO.Set' to position the servo at any position between 1ms (1000) and 2ms (2000) at any time through the remainder of the program.

    ·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • JerryAJerryA Posts: 11
    edited 2008-03-14 06:51
    Hi there again:
    @ deSilva: Will do. I have read some of your stuff before and have found it both interesting and informative.
    @ Beau: Thanks for the enlightenment. I knew from the internal docs about the time slots, but I didn't realize
    the full implications. I fully understand about the current surge problem, and I think your solution to it is really slick!
    yeah.gif (nodding with fuller understanding). Although this may complicate making a smooth walking gait for
    my hex crawler application, I think judicious pin allocation can solve a lot of it. It'll require some thought though.
    As for the resolution thing, it does seem rather useless to waste processing bandwidth on resolution that the mechanics
    just aren't able to deliver.. smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    jac {^[noparse]:)[/noparse]}

    Never underestimate the power of human stupidity! (It bites me all the time!)
  • TinCansAssocTinCansAssoc Posts: 9
    edited 2008-03-14 12:59
    geez, I didn't even think about having the different voltages on the same ground. well my servo works now thanks Beau, that should be all I need. I think my hardest challenge learning about the propeller is understanding how to hook up my hardware correctly so that everything works. I wish the demo codes had sample pin diagrams.
Sign In or Register to comment.