Shop OBEX P1 Docs P2 Docs Learn Events
control of servo position — Parallax Forums

control of servo position

panagiotispanagiotis Posts: 14
edited 2006-01-14 09:32 in BASIC Stamp
HELLO. I TRY TO IMPLEMENT A PROJECT RELATED TO A ROBOTIC ARM WITH 4 DEGREES OF FREEDOM.I USE THE BS/2 AND HITEC SERVOS.·MY QUESTION IS HOW (IN THE BS/2 PROGRAM) CONTROL THE POSITION OF 2 OR MORE SERVOS SIMULTANIOUSLY·TO PRESERVE THEIR POSITION WITH DO LOOPS E.G.IF I WANT TO MOVE·THE SHOULDER AT A DESIRED ANGLE A DO LOOP MUST EXIST IN ORDER·FOR THE THE SERVO TO KEEP THE POSITION CORRECT;. SO·CONSIDERING THAT IN ORDER·TO MOVE THEN THE ELBOW I NEED ANOTHER DO LOOP FOR THE OTHER SERVO. SO HOW CAN I MAKE BOTH LOOPS WORK SIMULTANIOUSLY;;cry.gif··I WOULD APPRECIATE·ANY POSIBLE ANSWER..

Comments

  • Tronic (Greece)Tronic (Greece) Posts: 130
    edited 2006-01-13 10:21
    Take a look in the attached file that·for a 5-axis robotic arm·with Pots for position encoder.

    It came from here:
    http://users.thess.sch.gr/xrysoxoidou/e107/download.php?view.24

    It would be easy to convert it for 4-axis you are·using.


    Thanos



    www.greekbotics.tk
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-01-13 13:01
    Its not as hard as you may think, a servo requires a 1-2ms pulse every 20ms, there is nothing stating that the pulses to different servos has to occur at the same time. So since you want to control 4 servos, you break the 20ms into 4 equal sections of 5ms each. Say the servo pulse width for each servo is given the variables A-D, the pseudocode for controlling all 4 would be:

    pulseout servo1 duration A

    pause 5ms-A

    pulseout servo2 duration B

    pause 5ms-B

    pulseout servo3 duration C

    pause 5ms-C

    pulseout servo4 duration D

    pause 5ms-D

    loop back to servo1

    You may need to adjust the timing to account for any additional computations you need to do within the servo control loop.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-01-13 14:42
    Or even:

    Servo1:
    pulseout servo1 duration A
    pulseout servo2 duration B
    pulseout servo3 duration C
    pulseout servo4 duration D

    Pause 20-ms

    loop back to servo1

    This works because the servo refresh will work anywhere from 20 to 50 mSec -- so as long as your code runs in 30 mSec (a pretty safe assumption, if you don't put a large 'pause' anywhere) you'll be ok.
  • Tom WalkerTom Walker Posts: 509
    edited 2006-01-13 15:14
    The easy answer is to get a servo controller to handle all of your servo needs. This would allow your program to simply tell the controller to "move servo 1 to position x" and "move servo 2 to position y", and the controller would do so (and hold them there) while the Stamp is off doing other things (checking sensors, receiving input, displaying information, etc...). Trying to accomplish this with a single-tasking Stamp would require some tricky programming to meet the timing requirements (if it was possible at all) and would likely not allow the Stamp to do anything else while it deals with the servos.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Truly Understand the Fundamentals and the Path will be so much easier...
  • panagiotispanagiotis Posts: 14
    edited 2006-01-14 09:32
    thank you all about the answers
Sign In or Register to comment.