Shop OBEX P1 Docs P2 Docs Learn Events
Novice with question about servo control — Parallax Forums

Novice with question about servo control

ArchiverArchiver Posts: 46,084
edited 2000-05-23 00:21 in General Discussion
I would lie to proportionally control a servo using a variable
potentiometer. I have tried using a 555 timer and a r/c circuit to
collect a variable but I am having a hard time converting the
variable to a useful pulsout number. Can anyone give me a clue? Thanks

Jeff

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2000-05-22 17:03
    DLC, Thank you very much! A very elegant solution that also addresses servo
    response time which is very critical in this application. I do need to
    operate 2 servos and was thinking about using a stamp for each as the servos
    will have to operate simultaneously. My initial thought was to include both
    the checking of the pot and the pulsout to the servo in the same for next
    loop so that there would be a servo correction for every pass through the
    loop. I will give your method this a try this evening.

    Thanks again

    Jeff
  • ArchiverArchiver Posts: 46,084
    edited 2000-05-22 22:57
    Jeff,

    You can use the pot with a capacitor and the rctime function to get
    the pot values. You'll then need to scale it in some fashion to whatever
    resolution you want with the servo control and use pulsout to the servo.

    Remember that the rctime function takes some finite amount of time to
    complete - use the formulae in the Stamp II manual to find that time and
    factor that into the pause for the pulsout command.

    I don't recommend that you do the "usual" servo commands that look like:

    for x = 1 to 15
    pulsout SERVO,value
    pause 20
    next

    You would have just used up over 300ms where the Stamp was doing nothing
    but twidling its thumbs. Rather, use some form of state machine to track
    where you are in the 20ms repeat cycle needed by the servo, for example:

    SERVO con 7
    LOOPS con 20
    v var byte
    s_state var nib

    s_state = 0

    main:
    gosub get_pot
    gosub move_servo
    goto main

    move_servo: 'moves servo to v location
    if s_state = 1 then dservo
    pulsout SERVO,v 'do pulsout
    s_state = 1 'set up for decrement
    goto sdone
    dservo: 'decrement loop
    sloop = sloop -1
    if sloop > 0 then sdone
    s_state = 0 'reset to do pulsout next
    sloop = LOOPS 'reset loop counter
    sdone:
    return

    get_pot:
    ..

    I arbitrarily set LOOPS to 20, timing Stamp instructions is kind of non-
    deterministic on occasion, so to figure out what your loop count needs to be
    I suggest that you set it to some high value where the servo doesn't work well
    and reduce it until it does work. Note, you can add several routines to the
    main loop and get the affect of having a multitasking setup just by reducing
    the number of times the move_servo loop is executed between pulsout commands.
    All the routines in the main loop can be constructed similarly and you will
    interleave actions to get more efficient use of the Stamp. For instance,
    suppose you wanted to sample 2 pots to position 2 servos, you could have the
    get_pot routine sample one pot on one entry through and the other pot on the
    next time through, then you can have the math for scaling done on a third
    loop through that sets the "v" value. Each servo could have its own move_servo
    function as well. This will allow you to get a WHOLE lot more done without
    forcing the Stamp to sit in useless "wait" loops.

    DLC

    > I would lie to proportionally control a servo using a variable
    > potentiometer. I have tried using a 555 timer and a r/c circuit to
    > collect a variable but I am having a hard time converting the
    > variable to a useful pulsout number. Can anyone give me a clue? Thanks
  • ArchiverArchiver Posts: 46,084
    edited 2000-05-22 23:27
    Jeff:
    Maybe I don't understand the big picture, but I built a servo tester that
    controls servo position with a pot. All it uses is a 555 timer controlled
    by the pot. It consists of a 555, 2 resistors, a diode, a cap, and a pot.
    If this is useful to you, I can describe the circuit.

    Ray McArthur

    Original Message
    From: Jeff & Julia <EL-JEFE@P...>
    To: <basicstamps@egroups.com>
    Sent: Monday, May 22, 2000 12:03 PM
    Subject: Re: [noparse][[/noparse]basicstamps] Novice with question about servo control


    > DLC, Thank you very much! A very elegant solution that also addresses
    servo
    > response time which is very critical in this application. I do need to
    > operate 2 servos and was thinking about using a stamp for each as the
    servos
    > will have to operate simultaneously. My initial thought was to include
    both
    > the checking of the pot and the pulsout to the servo in the same for next
    > loop so that there would be a servo correction for every pass through the
    > loop. I will give your method this a try this evening.
    >
    > Thanks again
    >
    > Jeff
  • ArchiverArchiver Posts: 46,084
    edited 2000-05-23 00:21
    Jeff,

    De nada. If you are interested in some examples that may help you design
    such code check out my web page http://www.verinet.com/~dlc/botlinks.htm
    and bonk on the article download under the BoE-Bot picture. Also, the
    Parallax web site has a PDF of this article under their robotics section,
    I think its called experiment 6 or somesuch.

    have fun,
    DLC
    > DLC, Thank you very much! A very elegant solution that also addresses servo
    > response time which is very critical in this application. I do need to
    > operate 2 servos and was thinking about using a stamp for each as the servos
    > will have to operate simultaneously. My initial thought was to include both
    > the checking of the pot and the pulsout to the servo in the same for next
    > loop so that there would be a servo correction for every pass through the
    > loop. I will give your method this a try this evening.
    >
    > Thanks again
    >
    > Jeff
    >
    >
    >
    >
Sign In or Register to comment.