WebbotLib AVR library
WebbotLib It just does it
C++documentationCdocumentation

Stepper

Support for various stepper motor controllers.
So what's a stepper motor?
Whilst a DC motor continues to rotate whilst any voltage is applied; a stepper motor contains electromagnets which are used to kick the motor around in individual 'steps' - or 'ticks'. To perform a 'step' then the electromagnets need to be energised in a particular sequence. It is only this 'change' that performs a 'step' - the continued application of the same current will produce no further steps. So to keep a stepper motor rotating then the electromagnets must continue to be energised in a given sequence.
All stepper motors will state the number of steps per revolution. ie a motor with 200 steps per revolution will mean that each step will turn through 360 / 200 ie 1.8 per step.
Since a 'step' only happens when we ask it to happen; and we know the angle each step represents then these appear to be ideal for giving accurate and precise turning angles and distance measurement.
Compare with a DC motor. Since we don't really know precisely the exact RPM of our DC motor at any given time then we use an encoder to tell us that information - and it is used in a closed loop feedback system to adjust the voltage, or PWM duty cycle, to control the DC motor more precisely.
On the other hand - a stepper motor is open loop. ie we don't need the encoder to say how fast it is turning because it turns through a fixed angle for every 'step' command we send it. - so if we added an encoder then it would only confirm what we already knew.
Well that's the elementary theory - but, as usual, the real world sometimes gets in the way. For example: let's take a small stepper motor out of a floppy disk drive and attach it to the drive shaft of our 30 ton tank. Will it be guaranteed to move the tank track for every step => "No the tank is too heavy ie the motor doesn't have enough torque". Conversely lets take a great big heavy industrial stepper motor and give it step commands every millionth of a second. Will it rotate a million times a second => "No the motor can't move that fast - as it has a maximum RPM".;
We have learnt some examples of how a stepper motor can go wrong - but if the motor is running inside its limits of torque and RPM then it can provide a cheaper alternative to a DC motor with an encoder. Of course there is nothing to stop you adding an encoder to a stepper motor but it defeats the whole point some what. Spend more money on a better stepper motor and save the money by not requiring the encoder.
When looking to buy a stepper motor then you need to check info such as whether it has a gearbox, A gearbox will improve the torque (moving power) but reduce the RPM (speed).
The next consideration is that there are two different categories of stepper motor: bi-polar and uni-polar.
If you have already purchased a motor, or re-cycled one from some old hardware, then you need to determine the category.
Generally: a bi-polar motor has 4 connections and a uni-polar has either 6 or 8 connections.
stepper4.jpg
This is a bi-polar stepper motor
stepper6.jpg
This is a 6 pin uni-polar stepper motor. By leaving the A' and B' centre taps unused then we can use the AC and BD terminals as if it was a bi-polar motor.
stepper8.jpg
This is an 8 pin uni-polar stepper motor. By connecting A' to C' and B' to D' then we can use the AC and BD terminals as if it was a bi-polar motor.
seperator.jpg
A simple ohm-meter, on a low setting, can be used to discover which pin is which.
Note how a uni-polar can be transformed into a bi-polar motor; but not the other way around.
Stepper Motor Specifications
The specifications of your motor should list the resistance of each coil (or 'phase' as they are also known). This will help you to use your multi-meter to work out which terminals are which if your data sheet isn't very revealing. If not: then you will have to play with your ohm meter to work it out.
Knowing the coil resistance then the data sheet may give a range of battery voltages that can be used or it may list a maximum current. Using Ohms law: Voltage = Current x Resistance then we know the coil Resistance so given either the current or voltage then we can calculate the other value.
Now that you know the voltage to be applied, and hence the current drawn, then you can find a suitable driver for that combination.
For example: if the coils are 2 Ohm and we have a 6V battery then the controller needs to be able to supply (Volts./ Resistance) = 6/2 = 3 Amps.
Check the torque of the motor you buy is capable of the mass it needs to control. If your motor is just rotating the 'head' of the robot then it wont need as much torque as if it was driving the whole robot across the ground.
Also check the number of steps per rotation, or angle per step, to make sure it gives the accuracy you need.
Drive Modes
All stepper motor drivers provide a 'Full Step' mode. This mode provides the best torque but requires the highest current drain and gives a 1:1 ratio - ie it will give 200 steps for a motor listed as having 200 steps per revolution.
Most drivers can provide 'Half Step' mode. This doubles the number of steps per revolution but normally requires less current and hence there is less torque. NB it also means the maximum RPM is also halved.
Deluxe drivers go beyond 'Half Step' and provide 4, 8 or even 16 times the number of steps per revolution. Often called 'micro-stepping' but, as mentioned above, this positional accuracy comes at the expense of torque and RPM.
Summary
So you should now understand how to connect your motor as well as the benefits/implications of using micro-stepping for greater positional accuracy at the expense of torque.
Most boards allow you to configure the 'micro-stepping' via some input pins. However: this is something that you will set once and not reconfigure whilst the robot is running. Hence this library leaves those connections down to you. Suffice it to say that if your motor has 200 steps/revolution and you configure the driver to use 'Half Stepping' to give 400 steps/revolution then you should just declare it as having 400 steps/revolution.
Slip
As mentioned earlier stepper motors are liable to slippage if they are not used within their capabilities. This normally happens because you are trying to turn it too fast for the load it is supporting or because you are accelerating/braking too fast (ie the wheels skid). Consequently: WebbotLib allows you to specify the maximum acceleration/braking to be used to try and avoid such slippage.

File

Valid XHTML 1.0 Transitional