Shop OBEX P1 Docs P2 Docs Learn Events
Servo control with BS2 — Parallax Forums

Servo control with BS2

JrconeJrcone Posts: 3
edited 2009-03-08 16:40 in BASIC Stamp
I am trying to write a Basic Stamp program to control a servo motor with the Debug screen interface.
I need to be able to enter a decimal number in the Debug screen to tell the servo how many stops to make in it's movement
from fully clockwise to fully counterclockwise with a .25 second pause at each stop. It then needs to return to the starting point
in a continuous movement. I would appreciate any help anyone can give me.
Thanks

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-06 16:00
    You need to download and read 3 references:

    The Basic Stamp Syntax and Reference Manual

    What's a Microcontroller?

    Robotics with the BoeBot

    All can be found by going to the main Parallax page and clicking on the Resources tab, then clicking on the Downloads link.
    The first reference can be found under BASIC Stamp Documentation. The other two can be found under Stamps in Class Downloads.

    Look at the description of the DEBUGIN and DEBUG statements and read through the discussion in Robotics ... on servo motors and
    how to control them with a Stamp. The PULSOUT statement and the PAUSE statement are mostly what's used for that. There's lots
    of sample code included in all the references I mentioned.
  • JrconeJrcone Posts: 3
    edited 2009-03-06 20:32
    Thanks for the suggestion. I have all three references and have been going over them the last two days and still can't figure this out.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-06 20:44
    You have to divide you task up into managable pieces. For example, you need a piece that prompts the user for an entry, then gets the number typed.
    You also need a piece to divide up the range of pulse widths and moves the servo through a specified piece of its range of motion. You need a piece that pauses for 0.25 seconds, then you need a piece to move the servo back to its starting position.

    Start with those pieces. If you have specific questions along the way, ask.

    This sounds like a class project. Don't cheat.
  • JrconeJrcone Posts: 3
    edited 2009-03-08 16:22
    The part I am having problems with is the part dividing up the range of motion. I can do the other parts but I cant get the division part to work.
  • FranklinFranklin Posts: 4,747
    edited 2009-03-08 16:31
    With most servos the range is between 1 ms to 2 ms pulse and a 20ms rest between pulses. Depending on the stamp this equates to a number which you can find in the manual section on pulsout.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-08 16:40
    You'll have to figure out the range of motion of your particular servo. It tends to vary somewhat. Usually a servo will move through 180 degrees with a control pulse width ranging from 1ms to 2ms with a BS2 doing a "PULSOUT <pin>,500" up to "PULSOUT <pin>,1000" to generate a pulse. If you were going to split this range into two pieces, you'd need a control pulse ranging from 1ms to 1.5ms, a pause, then a control pulse from 1.5ms to 2ms. With 3 pieces, you divide that range into 3 segments, 1-1.33ms, 1.33-1.66ms, then 1.66 to 2ms. From your program's perspective, you're dividing up the PULSOUT parameter range, so you might have:

    1 segment - 500 to 1000
    2 segments - 500 to 750, 750 to 1000
    3 segments - 500 to 666, 666 to 832, 832 to 1000

    You figure out the general rule.

    It may be that your servo has a different mechanical range and a different range for the control pulses (and a different range for the PULSOUT statements). You may need to modify these values somewhat, but this is a good starting point.
Sign In or Register to comment.