Shop OBEX P1 Docs P2 Docs Learn Events
Servo/Programming help please — Parallax Forums

Servo/Programming help please

ur5pointos2slour5pointos2slo Posts: 19
edited 2008-12-06 20:38 in BASIC Stamp
I have written a code and I am having problems with the servo. I have written other posts regarding what I am trying to get the bot to do, I have finally got everything to work the way I want. Now I am having problems getting the servo to turn correctly. It is a standard servo(180 degree movement). I am starting on a line with qti sensors.I also have an IR sensor hooked to the bot. So the bot follows the line until it sees the wall or whatever it may be. Then the servo will rotate the full 180 degrees(WHICH I CANNOT GET TO WORK), Rotate -180 degrees, then turn around and continue following the line until it sees something. Then on and on from there in the same way. So my problem is under the Dump_balls subroutine I cannot get the dumpservo to actually turn 180 degrees it seems like it makes a simple pulse then pauses makes a simple pulse(split second) then turns around follows line and on and on. How can I make the servo turn for the whole 180 degree it is allowed. I have tried all different numbers and nothing seems to help it. I have attached a copy of the code any help would be appreciated. Thank you

Comments

  • FranklinFranklin Posts: 4,747
    edited 2008-12-05 22:17
    Try pause 20 instead of 100.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • ur5pointos2slour5pointos2slo Posts: 19
    edited 2008-12-05 22:21
    Franklin said...
    Try pause 20 instead of 100.

    I just tried to pause 20..I had tried pause 10 pause 20 all different pauses but that doesnt seem to have anything to do with how long the servo itself will turn..
  • MSDTechMSDTech Posts: 342
    edited 2008-12-05 23:03
    What you have written will hold the servo in a single postion while in the dump_balls subroutine is running and the servo will probably be shut off the rest of the time.
    The standard servo will move from one extreme to another as the pulse width changes from 1ms to 2ms. You would also need to refresh it every 20 ms to hold it in position. You should add a line during your main loop to hold it in the running position:
    PULSOUT Dumpservo, 500 'Assuming that the extreme corresponding to 1ms is the running position.

    Then to have it rotate 180 degrees, increse its pulse to 2 ms

    FOR counter = 1 TO 100
    PULSOUT Dumpservo, 500 + ( 5 * counter)
    PAUSE 20
    NEXT
  • ur5pointos2slour5pointos2slo Posts: 19
    edited 2008-12-05 23:16
    MSDTech said...
    What you have written will hold the servo in a single postion while in the dump_balls subroutine is running and the servo will probably be shut off the rest of the time.
    The standard servo will move from one extreme to another as the pulse width changes from 1ms to 2ms. You would also need to refresh it every 20 ms to hold it in position. You should add a line during your main loop to hold it in the running position:
    PULSOUT Dumpservo, 500 'Assuming that the extreme corresponding to 1ms is the running position.

    Then to have it rotate 180 degrees, increse its pulse to 2 ms

    FOR counter = 1 TO 100
    PULSOUT Dumpservo, 500 + ( 5 * counter)
    PAUSE 20
    NEXT
    ····· Thanks for a·quick reply..what exactly do you mean by running position? How would I write a code to make it stay in this position? Would it need to be under GOSUB Dump_Balls in the main loop or where would I need to put it in the loop?
  • MSDTechMSDTech Posts: 342
    edited 2008-12-06 14:23
    By running position, what direction do you want the servo to point while it's following the line? You need something in or called by your main loop to keep the standard servo in position.
  • ur5pointos2slour5pointos2slo Posts: 19
    edited 2008-12-06 18:03
    MSDTech said...
    By running position, what direction do you want the servo to point while it's following the line? You need something in or called by your main loop to keep the standard servo in position.
    ·Ok basically I have a bot that is putting ping pong balls into cups on opposite ends of a board...the dumpservo is being used to lift the arm I have built..so the bot is going to start on a line, follow that line until the infrared sensors spots the wall. The ping pong balls will be fed one at a time into the tube on the arm. So when the sensors spot the wall the bot will stop..the arm will go up with the ball inside and dump it off into the cup, then the arm has to go back down to pick up the next ball, then turn around follow the line and repeat that process 6 times. So I know that the servo has to be all the way to the right the way I have it set up, then turn the full 180 to the left(which is actually lifting the arm), then turn back to the right(which will put it in down position. I hope this is making sense. So if by chance you can understand what I am saying tongue.gif· which position would you think that would be? I have attached a diagram that will maybe show this a little more clear.

    Post Edited (ur5pointos2slo) : 12/6/2008 6:32:26 PM GMT
    565 x 608 - 13K
  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-06 18:30
    You're going to have to determine the correct position and the pulse width to achieve it by trial and error.

    Write a 4 line program to position the servo to some position and just modify, download, and run the program repeatedly until you've found all the servo positions of interest to you and the pulse width to go there. With a BS2, the extremes are somewhere on the order of 1.0ms (PULSOUT <pin>,500) to 2.0ms (PULSOUT <pin>,1000). Your test program would just be
    DO
       PULSOUT <pin>,<pulseWidth>
       PAUSE 20
    LOOP
    


    where <pin> is the pin number being used and <pulseWidth> is the pulse width in units of 2us (1.5ms = 750)
  • ur5pointos2slour5pointos2slo Posts: 19
    edited 2008-12-06 18:45
    Mike Green said...
    You're going to have to determine the correct position and the pulse width to achieve it by trial and error.

    Write a 4 line program to position the servo to some position and just modify, download, and run the program repeatedly until you've found all the servo positions of interest to you and the pulse width to go there. With a BS2, the extremes are somewhere on the order of 1.0ms (PULSOUT <pin>,500) to 2.0ms (PULSOUT <pin>,1000). Your test program would just be
    DO
       PULSOUT <pin>,<pulseWidth>
       PAUSE 20
    LOOP
    


    where <pin> is the pin number being used and <pulseWidth> is the pulse width in units of 2us (1.5ms = 750)
    ok that makes sense, I have done a lot of trial and error. I just tried this and it made the servo turn the way I wanted to turn the full 180 degrees. But now I need a pulsewidth that will make it go the opposite way I think..here is what I wrote

    Dump_Balls:
    FOR counter = 1 TO 100
    · PULSOUT Dumpservo,1000
    ·· PAUSE 20
    NEXT
    FOR counter = 1 TO 100
    · PULSOUT Dumpservo,(Need this value to spin the servo in the opposite direction?)
    ·· PAUSE 20
    NEXT
    GOSUB Turn_around
    RETURN

    Post Edited (ur5pointos2slo) : 12/6/2008 7:17:58 PM GMT
  • SRLMSRLM Posts: 5,045
    edited 2008-12-06 19:53
    For the BS2, as servo PULSOUT is between 500 and 1000, with 750 being the center. You've got the 1000, so now you need a 500.
  • ur5pointos2slour5pointos2slo Posts: 19
    edited 2008-12-06 19:59
    SRLM said...
    For the BS2, as servo PULSOUT is between 500 and 1000, with 750 being the center. You've got the 1000, so now you need a 500.
    Thanks. I have 500 actually programmed right now but it will not spin the servo fully back to the original position. It will make it almost there and stop. I have tried different counter numbers, pauses, tried to read the boe bot book. I cannot seem to find out why it stops short..
  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-06 20:03
    Servos are not precise devices. Some of them will accept a control pulse as short as 0.5ms or as long as 2.5ms. You can try a PULSOUT value as low as 250 or as high as 1250. Keep in mind that it's not good for the servo to ram up against the mechanical stop inside, so try values smaller than 500 or larger than 1000 in small increments.
  • ur5pointos2slour5pointos2slo Posts: 19
    edited 2008-12-06 20:12
    Mike Green said...
    Servos are not precise devices. Some of them will accept a control pulse as short as 0.5ms or as long as 2.5ms. You can try a PULSOUT value as low as 250 or as high as 1250. Keep in mind that it's not good for the servo to ram up against the mechanical stop inside, so try values smaller than 500 or larger than 1000 in small increments.
    I had been trying 450 400 350 and all of those seemed to make it stop even shorter..but when I put it down to 250 it did exactly what I needed it to do. It is off by just a hair which is close enough to work with what I have built. Thanks for all of your help.
  • SRLMSRLM Posts: 5,045
    edited 2008-12-06 20:38
    As a practical example, one one of my projects the servo left was 950, center was 1325, and right was 1600 uS. So, it helps to have constants declared at the beginning of your program, so that you don't have to worry about the exact values. Just say something like PULSOUT Servo, LEFT/2
Sign In or Register to comment.