Go Down

Topic: Stepper motor as a "servo" (Read 608 times) previous topic - next topic

michael96048

I am trying to set up a stepper motor control on my Arduino Mega.  I need to be about to control the position on the motor with a joystick. I'm not concerned about the speed because that can easily be written into the program.  My biggest concern is returning to home when the joystick is released (like a servo).  I would just use a servo but I have a stepper motor that does 17 ft-lbs and good luck finding a servo that does that.

UKHeliBob

Ideally you need position feedback from the stepper motor but might be OK if you just count steps.  If you have moved, say, 100 steps in one direction from 'home' and now wish to return to it then 100 steps the opposite way should do it as long as there are no missed steps and no slippage.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Robin2

My biggest concern is returning to home when the joystick is released (like a servo).
I don't know whether you want it to return to home or NOT to return to home. Please clarify.

With a stepper motor you will need a limit switch so that the Arduino can establish the HOME or ZERO position at startup. In other words the motor needs to move step by step until it triggers the switch and then the Arduino knows where it is.

You also need a suitable stepper driver board to sit between the Arduino and the motor. With a servo all the drive and positioning system is inside the case.

...R
Stepper Motor Basics
Simple Stepper Code
Two or three hours spent thinking and reading documentation solves most programming problems.

michael96048

I need the stepper motor to be in whatever position the joystick is in. IE at full forward, move to X position, and if I ease off the stepper motor would have to follow (exactly like a servo would do it), with an "emergency" return to home input. I'm not sure a rotary encoder would be accurate enough to get it back to within a degree or 2 of center.

I've got a good rotary encoder on the way but I cant find anything online that suggest how to put that in the code. I'm not sure I would trust counting steps because if its off by a step when it returns my hydro-stat pump will not be in the neutral position.

RayLivingston

A stepper motor, properly used, will ALWAYS be where you command it to be, unless you over-load it.  If you over-load it, it will be off-position, as would a servo motor under the same conditions.  So, control it correctly, and don't ask it to do something it is physically incapable of doing, and you'll have no problems.  For homing, you need nothing more than an accurate, repeatable home switch.  This is exactly how it is done on millions of CNC machines using steppers.  And even an inexpensive quadrature encoder is capable or FAR great accuracy than any stepper motor.

Quote
I would just use a servo but I have a stepper motor that does 17 ft-lbs and good luck finding a servo that does that.
That is just flat-out wrong.  Servo motors are capable of FAR greater torque than stepper motors, which is why, on industrial machines, you won't see any very large stepper motors, but you do see loads of very large servo motors.  I sell a product that uses a very small RS-775 DC servo motor (12VDC, 40A, roughly 1.75" OD x 2.5"L), to generate well over 30-ft-lbs of torque.

Regards,
Ray L.

Jiggy-Ninja

With a stepper motor you will need a limit switch so that the Arduino can establish the HOME or ZERO position at startup. In other words the motor needs to move step by step until it triggers the switch and then the Arduino knows where it is.
Not true. You need a method of determining your absolute position. Counting offsets from a limit switch is one method, but not the only method.
Hackaday: https://hackaday.io/MarkRD
Advanced C++ Techniques: https://forum.arduino.cc/index.php?topic=493075.0

michael96048

#6
Aug 17, 2016, 06:19 pm Last Edit: Aug 17, 2016, 06:36 pm by michael96048
I sell a product that uses a very small RS-775 DC servo motor (12VDC, 40A, roughly 1.75" OD x 2.5"L), to generate well over 30-ft-lbs of torque.
I would love a link to the servo motor. That even seems like overkill for what I need, and 40A x2 would be too much draw on my 12v system.  If you sell what I need, this may be a production quantity project that could make you some $.

Robin2

Servo motors are capable of FAR greater torque than stepper motors, which is why, on industrial machines, you won't see any very large stepper motors,
I suspect the OP was referring to hobby servos, not industrial servos.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

daveygmail

That's not true. A servo that's out of position will apply more torque and for whatever time it takes to get to the commanded position. Even if it fails to do that, as soon as it's moved away from whatever stalled or restricted it it will return to its currently commanded position and remain accurate. If a stepper slips, say 100 steps, it will remain off by 100 counts until it is re-homed.

The other thing is that if a servo cannot maintain position it can give an error that there's a fault so that the controller can intervene. If a stepper gets out of position it will just merrily keep going on and moving the load essentially blindly. In a milling machine, a stepper will continue to move and at best ruin the workpiece at worse it'll damage the machine. A server can simply stop and not do any further damage and give the operator the option to take some action to recover. 

A stepper motor, properly used, will ALWAYS be where you command it to be, unless you over-load it.  If you over-load it, it will be off-position, as would a servo motor under the same conditions. 
Regards,
Ray L.

weldsmith



A stepper can be programmed as you wish. There are several ways this can be done. The tricky part is when the power is lost inadvertently. Simply use an encoder with a z channel. you can use this single tick on the encoder to home the stepper. If you program the motor to count in a positive direction on one side of home and then negative on the opposite. You can create a right or left flag that you save to memory. if the power goes out you have saved which side of home you are on and you can center the stepper in the setup loop. If, on power up the left flag is true, move left to find zero and vice versa. if someone manually moves the stepper while the power is off then you may have to write a piece of code that would return the other direction if it does not find home in so many steps. Using an encoder is an easy way to ensure you stay in position. I have included the libraries that I use. Now for the safety Speech. If you are controlling a dangerous piece of equipment, be sure to incorporate a safety signal that would disable the power supply if the arduino loses power.

Dave.



Code: [Select]
#include <AccelStepper.h>
#include <Encoder.h>
David Smith

Go Up