Servo Ramping in DO-LOOP Statement
TheTech69
Posts: 51
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.
The prop is by Widgetwerks from the September 2014 Nuts and Volts Halloween issue with the article written by Kevin Goodwin.
Comments
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.
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)
http://www.jameco.com/Jameco/workshop/JamecoBuilds/peek-a-boo-ghost.html
@TheTech69: How did you make out? Don't leave us hangin'!
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.
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.
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.