I'm a noob so I want to thank all of you for the help I'm about to receive.
I'm trying to create a clamping device using a toggle clamp and a servo. My problem is that I'm clamping different thicknesses of material and therefore can't tell the servo what angle I want it to stop at. I have to sense the thickness and request an in-motion stop, using a micro switch, but I'm at a loss to figure out the code. More than likely because I don't understand how servos work yet. Or the code to control it.
Oh... by the way, I've spent close to 5 hours youtubing and surfing this and other forums for a solution.
Thanks so much for the fast response. I really want to keep this simple. I'm not worried about the force being applied. I just want to stop the servo at a point where enough force is applied to lock the material down. I'm not even sure that a servo is a good device for this application. I thought about a linear actuator but they are HUGE. Take up way too much space. And still I need some ideas on coding a hard stop on feed back from a micro switch.
Start with the servo in the fully open clamp position, say at angle 0. Command the servo to go to an angle of 180 using small steps by means of a for loop as in the Servo Sweep example. If at any time the stop button becomes pressed then exit the for loop and the servo will remain at that position
Have you thought about how you are going to return to the servo to the start position
What advantage does using a servo have over using a normal clamp of some kind ? I don't know what sort of servo you have in mind but you need to provide power to it from an external source and not the Arduino 5V pin
Thanks so much for your response. I will check out the tutorials again but I only see one, so far, that talks about the servo and how the code works but it's limited. Not well explained either.
I'm a coding noob. I'll check out the tutorial again. Maybe I missed something.
Yup, I get the idea of a for loop but how to bring it to a stop is the question I have. How to return it to zero is the next challenge. I'm working on stopping it right now.
So if I have an input from a switch, how do I code an exit from the for loop?
Oh yeah... I do intend on getting a servo driver when I need to apply power. Right now it's just watching the motion of the servo until I have the action right.
if you are in the planing stages on the mechanics, there are a lot of options.
a servo will not be delivering much force so it might be perfect, or it might be underpowered.
do you have a force in mind ? as much as a clothespin ?
as much as a 6 inch hand held spring clamp ?
holding down a 100 pound part ?
I highly expect that knowing distance and getting to it will not work.
the amount of pressure exerted with a movement of the thickness of a human hair might be hundreds of pounds.
higher motor amps might be a feedback.
a spring arm on the servo, etc.
Since you found no answers, I am guessing is because it is not the correct path. I was in machining for 20 years and would never consider a distance as a suitable clamping method.
So the toggle clamp has a rubber bumper on it that compresses over the material, I've found that I get equal clamping force when the rubber compresses about 3/64". That's all I need to keep it consistent. So if I set a micro switch to actuate and that amount of compression I have a secure material. I'm pretty sure I'll need to move to linear actuator to make this happen. Might make my own.
Yup, that's the exact servo I'm using for experimentation of the code. I'm just borrowing other people code so far so I have nothing original as yet. And not sure on how to exit a for loop.
IF that works, then add a pin that goes through the center of the rubber, so when the rubber is compressed, the pin is also pressed and it will press a microswitch and tell you to stop pressing. The pin will need a small spring to return it to it's original position.
Paul
That said, using a "for" loop to do this is poor coding practice.
Just saying ...
The concept of "state machine" coding is that in the main "loop()", on each pass through the loop you make decisions based on such things as a variable which defines the current position of the servo and whether the switch is actuated, and those decisions determine whether you change the current position of the servo or not, and how much you change it. Unless you change it, there is no need to alter the value of the servo command.
Doing this in the loop() allows you to add other functions if you need to which may or may not be even related to the servo operation.