Controlling Servos With Serout Command
Scarecrow
Posts: 38
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
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
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
·
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
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
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.
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
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