Go Down

Topic: Motors acting crazy (Read 294 times) previous topic - next topic

nking

Jun 14, 2018, 08:36 am Last Edit: Jun 14, 2018, 08:38 am by nking
Hello to everyone!

First time poster, but I've been playing with Arduino and electronics for a little while now.

I'm creating a 'pet food catapult', which throws dry pet food to spread it out and delay my dog simply eating all of her food within 1 minute. :)

I'll attach a fritz of my electronics, plus another actual photo of the working prototype. They are different in their power sources. In the living version I'm powering it by a DC power source putting out 9v 1A.

The idea is straight forward. One 360 degree servo (Rotator) pulls down the catapult arm via fishing line, until it touches the Limit Switch (using a 10k resistor). Another servo (Trigger) then locks it down. The Rotator winds back to unwind the fishing line.
The third servo (Delivery) turns a pipe and delivers a portion into the catapult. The Trigger releases the catapult and lets the food fling across the backyard.

However, what is driving me nuts is that it isn't consistent. When it follows my code, it works beautifully.
But, then, for no apparent reason one of the motors moves in a jittery back/forth motion. Especially the Delivery servo. Sometimes the Delivery servo or the Trigger will go back to old positions from what seems like old code, or reverse the positions I've told them to be in.

E.g. Trigger has two integers in the code TRH (trigger hold) TRR (trigger release). One is at 90, other at 160. When it's working properly, it goes to those two positions. Then for no apparent reason it will switch the positions and be at the wrong position at the wrong time.

I've read that some servos, especially the cheaper ones can do weird things and be generally unreliable. Is that is what is happening?
I've also had problems in the past by just using the breadboard. Where as soldering everything into a proper perf board (PCB) has solved things. Is that what is happening?

I've replaced the switch and the Arduino, to no effect.

I've attached the Arduino code. Excuse the messiness, it's gone through various iterations and I haven't had time to clean it up and add proper notations.

The more I write, the more I realise that I'm going to need videos as well.
I've got two videos, the first is where it works, the second is where it goes nuts.
However, this sites limitation is a max of 1Mb per file. Which is a ridiculously tiny video file.
So, unfortunately, I've had to upload them to YouTube, linked below:

Working normally:  https://youtu.be/kZKmve8SEic
Going nuts:            https://youtu.be/aJKz1rbsVJU

It's all driving me a bit nuts. If anyone can assist I'd be very grateful!


PaulS

Code: [Select]
int FDR = 60;       // variable to store the Trigger servo position - Release position
int FDH = 0;      // variable to store the Trigger servo position - Hold position
int TRR = 90;       // variable to store the Trigger servo position - Release position
int TRH = 160;      // variable to store the Trigger servo position - Hold position

Do those comments add any value? Do they when the same comment applies to two different variables?

Code: [Select]
Servo fooddelivery; //  create servo object to control the food delivery arm
Servo trigger2;     // create servo object to control the trigger
Servo rotater1;     // create servo object to control the rotator

Why trigger2 and rotater1? How many trigger servos do you have? How many rotater servos?

Code: [Select]
int switch_state = 0;
Why does this need to be global?

The commented out code is NOT part of the problem, and did NOT need to be posted here.

Your program really could benefit from some organization into functions.

If you have multiple servos moving at once (I can't tell. There is so much chaff in your file, obscuring the wheat), then your power supply isn't up to snuff. Even with only one servo moving, it may not be. Typically, you plan on 1 A per servo, at the servo's voltage (which likely is NOT 9V).
The art of getting good answers lies in asking good questions.

nking

Thanks for responding PaulS.

Please keep in mind what I said in the initial post about the code need attention and that I haven't had time.
BUT, to answer your questions.

#1 - the comments were from a copy/paste and haven't been updated. But I did mention the servo names in my post, so they should be clear. Regardless of whether they're named with a number or not.

#2 - "int switch_state = 0;  Why does this need to be global?" It doesn't, but as there's only one...

Ignoring your further comments on my coding skill and lack of clarity. As I've already explained.

There is only one servo running at one time.

Thanks for your suggestion, I'll double check what voltage and amps are required for each of the servos.

Delta_G

Code: [Select]
int FDR = 60;       // variable to store the Trigger servo position - Release position

The best comments ARE the code:

Code: [Select]
int triggerReleasePosition = 60;

And now you don't have to go find the comment when you see it later. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

nking

Thanks DeltaG

A great idea to use some descriptive variable names. I'll definitely start doing that instead of the short hand version.

:)

Delta_G

Thanks DeltaG

A great idea to use some descriptive variable names. I'll definitely start doing that instead of the short hand version.

:)
When you do it right, the code starts to read like prose:


Code: [Select]

if(dog.isHungry()){
     feedDog(dog);
}
if(cat.isWantingOut()){
     openDoor();
     waitFor(cat);
     closeDoor();
}

|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

Go Up