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

Controlling Servos With Serout Command

ScarecrowScarecrow Posts: 38
edited 2005-06-11 21:22 in BASIC Stamp
hi guys,

i just received my new bs2 px24 and i was wandering if you could explain to me how to control the servos with the serout command in detail, since ive been searching in the forum and i dont understand all the parameters you guys put in the serout command i would appretiate a parameter by parameter explanaition =P thanks A LOT!!!·in advance =D

Comments

  • NewzedNewzed Posts: 2,503
    edited 2005-06-10 19:59
    Very simple.

    You write
    lserv pin 0
    rserv pin 1
    baud con 16636
    com· var byte
    x····· var word

    start:

    serout 16, baud, [noparse][[/noparse]Enter command", cr]
    debugin com·············· 'you press r or l
    if com = "R" or com = "r" then
    for x = 1 to 500
    pulsout 1, 800············ 'servo rotates right
    pause 20
    next
    endif

    if com = "L" or com = "l" then
    for x = 1 to 500
    pulsout 0, 600············ 'servo rotates left
    pause 20
    next
    endif

    goto start

    That's all there is to it.· Do you understand?





    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Need a bezel for your LCD?

    Newzed@aol.com
    ·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-06-10 20:04
    Scarecrow:

    You should download and read our "What's A Microcontroller?" text -- it will get you going on servos and lots of other things.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • ScarecrowScarecrow Posts: 38
    edited 2005-06-10 22:39
    im sorry, i think i couldnt explain myself, what i wanted to do was to control a servo with the serout command not the pulsout one and i wanted to know how since the bs2px24 has different timings than the others etc....
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-06-11 00:11
    You can find the standard timing values for the BS2px in the help file, as well as the formula for calculating the parameter for any baud rate.

    I make my life easy by having this Conditional Compilation segment in my programming template (attached).· SERIN/SEROUT paramaters always get people in trouble; that's why I built them in.

    #SELECT $STAMP
    · #CASE BS2, BS2E, BS2PE
    ··· T1200······ CON···· 813
    ··· T2400······ CON···· 396
    ··· T4800······ CON···· 188
    ··· T9600······ CON···· 84
    ··· T19K2······ CON···· 32
    ··· TMidi······ CON···· 12
    ··· T38K4······ CON···· 6
    · #CASE BS2SX, BS2P
    ··· T1200······ CON···· 2063
    ··· T2400······ CON···· 1021
    ··· T4800······ CON···· 500
    ··· T9600······ CON···· 240
    ··· T19K2······ CON···· 110
    ··· TMidi······ CON···· 60
    ··· T38K4······ CON···· 45
    · #CASE BS2PX
    ··· T1200······ CON···· 3313
    ··· T2400······ CON···· 1646
    ··· T4800······ CON···· 813
    ··· T9600······ CON···· 396
    ··· T19K2······ CON···· 188
    ··· TMidi······ CON···· 108
    ··· T38K4······ CON···· 84
    #ENDSELECT

    SevenBit······· CON···· $2000
    Inverted······· CON···· $4000
    Open··········· CON···· $8000

    Baud··········· CON···· T9600

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • ScarecrowScarecrow Posts: 38
    edited 2005-06-11 12:25
    im too ignorant for the manual and i couldnt understand it :P so for example if i want to put the servo in center position i need a 1.5ms signal, what should i do? with serout?
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-06-11 14:59
    That depends, of course, on which servo controller you're using. Parallax PSC? SEETRON SSC? Other? They all have different protocols. If you're under the impression you can send a serial message directly to a servo, well, you can't.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-06-11 15:31
    Yes, if you hook the center wire from the Servo (I'm pretty sure that's the signal wire) to an I/O pin on the BS2, then you will HAVE to use the pulsout command to control the servo. That's the signal a Servo wants.

    LOW ServoPin ' Make Servopin an Output, and output a zero 'idle' state
    ServoRefresh:
    PULSOUT ServoPin, 750 ' This will send it to center position
    PAUSE 20 ' A servo signal should be 'refreshed' every 20 to 50 mSec to hold a position
    GOTO ServoRefresh

    If you have a Servo Driver board of some kind (like the PSC) then you talk to THAT board with SEROUT, and THAT board will send pulsout-equivalent signals to the Servo.

    A servo, by itself, does not know the SEROUT RS-232 protocol. You have to 'talk' what your device knows how to listen to. And the BS2 is well designed to 'talk' what a servo knows how to recieve -- the PULSOUT command does that.

    P.S.· Oops, the '750' value will give you a 1.5 mSec pulse (center) on a BS2.· On a BS2px, you'll have to look in the manual to find the equivalent value.
  • ScarecrowScarecrow Posts: 38
    edited 2005-06-11 17:11
    ive seen that in the other bs2 they do not use pulsout but instead serout and i would like to learn how to do that
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2005-06-11 17:45
    First of all don't think that you aren't advanced enough for the "What's a Microcontroller"- it was written to be very accessable to people just learning (hence the title!) and it's a great place to start as Jon pointed out. And you can download it for free. You really should take a look at it...

    If you've seen other code listings using serout and serin for controlling a servo then they are talking to some type of controlling device, such as the PSC controller. They are not sending serout/in commands directly to the servo; a servo only understands pulses, and varying those tell the servo were to turn to. (In the case of the continuous rotation servos they are sent a pulse to move/not move- this is because they are trying to reach a position that they will from their perspective never get to)- So all the fancy control of a servo is simply a function of changing the pulses you are sending. The PSC can alter those pulses in such a way as to make the resulting motion faster, slower, etc. - the SEROUT commands from the stamp are taken by the PSC and turned into the necessary pulses.

    So try reading What's a Microcontroller, and then the documentation for the PSC.

    You can find them here:

    http://www.parallax.com/dl/docs/books/edu/wamv2_2.pdf (What's a Microcontroller)
    http://www.parallax.com/dl/docs/prod/motors/ServoController.pdf (PSC)

    Ryan
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-06-11 18:00
    Scarecrow -

    I think you may be missing what is being said. Here is a summary.

    All standard R/C servos which are controlled directly from the Stamp, are controlled using the PULSOUT command, regardless of which Stamp platform you are using.

    A 1.5 mSec pulse will center any standard R/C servo. Different values are used in the PULSOUT command to develop this 1.5 mSec pulse, since the speed of execution in many of the Stamps differs. The Stamp MANUAL or the Stamp Editor Help File, is your guide to the specific values required. Learning how to CENTER an R/C servo is the best first step you can make, in understanding how they operate using the Stamp as a servo driver.

    Usually SEROUT is used ONLY when a separate Servo Controller Board (regardless of whose board it is) is used to drive the R/C servos, rather than having them driectly driven and controlled by the Stamp, regarless of the Stamp model. I say "usually" since I'm not familiar with the newer digital R/C servos, and I'm not sure how they are controlled. All analog servos will NOT respond properly to ANY SEROUT commnad, on ANY Stamp.

    Servo Controller Boards are used when it's necessary to control multiple (more than two or three) servos simultaneously, and/or to permit the Stamp to do other things while the R/C servo motion is being controlled by the board. Otherwise the Stamp will be spending most of its time updating and refreshing the R/C servos as is necessary for their proper operation. One single command will not move an R/C servo to a particular position and keep it there indefinitely.

    If you have a reference or link to the contrary, we'd be happy to take a look at it for you.

    My apologies if this message sounds a bit stern, it wasn't meant to be. I just wanted to try to straighten out, in simple terms, what's been said in numerous different posts prior to this.

    Regards.

    Bruce Bates
  • ScarecrowScarecrow Posts: 38
    edited 2005-06-11 21:22
    thanks a lot for your post. It kind of cleared everything for me, I guess I wasn't paying enough attention to the other posts and also i kind of flash answered to them and i apologize......=(
Sign In or Register to comment.