Shop OBEX P1 Docs P2 Docs Learn Events
servo32v3 object — Parallax Forums

servo32v3 object

seadog13seadog13 Posts: 9
edited 2009-02-25 02:17 in Propeller 1
hey all, have a question for ya.

I am using the servo32v3 object and trying to get multiple servo's to work. I saw in the object file that that a max of 8 servos would receive a pulse at a time.

Only using two servo's attached different pins, I can only get one to move at a time. Is there a way to get two of them working at the same time? If so, can they go in opposite directions?


sample code that i'm using:

pub main
···· repeat
···· servo1
···· waitcnt(clkfreq + cnt)
···· servo 2

pub servo1
··· servo.set(servo1,1200)
··· waitcnt(clkfreq+cnt)
··· servo.set(servo1,1500)
··· waitcnt(clkfreq+cnt)
··· servo.set(servo1,1800)
··· waitcnt(clkfreq+cnt)

pub servo2
··· servo.set(servo2,1800)
··· waitcnt(clkfreq+cnt)
··· servo.set(servo2,1500)
··· waitcnt(clkfreq+cnt)
··· servo.set(servo2,1200)
··· waitcnt(clkfreq+cnt)

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-02-24 18:08
    You need to read the documentation for the servo object (comments in the demo program and the servo object). It explains how to use the object.

    Notice that you need to do an initial set call for each servo you intend to use, then call the start routine to initialize the object, then you can call the set routine whenever you want to change the servo position (or speed/direction).
  • seadog13seadog13 Posts: 9
    edited 2009-02-24 21:04
    i have done that mike.

    set both servos to an initial postition and then started the object all before the repeat. Sorry for not mentioning that. I plan on taking another look tonight. Will post what i find out.
  • TJHJTJHJ Posts: 243
    edited 2009-02-25 02:17
    If I understand the problem right, is it runs in sequence, if you want them to move at the same time, you need to update both of them at the same time.

    So two options, update both between each waitcnt, or start a second cog to handle the other one.


    pub main
         repeat
            servo1
    
     
    pub servo1
        servo.set(servo1,1200)
        servo.set(servo2,1800)
    'Position for servo 1 and 2 changed. 
    
        waitcnt(clkfreq+cnt) 'wait 1 second.
        servo.set(servo1,1500)
        servo.set(servo2,1500)
    'Position for 1 and 2 changed
    
        waitcnt(clkfreq+cnt) 'wait 1 second
        servo.set(servo1,1800)
        servo.set(servo2,1200)
    'Position for servo 1 and 2 changed. 
    
        waitcnt(clkfreq+cnt) 'wait 1 second
    
     
       
    
    
    



    Also not sure if this is an effect of the forum, but make sure your function calls under Pub Main Repeat are indented in, or it will never loop correctly.
Sign In or Register to comment.