Shop OBEX P1 Docs P2 Docs Learn Events
contolling standard servo from basic to advance movements — Parallax Forums

contolling standard servo from basic to advance movements

sushiandmorihikosushiandmorihiko Posts: 40
edited 2007-10-16 15:54 in BASIC Stamp
hi guys--i need some help in controlling unmodified servo that turns 180 degrees. i want it to have full control of its movements like lets say move it by 10 degree and stay still in that position and when i press a button or reset it--it will come back to the center position(eehmm--first of all how do you center the servo?).long and detailed explanation are greatly welcomed in controlling standard servo.thank you for the attention

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-04 02:09
    1) Please delete your duplicate message. The box in the upper right corner of the message box will delete it.

    2) The Robotics tutorial (download from: www.parallax.com/detail.asp?product_id=28154) discusses servos, both modified and unmodified. For standard servos, you simply produce a logic level pulse with a width of 1.5ms and the servo will center itself. Shorter pulses will move the servo in one direction to a particular position and longer pulses will move the servo in the other direction. The servo requires these pulses to be repeated about every 20ms or it will turn itself off until the pulses resume. Different models of different manufactures may move slightly different amounts for the same pulse width. You have to calibrate your program to the servo you're using. The maximum range is roughly 0.5ms to 2.5ms with the officially acceptable range being 1.0ms to 2.0ms. See the tutorial for sample programs.
  • sushiandmorihikosushiandmorihiko Posts: 40
    edited 2007-10-04 02:43
    thanks mike green for the fast reply.
    i roughly get the answer but some sample codes for each of the explanation would greatly help.
    i am still vey noob in contolling standard servo--correct me if i am wrong, i found it very different than controlling continous rotation servo.
    so far,i have been controlling standard servo by trials and error without actually understanding it.
    here is how i did it:

    do

    for count = 200 to 1200 step 50
    pulsout 1, count <----this "count" represents the increment of the degrees of the servo rotating--am i correct?
    pause 50
    next

    loop

    one more question, how do you adjust the speed of the rotation for standard servo ( if continous rotation servo you just have to move the pulsout value away from 750 )

    thank you for the time
  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-04 02:55
    The PULSOUT count is proportional to the degrees of rotation of the servo, but you'll have to figure out the ratio and it will vary from servo to servo as I mentioned.

    I don't think you can adjust the speed of rotation of a standard servo. Some servos are faster than others.
  • sushiandmorihikosushiandmorihiko Posts: 40
    edited 2007-10-04 03:03
    thanks for the reply mike green--greatly appreciated
    it really helps clear my doubt in the degrees of rotation--hhmm too bad i cant adjust the speed

    is there manual or any pdf sheet (other than http://www.parallax.com/dl/docs/prod/motors/stdservo.pdf) about controlling standard servo because this topic is very crucial for my project and i need precise movement of servo

    thank you
  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-04 03:38
    Really, the other manuals that discuss this say the same thing and use essentially the same examples. I suggest you calibrate each servo you use in your project by attaching a thin rod to the servo wheel so it acts as a pointer, then center the servo over a compass (circle with degree or radian measurements marked). Write a small program that uses two buttons, one to increment the PULSOUT value until it reaches some limit (like 1250) and the other to decrement the PULSOUT value until it reaches the other limit (like 250). If you hold the button down, it will increment or decrement the value by 1 each 20ms cycle of a loop. That way, it'll take 20 seconds to go from one extreme to another ... reasonable for reaction time. If you use DEBUG to display the PULSOUT value on your PC, you can move the servo from one extreme to another and record a number of values for specific positions through the servo range. You should be able to come up with a formula for PULSOUT values given a position in degrees for example. Later, you can write another program to move the servo through a series of positions randomly and check to see how reproducible the positions are over time.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-10-04 07:41
    If rotational speed, exact positioning and repeatabilty are so important, you may want to consider using a stepper motor (geared or un-geared) and an encoder rather than an R/C servo. If you do use an R/C servo, just make sure it is capable of rotating a full 180 degrees if that is a requirement. Some R/C servos will stop-out at 160 degrees or less.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • MorrolanMorrolan Posts: 98
    edited 2007-10-04 16:16
    Hi sushiandmorihiko,

    I'm doing something similar, but I am using an 8-pin IC interfaced to my BS2e.

    The way it works is by sending a 2-byte signal to the IC. These 2 bytes are broken up into <aaaabbbb> <xxxxxxxx> (each pair of brackets is a byte)

    Where aaaa (High nibble) is speed between 0-15 (0 = fast, 15 = slow)

    Where bbbb (Low nibble) is a command from the list below

    ' 0 = Send servo 0 to position
    ' 1 = Send servo 1 to position
    ' 2 = Send servo 2 to position
    ' 3 = N/A
    ' 4 = Report servo 0 position
    ' 5 = Report servo 1 position
    ' 6 = Report servo 2 position
    ' 7 = N/A
    ' 8 = Report ALL servos
    ' response will be %BBBB1XYZ where XYZ may be 1 or 0
    ' depending on whether that servo has reached its end
    ' point (1) or not (0)- a quick way to read all servos.
    ' Note that bits B depend on whether the servo is switched ON
    ' (1) or switched OFF (0) - mask them if you don't know
    ' by ANDing with %00001111
    ' 9 = N/A
    ' 10 = N/A
    ' 11 = N/A
    ' 12 = Switch OFF servo 0
    ' 13 = Switch OFF servo 1
    ' 14 = Switch OFF servo 2
    ' 15 = N/A

    Sorry for the formatting, comments nicked directly from my code tongue.gif

    and xxxx is the position of the servo (127 is centred)

    I got it from a UK company called Milford Instruments and it did cost almost $20 US (£10 UK). I don't know where they get them from, but i'll examine the IC tonight for serial numbers, manufacturers etc. and give you an update later.

    Meanwhile, here is the link: www.milinst.com/animatronics/animsside.htm

    It is the 4th item down, no image, and they call it the Micro Serial Servo Driver Chip

    This IC can control upto 3 servo's, comes with sample code for the BS2 series, and it also contains speed control for the servo's (yes it is possible!) as well as range select between 90 and 180 degrees.

    Expensive yes, worth it? Definately in my opinion.

    It might sound complex, but it is extremely easy to work with thanks to their sample code. wink.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Flying is simple. You just throw yourself at the ground and miss.
  • sushiandmorihikosushiandmorihiko Posts: 40
    edited 2007-10-04 17:06
    geee--thanks for the replies, guys

    to mike green advice,it seems like a good idea to increment the degrees by a touch of a button , i might use potentiometer-perhaps it ll work too but little more complex.you guys have any experience in controlling servos using potentiometer?

    to bruce bates,--i do notice some of the servos feel like turning less than 180,nevertheless i m still in the mood for servos-hihihi. other reason of course bcos stepper motor is more complex--too bad parrallax doesnt have course kit for stepper motor.

    to morrollan--hhhmm--dats some cool kits u got there, i do consider some servo driver too from parallax ,lynmotion and servocity but for now i really wanna brush up my programming skill--doing everything by BASIC codes.

    one more thing guys---right away after i reach my home after a 2 hours flight, i finally figured out the speed to control standard servo---hahahha--finally(not bad for a noob hihi)

    DO

    boom VAR Word

    FOR boom = 200 TO 1200 STEP 25
    PULSOUT 2, boom
    PAUSE 10
    NEXT

    PAUSE 500

    FOR boom = 1200 TO 200 STEP 25
    PULSOUT 2, boom
    PAUSE 10
    NEXT

    PAUSE 500

    LOOP

    man--i bet for experts like you guys already know(piece of cake for you guys hihihi ) however,i just post it here as for people who encounter the same problem like i did.
    the "pause 10" that determines the speed(the larger the slower it moves)
    the "pause 500" is the delay until it is done reaching one end
    the rest is explained by mike green on the above post

    thanks--hope this helps
  • MorrolanMorrolan Posts: 98
    edited 2007-10-05 09:55
    I take it that your code makes your servo sweep back and forth?

    Have you tried gently increasing the pulse length to see how far your servo will go? I use Futaba servos and I can get about 195 degrees before they complain, but I use code to limit them. If you push the servo too far you will hear audio feedback from the servo, sounds like grinding gears but if you take it slowly and in small steps you won't damage it.

    I add constants for MinPosition and MaxPosition for my servos - either as Words (i.e. PULSOUT freqs) or using my IC, I use bytes as it expects positions between 0 - 255.

    Obviously, the benefit of using constants is that it doesn't take up any RAM space!

    DO
    
    MinPosition CON 210
    MaxPosition CON 1190 
    
    boom VAR Word
    
    
    FOR boom = MinPosition TO MaxPosition STEP 25
    PULSOUT 2, boom
    PAUSE 10
    NEXT
    
    PAUSE 500
    
    FOR boom = MaxPosition TO MinPosition STEP 25
    PULSOUT 2, boom
    PAUSE 10
    NEXT
    
    PAUSE 500
    
    LOOP
    



    I find it a bit safer and it makes me feel better by limiting range like that - I've made mistakes before now and heard horrific noises come from a servo... sad.gif

    I have a circuit at home which uses a potentiometer to control a servo - came pre-built but it's simple so I'll see if I can build a schematic from it - it allows you to manually rotate the servo using a potentiometer, or you can put it into "automatic" mode where it will sweep backwards and forwards, just like your code...

    I'll see what I can do! smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Flying is simple. You just throw yourself at the ground and miss.
  • sushiandmorihikosushiandmorihiko Posts: 40
    edited 2007-10-05 14:47
    thanks morollan

    its amazing to see that you are roughly did i wanna do---like you see in my new thread---i did successfully control a servo by potentiometer however i want it to have 2 mode: one is manual whereby you control with the potentiometer(yesh i can do that now), second i wanna it to be controlled automaticlly by a program--lets say connected to the infra red sensor.

    i really wanna do this--pls suggest the best way---i thought about having a switch so that i can shift from 1 mode to the other.what do you think? eg, IF PUSHBUTTON1=0 THEN BLABLABLA
  • sushiandmorihikosushiandmorihiko Posts: 40
    edited 2007-10-05 14:50
    oya--i did encounter the same problem as you did last time---when the servo reach the end of its rotation---it feels like the motor still push for more--i scared it might ruin the servo---i ll try your method for better---thanks man---
  • MorrolanMorrolan Posts: 98
    edited 2007-10-05 15:30
    No problem - if it feels like it is pushing for more, narrow the frequency you are pulsing at using any method, mine or yours.

    You're right - my circuit uses a standard switch, but jumper pins would work well if it wasn't something you wanted to change often. You could have a jumper pin +5V plus current limiting resistor (22R recommended) - into an input on your stamp. Code would simply be:

    IF IN0 = 1 THEN
    do stuff
    ELSEIF IN0 = 0 THEN
    do other stuff
    ENDIF
    



    With 0 being off, 1 being on in binary. Put this is some kind of loop and you're away..

    The pullup and pulldown resistor in the circuit below might not be needed, i'm not the best person to ask for that (slight grey area for me!) but you can see by the schematic that you can have a jumper or a switch which switches between 0v and 5v - reading this input through a current-limiting resistor into a pin will enable you to use code to only run automatic mode when the pin receives 5v etc.

    attachment.php?attachmentid=49738

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Flying is simple. You just throw yourself at the ground and miss.

    "I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image."
    Stephen Hawking

    Post Edited (Morrolan) : 10/5/2007 3:58:37 PM GMT
    665 x 484 - 29K
  • sushiandmorihikosushiandmorihiko Posts: 40
    edited 2007-10-05 16:17
    i got your idea man---i should try them later--many thanks for your support--i hope i could make this project a reality and i ll show it to show how it looks like if everything put in place.
    anyway--what kind of project did you make to have this 2 servo modes?
  • MorrolanMorrolan Posts: 98
    edited 2007-10-08 08:26
    The first project was simply a demo for something much bigger - I built a small laser turret using 2 servo's and a laser pen to entertain my cat.

    The second project won't use servo's but stepper motors, as I'm building a wireless, remotely controlled Paintball gun turret. tongue.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Flying is simple. You just throw yourself at the ground and miss.

    "I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image."
    Stephen Hawking
  • Mike WaltzMike Waltz Posts: 2
    edited 2007-10-16 15:54
    Mike Green said...
    The Robotics tutorial (download from: www.parallax.com/detail.asp?product_id=28154)
    I went to that link but I don't see the tutorial.· Can you help me find it?
Sign In or Register to comment.