Shop OBEX P1 Docs P2 Docs Learn Events
Controlling 2 servos at almost the same time with BS2 — Parallax Forums

Controlling 2 servos at almost the same time with BS2

jacko87jacko87 Posts: 6
edited 2009-06-17 08:55 in BASIC Stamp
Hi all,

I have a problem with my project. I need to run at least 2 servo motors at almost the same time using BS2. Here is my simple BS2 code:

' {$STAMP BS2p}
' {$PBASIC 2.5}

PULSE VAR Word
PULSE2 VAR Word

Init:
PULSE2 = 1670

MAIN:
FOR PULSE = 2100 TO 1250 STEP 5
PULSOUT 0, PULSE
PULSOUT 1, PULSE2
PULSE2 = PULSE2 + 5
PAUSE 20
NEXT




the specification of the 1st servo is pulse 2100 at -90deg and pulse 1250 at 90deg, and the 2nd servo is pulse 2350 at -90deg and pulse 1670 at 90deg.
The code above will make 1st servo run slowly from -90deg to 90deg, however the 2nd servo will run from 90deg to more then -90deg.

I need the 2nd servo to run to -90deg (from pulse 1670 to 2350). The servo I use is GWS S-125 Standard 360Deg. Can anyone help me with this?

Thx before..

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2009-06-17 06:26
    The Delta of your main PULSE is 850, or 170 after you divide the step increment from 2100 to 1250

    If you need PULSE2 to go from 1670 to 2350, then that's a Delta of 680, or 136 after you divide the step increment.

    For your code, instead of using the line...

    PULSE2 = PULSE2 + 5

    ... change it to...

    PULSE2 = PULSE2 + 4

    ... 4 times 170 (<- the number of iterations from your FOR/NEXT loop) equals 680 which is the Delta you want on PULSE2

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

    IC Layout Engineer
    Parallax, Inc.
  • jacko87jacko87 Posts: 6
    edited 2009-06-17 08:55
    Thx for the reply Beau Schwabe. Yes I just figured it out and tried it, both servos can run at the same time, but there is delay for the 1st servo to run when it reach the end of its pulse (2100 and 1250).. So when the 1st servo reach 2100 or 1250, it stop for a moment, while the 2nd servo keep moving.. What could be the cause for the delay?

    is there other method to run 2 servos at almost the same time? I thought of using FOR too for the 2nd Servo, but the loop for the 2nd servo will be carried out repetitively.. Can I combine AND or OR Function with FOR?
Sign In or Register to comment.