Shop OBEX P1 Docs P2 Docs Learn Events
Using 2 Continuous Rotation Servos at Once — Parallax Forums

Using 2 Continuous Rotation Servos at Once

Hi all,

I am trying to move something on an x-y table, controlled by two continuous rotation servos. I am wondering how to get from point A to B "as the crow flies", by making both servos run simultaneously, as opposed to moving in direction 1 for a period of time and then direction 2 for a period of time. The main obstacle I am facing is getting both servos to operate at exactly the same time. If anyone could help me code this, that would help a lot. I'm using the Basic STAMP Board of Education revC.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2015-10-24 14:40
    ' count1 is time to run for servo 1 (20ms units)
    ' time1 is servo 1 control pulse width (2us units)
    ' count2 & time2 are similar for servo 2
    
    ' This loop outputs servo control pulses as needed for
    ' servos 1 and 2 approximately every 20ms compensating
    ' for the times needed for the control pulses.  When both
    ' servos are no longer running, the loop stops.
    
    do while count1 > 0 and count2 > 0
      delay = 10000  ' 20 milliseconds
      if count1 > 0 then  ' servo 1 still running
        pulsout servo1,time1  ' PULSOUT takes time1 to execute
        delay = delay - time1  ' adjust for that (2us per unit)
        count1 = count1 - 1  ' one less 20ms period to go
      endif
      if count2 > 0 then  ' same thing for servo 2
        pulsout servo2,time2
        delay = delay - time2
        count2 = count2 - 1
      endif
      pause delay / 500  ' delay 20ms less time for servo pulses
    loop
    

    The above code will run both servos at the same time with independent speed settings and durations, but servos are pretty sloppy. How are you going to ensure that you've moved to the coordinates you think you've moved to, particularly after several moves?
  • ercoerco Posts: 20,256
    Per Mike, you can certainly move 2 CR servos simultaneously, but they don't have any positional feedback. Speed ( thus transit time) varies with load, voltage, and other variables , so you'll never move very accurately. Errors get larger, unless you add encoders.
Sign In or Register to comment.