Shop OBEX P1 Docs P2 Docs Learn Events
Controlling Servos — Parallax Forums

Controlling Servos

Sgt.Sgt. Posts: 2
edited 2010-03-13 19:27 in Robotics
OK, I'm new to Basic Stamp programming and would like to see some code examples for the BS2. I'm working on the BoeBot to learn code and don't understand how one would keep the two wheel servos in motion and control another servo or more at the same time. For example, I want to have a wheeled robot in motion and at the same time control an arm or camera servo without interrupting the wheel motion. I’m sure this is done in many designs but I’m not sure I understand the code enough to see all the ways to do this.

Thanks

Comments

  • W9GFOW9GFO Posts: 4,010
    edited 2010-03-11 19:49
    The simplest way is to use the ServoPal. It will continue to send the required pulses to the servos while your program does other things.

    Servos need a pulse approximately 50 times a second (once every 20 milliseconds). If your program loop is short then it may not be a problem to keep feeding the servos the pulses they need. Every line of code takes a bit of time to execute. When you have lots of lines of code it may take considerably more than 20 milliseconds to run through your code loop, and your servos will start to stutter. That is where the ServoPal comes in. It will, on it's own, continue to send pulses to the servos until your code tells it to do something different.

    Rich H

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Simple Servo Tester, a kit from Gadget Gangster.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-03-11 20:18
    It gets complicated interleaving the code for continuous control of a pair of servos with other code that handles either a 3rd servo or some other device. Typically, the robot stops while it does something else like scan the environment. It can be difficult mechanically doing other tasks while the robot is in motion unless it's something simple like returning an arm to its resting position. Even scanning the environment can be a problem when the robot is in motion since you don't have a stable reference position while the robot is moving. People commonly use a motor controller when there's more than 2 or 3 servos involved. The ServoPAL can handle two servos (each) and the Propeller Servo Controller can handle up to 16.
  • Sgt.Sgt. Posts: 2
    edited 2010-03-11 22:11
    Thank you. I had a feeling it would take another piece of hardware to do. I'd like to eventually do the programming in C++ using Microchip controllers. You should be able to do this by setting up timming loops too.
  • John R.John R. Posts: 1,376
    edited 2010-03-11 23:50
    Check out the Propeller!

    I have a 3DOF hexapod (18 servos) driven by a prop, with no external servo controller.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John R.
    Click here to see my Nomad Build Log
  • ercoerco Posts: 20,256
    edited 2010-03-13 04:48
    Mike is right again, of course. A Stamp does not make it easy to control multiple servos. You can buy a Servopal (or a whole different chip) that does some of the work for you.

    But it IS possible to write code that loops through sending the desired pulses to multiple servos. I'm an ardent Stamp fan and a hardhead, and I like pushing one as far as it can go. I think of a difficult task like this as a rite of passage. If you try something hard like this, you'll learn more about programming efficiently.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • allanlane5allanlane5 Posts: 3,815
    edited 2010-03-13 19:27
    See, the servo control signal is a pulse from 1 mSec to 2 mSec, repeated every 20 to 50 milliseconds. The 1 to 2 mSec pulse determines if you go forward or reverse, and gives you a little speed control. The 'refresh' repeat is so these servos can work very cheaply and simply.

    As a result, you can control two or three servos, issuing their 'pulse' one after the other, then pause for 20 milliseconds before repeating. As long as you issue all pulses before waiting 20 mSecs, this works very well without additional hardware.
Sign In or Register to comment.