WebbotLib AVR library
WebbotLib It just does it


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 know.
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.
Purchasing Decisions
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.
This is a bi-polar stepper motor
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.
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.
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.
Stepper Motor Controllers
The WebbotLib stepper motor driver doesn't mean that you can just connect the motor directly to the micro controller - they need way too much current. Hence you will also need one of the supported stepper motor controllers.
Drive Modes
All stepper motor controllers 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 controllers 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 controllers 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.
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 controller 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 in Project Designer as having 400 steps/revolution.
Project Designer
When you create a stepper motor driver in Project Designer you need to specify the 'Maximum Step Frequency (Hz)' ie a value of 200 would mean that the maximum speed for the motors is set at 200 steps per second. Check the datasheets for the motors you are using to see if they specify this value. If they don't then you will need to find it by trial error. If the number is too low then you will be restricting the maximum speed of the motor and if it is too high then the motor may ignore some of the pulses as it is unable to keep up.
If you are using a variety of different motors then use the smallest value across the different motors - alternatively create a different driver for each motor model.
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. When adding each motor in Project Designer you can specify the 'Acceleration speed increment' and the 'Acceleration speed interval' - these two settings combine to set the maximum acceleration.
For example: if the maximum step frequency is 200Hz (ie every 5ms) and we set the 'Acceleration speed increment' to 1 and the 'Acceleration speed interval' to 10 then the motor will increase by '1' every '10 x 5ms = 50ms'. So if the motor is currently at rest and we set a DRIVE_SPEED of 100 then it will take 5 seconds to get up to the final speed.
Setting the 'Acceleration speed increment' to 127 will give 'infinite' acceleration.
Modes of Operation
WebbotLib allows you control the stepper motor in two different modes: continuous and one-shot.
In continuous mode you specify a DRIVE_SPEED and the motor accelerates, or decelerates, to the required speed. This allows you to use it just like any other DC motor and you can do this by using the functions, and example, shown in Actuators.
In one-shot' mode you specify how many steps you want the motor to turn. This will happen in the background and once completed the motor will stop. This is useful, for example, to make precise turns.

Project Designer supports the following devices

Valid XHTML 1.0 Transitional