Shop OBEX P1 Docs P2 Docs Learn Events
Can I control several servos via BS2 simultaneously, like with servo controller? — Parallax Forums

Can I control several servos via BS2 simultaneously, like with servo controller?

hellobazovhellobazov Posts: 5
edited 2012-09-13 01:33 in BASIC Stamp
Thank you!

Comments

  • ercoerco Posts: 20,257
    edited 2012-09-01 15:50
    Heck no. That would cause a black hole! At least a worm hole. Maybe just a hole lotta servo noise.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2012-09-01 16:47
    I'm familiar with that exercise.
    "Control" can be interpreted in many ways.
    Those are all running the same routine, in succession, in a loop.
    Anything more "dynamic"?
    Could each be set to a different position, given some user or sensor input, leaving the others unchanged?
  • ercoerco Posts: 20,257
    edited 2012-09-01 19:42
    Quite. :):)

    A Stamp can easily control 3 servos while doing some useful i/o operations:
    http://www.youtube.com/watch?v=J5GMOAIQbJ4
    http://www.youtube.com/watch?v=-Z8lTSX4PHs

    Four or more requires some tight programming and less i/o stuff.
  • Mike GreenMike Green Posts: 23,101
    edited 2012-09-01 19:55
    To try to be more specific answering your question ... The BS2 is a single threaded processor ... It can do only one thing at a time. Since providing control pulses to servos is part-time work, there's some overlap possible so it's possible to control two or three servos plus do a little bit of sensor reading and a little bit of computation. The BoeBot does this normally with the two wheel servos plus a PING))) sensor and even a PING))) servo bracket, but there's not much time for anything else and the BS2 is not a really fast microcontroller. As PJ noted, you're much better off using some sort of external hardware to offload the production of individual servo control pulses from the Stamp. One or two StampPALs is perfect for this for 2 to 4 servos.
  • hellobazovhellobazov Posts: 5
    edited 2012-09-01 22:39
    Thank you all! Thank you Mike! I needed to be more specific too. I want to control a robot arm, i.e. something like three servos simultaneously. From your response, I hope I understand it right, processor sends pulse to servos one after another (in code), but because a human eye can't see the difference in few milliseconds, it looks like "smooth" moving. But it must be enough for me. maybe for the future upgrade I'll learn to use servo controller.
  • Mike GreenMike Green Posts: 23,101
    edited 2012-09-02 09:20
    Look at some of the tutorials for the BoeBot. They have all sorts of sample code that uses the two wheel servos on the BoeBot. A third servo would use another 2ms or so out of a 20ms cycle.

    The main timing issue is that servos require a control pulse about once every 20ms. If this is missing, the servo turns off until it sees the next control pulse. This on / off cycling causes jerky movement, so you want to avoid it. Stamp programs using servos thus work in 20ms cycles using PULSOUT statements to provide the control pulses and PAUSE statements to fill out the 20ms cycles. The control pulses usually range from 1ms to 2ms, but could be as long as 2.5ms plus a few hundred microseconds for the PULSOUT statement. Figure 3ms for one servo.

    For 3 servos, you'd need to allow for 9ms. That leaves about 11ms for other things. There'll be some calculations or sensor reading that will take up some of this and the rest will be absorbed by a PAUSE statement. Often when some of the servos are not moving, they're allowed to turn off. They won't hold position if under tension, but the friction of the gears is often enough so that they won't slip, certainly in the case of wheel servos not on a steep incline. A robot arm may or may not tolerate this depending on how it's made and how much load is present on it.
  • hellobazovhellobazov Posts: 5
    edited 2012-09-13 01:33
    Thank you very much, Mike!
Sign In or Register to comment.