Shop OBEX P1 Docs P2 Docs Learn Events
Servo controller HELP!!!! — Parallax Forums

Servo controller HELP!!!!

mphillipsmphillips Posts: 12
edited 2011-04-21 20:38 in BASIC Stamp
I am currently making a robotic arm for digital class with a bs2 and 4 servos. I got the basic code from "experiment #25 hobby servo control" The only problem is that the sweep of the servo is about 22.5 degrees if that. How can i modify to get at least 90 degrees of sweep. What is the deciding factor in the code that says how much distance the servo covers.

Heres the code I am using:
4 servo control.bs2

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-04-21 05:41
    PULSOUT servo1, (750 + sPos)
    PULSOUT servo2, (750 + sPos)

    So the pulse will always be at least 1500usec (750 * 2us)
    Change the 750s to 500, or 600. What results?
  • mphillipsmphillips Posts: 12
    edited 2011-04-21 14:57
    i tried 600 and 500 with no results. There has to be an easy explination for this its just a servo for god sake!
  • Mike GreenMike Green Posts: 23,101
    edited 2011-04-21 15:18
    You are unlikely to get this to work. The Stamp can only do one thing at a time. When the PULSOUT is executed, the Stamp stops while the pulse is produced. The proper range of pulse widths is 0.5ms to 2.5ms. Strictly speaking, the pulse widths should be 1.0ms to 2.0ms, but some servos accept a wider range. With 4 servos, the total time spent doing PULSOUTs can be up to 4*2.5ms = 10ms. Servos require a control pulse roughly every 20ms or they shut down until the next control pulse comes along. If you add a PAUSE 10, that's already 20ms worst case. That doesn't include the time needed for all the RCTIME statements let along the other statements that may take up to several hundred microseconds each to execute.

    Try getting this to work with one servo and make all the other RCTIME / PULSOUT stuff into comments, then add one servo at a time to see when it stops working. You'll probably find that two servos will work, but not three. If you switch to a faster Stamp like the BS2px, you may find that you can use three or four servos, but you will have to adjust the calculations because the time unit for that is not 2us. I think it's 0.8us, but you'll have to check the Stamp Manual or help files for the exact values.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-04-21 15:55
    Excuse me, for god sake, but, given PULSOUT servo, (750 + sPos),
    (750 + sPos) determines servo position for god sake. Inasmuch, for god sake, the pulse out will always be 1500 (which is 750 * 2) + whatever sPos is, for god sake. 1500us is midposition (or thereabout), for god sake. What, for god sake, is the argument?
  • ZootZoot Posts: 2,227
    edited 2011-04-21 16:54
    You have two issues: 1) what pulse value you need (in microseconds) to get a given servo to a given position. 2) can you fit all the stuff in that you need between all the pulse outs to 4 servos.

    Re: 1 -- While not strictly true, a decent generalization is that 1000us (1ms) is about 45 degrees off-center for a "normal" servo. 2000us is 45 degrees off-center the other way. 1500us is "center". For servos with something like a 180 degree range, a good starting place is 500us at one end and 2500us at the other. If you think of it in microseconds, it's easier, and then the flavor of Stamp (i.e. what is the "unit" for a pulsout) is trivial, e.g.
    svoVal VAR Word ' as microseconds !!!
    
    Start:
    
    svoVal = 1500
    
    Main:
    
    FOR svoVal = 1500 TO 2500 STEP 10 ' in 20us steps
      PULSOUT servo1, svoVal/2 ' if BS2, puslout is in 2us units, so divide by two
      PAUSE 20-(svoVal/1000) ' pause 20ms, backing out whatever length of pulse you just sent, rounded down
    NEXT
    
    FOR svoVal = 2500 TO 500 STEP -10 ' in 20us steps
      PULSOUT servo1, svoVal/2 ' if BS2, puslout is in 2us units, so divide by two
      PAUSE 20-(svoVal/1000) ' pause 20ms, backing out whatever length of pulse you just sent, rounded down
    NEXT
    
    FOR svoVal = 500 TO 1500 STEP 10 ' in 20us steps
      PULSOUT servo1, svoVal/2 ' if BS2, puslout is in 2us units, so divide by two
      PAUSE 20-(svoVal/1000) ' pause 20ms, backing out whatever length of pulse you just sent, rounded down
    NEXT
    
    GOTO Main
    

    Or, enter a value in us and put the servo there:
    svoVal VAR Word
    
    DEBUG CLS, "Enter servo pulse value in MICROSECONDS:", CR
    DEBUGIN DEC svoVal
    
    DEBUG CR, "Doing it.... ", DEC5 svoVal, CR
    
    DO
      PULSOUT servo1, svoVal/2
      PAUSE 20-(svoVal/1000)
    LOOP
    
    

    Re: 2 -- what Mike Green said :)
  • mphillipsmphillips Posts: 12
    edited 2011-04-21 20:18
    I tried the two codes and they both have undefined symbols. I am new to the programming lingo so its probly just a little mistake u made.

    Mike I have made a code with just one servo like the one in experiment 25. I have the same result as with 4 servo code. I have to move one servo at a time though. I cannot control two at the same time, i realize that two movements simultaneously wont happen

    I really only need to control 3 servos to get my project done.I just need to get a wider sweep with one. then i can figure out how to make them all work.

    Let me try to ingest this info and maybe i will realize what u guys are trying to tell me. Im a little slow sometimes.

    Mike thanks again for the in depth reply. U helped me a few weeks ago to figure out how to get multiple servos moving. Now i am just trying to get a wider range of movement.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-04-21 20:38
    You really need to remove the PAUSE 10 statements from your program. If you're just testing one or two servos, put back a single PAUSE 10 just before the GOTO at the end. For debugging you should also display the values of rcRt, rcLf, and sPos and make sure they're what you expect. The DEBUG statement will introduce enough delay so even the single servo movement probably won't work.
Sign In or Register to comment.