Shop OBEX P1 Docs P2 Docs Learn Events
Servo Ramping in DO-LOOP Statement — Parallax Forums

Servo Ramping in DO-LOOP Statement

TheTech69TheTech69 Posts: 51
edited 2015-10-01 00:33 in BASIC Stamp
I am trying to get 2 Standard Servo motors to slowly move from one position to another. When the code runs outside of the DO-LOOP statement, it works as expected. The servos ramp down slowly to a stop and remain motionless. However, when the FOR - NEXT statement of the ramping is placed in the DO-LOOP the servos keep repeating the starting and ending position numbers. The servos DO NOT remain in the final stopped motionless position. The Goal is to get the servos to ramp slowly down, stop, and remain in the final position until a signal is detected from the PIR Wide Angle Sensor again.

The prop is by Widgetwerks from the September 2014 Nuts and Volts Halloween issue with the article written by Kevin Goodwin.

Comments

  • ercoerco Posts: 20,257
    edited 2015-10-01 02:51
    First, try a pause 5000 before endif. That will stop everything, including servo pulses, but the arms should stay put unless they are heavy. If they move, we'll have to add a loop to hold them there.

    Overall, you need to figure out how long you want the cycle to run for. I think your sensor is retriggering from the same person, so you need to add a long enough delay for that person to scram before the sensor resets.
  • ercoerco Posts: 20,257
    Or try modified code attached
  • Remember that servos need to be updated every 20ms -- if you don't do that, they can move when you don't want them to. When I explained this to the animation crew at Legoland (who have used BS2's in many projects) one said, "Oh, so that's why the X-Wing's wings started to sag...." That response made me laugh. They now use the Propeller so they don't have to worry about refreshing the servos (the servo driver does that), but with the BS2 we have to take care of everything ourselves.

    I've attached version of the program (that will require adjustments to be sure) that handles delays and keeps the servos refreshed so they don't move. You'll need to verify the covered eye positions and the +/- for the animation offset. I also used just one position (covered) and offset from or to it. If I'm correct the program is supposed to do this:

    1. Wait for PIR
    2. Uncover eyes
    3. Blink eyes
    4. Cover eyes
    5. Back to 1

    Right? In my mind this suggests there should be a covered position for the eyes and you either move away from or to that.

    Finally... PIRs can be very twitchy, so it's a good idea to debounce them. My code debounces the PIR input for 100ms to ensure that it really is a valid signal.

    Finally (part 2)... I'm a nut about formatting, so you'll see that I've reformatted per my rules (you can find them in StampWorks and the PBASIC Help File)

  • ercoerco Posts: 20,257
    Ha, I thought this might be the OP's writeup, until I saw Ardu&@# in the BOM!

    http://www.jameco.com/Jameco/workshop/JamecoBuilds/peek-a-boo-ghost.html

    @TheTech69: How did you make out? Don't leave us hangin'!
  • erco,

    Many thanks to JonnyMac for the code correction and format standard! The code worked great once I got the servo position numbers straightened out. The original prototype works great...BUT....(there's always a "but") my Mom wanted one for her other Halloween decorations around the house. The standard servo motors shake and jitter when the poster board arms are attached to them. I thought it might be the second BOE - USB I am using; nope. I used my original BOE with Rev C BS2 and got the same issue. No idea why the servos with the arms do that.

    But the programming.....WOW... I am a retired Marine that dealt with the setup, operation and repair of radio communications. We received some pretty good electronics training and I bought quite a few books about electronics. I really liked it when I learned the theory about the circuits. What I would love here is the theory, the "why" the code is written the way it is to cause the circuit to do what it does. Like the Timer Object. I read the article in the October Nuts and Volts about the timer object for the propeller but still am lost in the sauce.
  • ok...I think the problem is the weight of the poster board cut out in the shape of an arm. The servo motors by themselves do not have the shakiness and jitter. Not sure how to determine the weight at the point where the hands are with the connection point of the servos 5 inches from the "tip of elbow".
  • If you can power the BoE from 6 or 7 volts and set the servo headers to use the raw input voltage that will help. You're right, it's the mechanical load on the servos.
  • I just finished setting the servo headers to use the raw voltage of 6 volts from the voltage selectable wall wart. The arms still shake. In addition, the arms also shake when they move to uncover the eyes and when they move to cover the eyes. I'll have to re-read the data sheet for the Parallax Standard Servo and try to figure out what specification pertains to the mechanical load issue. Then to determine which brand of servo to purchase.

    Bummer...I really like Parallax. I've seen advertisements in Nuts and Volts for Hi-Tec brand of servos. I'll pull their data sheets as well.
  • ercoerco Posts: 20,257
    See if you can add a rubber band somewhere to counterbalance the weight of the arm, even if the servo has to push the arm down at the bottom when the band is fully stretched.
  • erco,

    Thank you for the idea. So far I lucked out by having the arms come to rest against each other therefore eliminating the shaking of them. I've been contemplating Mechanical Engineering course of study next to aid in the better design of electronic projects.
  • ercoerco Posts: 20,257
    Or just get bigger servos. Vigor's quarter scale VS-11 is big and cheap at Hobby King.
Sign In or Register to comment.