Control
There are two sorts of motor control:
- Position Control – In position control, one attempts to control the angular position of the motor shaft. I.e. if you command the motor to move to a position, it moves to that position and attempts to hold that position even if one attempts to move the motor shaft.
- Speed Control – In speed control, one attempts to control the angular velocity of the motor shaft. Think of your table fan, where by turning the speed dial you control the fan speed.
The rest of this post talks about position control – speed control will be covered in a future post.
Hobby Servo Motor
In hobby robotics, position control is achieved using hobby servo motors and that will be subject of the rest of this post.
A hobby servo motor made by Hitec Servos.
Hobby Servo motor is a generic term used for a family of motors, made by a host of different manufacturers, where the motor case contains not just the motor, but also a gear train that increases the torque output and reduces the speed and also feedback control circuitry to provide easy position control.
Cross section of a hobby servo motor. Note the motor itself (blue box at the bottom left, the gear train and the circuitry. All this is inside the hobby servo case. The servo horn is actually outside.
Block Diagram for using a Hobby Servo Motor
There are typically 3 parts to any hobby servo motor control circuit – a computer, connected to a servo controller which is in turn connected to one or more hobby servo motors. The servo board is typically powered from an external battery or a wall charger.
- Computer: This is the computer (or Arduino board) running your robots main control program. The computer determines what sort of movements the motors should make and commands the motors to do so via the servo controller.
- Servo Controller: The servo controller is a circuit board (typically purchased off the shelf) which converts the command provided by the computer into the signal that the motor expects (i.e a PWM signal – more on this later). Arduinos likely have servo motor shields (I have not searched for them, but I would be surprised if they did not exist).
- To make your life really simple, servo controllers typically accept very simple commands – typically just a simple text string like “M 4 23” which means move servo number 4 to position 23 (the specific syntax depends on the servo controller board manufacturer). The servo motor controller then converts that command to an appropriate train of PWM pulses to move the motor to that position. Sophisticated servo controllers can move multiple servo motors in a synchronized manner, where you can command motor 1 to move say through 30° and motor 2 to move through 120° and have both movements start at the same time and end exactly 2 seconds later. The command for this movement could be as simple as “M1 30 M2 120 T 2”, where the controller will take care of the rest. Sophisticated servo controllers can even generate the motor commands to move a whole hexapod robot.
- The servo controller also provides the current to drive the servo motors (which does not come from the USB Port of the computer).
- Hobby Servo Motor: Obviously! Hobby Servo motors plug into the servo controller.
All the pieces needed to control a hobby servo motor.
Pulse Width Modulation (PWM)
The servo controller commands the hobby servo motor to move to a position, by encoding that position in the form of a pulse width modulated signal. What does this mean?
How pulse width affects motor position. Note in the lower 3 figures, that despite the fact that the pulse width changed, the interval between the square pulses does not change – it is always 18 ms.
The servo controller sends the hobby servo motor a regular train of rectangular pulses. I.e., like clockwork, every 18 ms, the servo controller sends the hobby servo motor a rectangular pulse.
The rectangular pulse itself, has a width – the time for which the pulse is “high”. Note that as the width of the pulse is specified in terms of how LONG, the pulse is high, the unit of measurement for pulse width is a unit of time i.e. milliseconds and not a unit of length (e.g. millimeters)
Position Control: In pulse width modulation, the width of the pulse is changed – for hobby servo motors, this width typically varies between 1-2 ms (could vary based on the motor). So, as the name pulse width modulation implies, the actual position you want the motor to move to, is encoded in the width of the pulse. As can be see in the figure above, for a motor which has a motion range of 180°, when the pulse is 1 ms, the motor moves to one extreme position (0°). At a pulse width of 2 ms, the motor moves to the other extreme position (180°). And if you feed it a pulse width between 1-2ms, the servo stops a corresponding position between the extreme positions.
Speed Control: It is clear now that the motor shaft position tracks the width of the pulse train. So if you change the pulse width of the train of pulses being fed into the motor in our example, from 1ms – 2 ms, in 5 seconds, the motor will move from its initial position to its final position, in 5 seconds. If you change the pulse width from 1-2ms in 1 second, the motor would make the movement from its initial position to its final position in 1 second (see the section on motor specs for more on the upper limits on this). I.e. the faster you change the pulse widths, the faster the motor will move – put another way, the rate at which you change the pulse width determines the speed at which the motor shaft moves.
How does a Hobby Servo Motor Work?
Parts of a hobby servo motor
Before we get started, to avoid confusion, note that everything described in this section is INSIDE the hobby servo motors case. Everything in the previous section is OUTSIDE the servo motor case.
With that out of the way, how does a hobby servo motor move to the position that you want it to move to? A motor on its own would not be able to do that – if you turn a motor on, it would just spin continuously without stopping.
To make the motor move to a particular position and stop, we need some way of figuring out where the motor shaft is. To do that, we the motor shaft is connected to a potentiometer so that as the motor shaft rotates, the potentiometer rotates. The potentiometer is the same thing that is used in the volume control of your stereo so just as your stereo knows the position of the shaft to change the volume of your music, using the potentiometer, it is possible to know where the motor shaft is.
The third piece in the puzzle is the control circuit. When you plug your hobby servo motor into the servo controller, the servo controller is actually plugging into the control circuit. So when the servo controller sends a PWM signal, that signal is actually going to the control circuit. The control circuit is in turn connected to the motor and the potentiometer. The servo controller uses the potentiometer to figure out where the motor shaft actually is. If the shaft is not where it should be, the controller sends the motor current which cause the motor shaft to rotate. As the shaft rotates, the potentiometer rotates along with it – this way, the control circuit always knows where the shaft is. As the shaft gets closer to the commanded position, the amount of current sent to the motor get less and less till when the motor is where it needs to be, no more current is sent to the motor so it does not move.
Once the motor shaft gets to where it needs to be, if you try to move the motor shaft, the control circuit will kick in and send current to the motor, to get it back to its commanded position. If you power up an actual hobby servo motor and try and do this, you will hear a buzzing sound, which is actually the sound of the motor making tiny movements to correct its position – dont let the buzzing noise worry you – that is quite normal.
The algorithm that the controller circuit uses to determine how much current the motor needs to get, depending on the how far the motor shaft is from where it needs to be, is called PID control. More about this in the section on motor specifications.
Selecting Hobby Servo Motors
This section discusses the various parameters one must consider while selecting a hobby servo motor for a position control application. While it may seem that at the end of this section you will be able to make very scientific choices regarding the hobby servo motor, to pick for your application, nothing could be further from the truth. At best the parameters are published for hobby servo motors are very coarse grained and will just allow you to get in the ball park of the motor you need. In reality, you will need to keep this ball park in mind and try and exceed it however much your budget will allow.
This is a good link to get a feel for the sort of parameters published for hobby servo motors. You should browse that page while reading the rest of this section.
Performance
- Torque – This is a measure of the turning “force” of a hobby servo motor. The higher the torque, the more massive the object the motor can move. Torque is measured in kg-cm or oz-in. Intuitively, if a motor is rated at a 4 kg-cm torque, it means that if you attached a rod to the motor shaft and suspended a weight of 4kg, at a distance of 1 cm, the motor would not be able to move – i.e. the motor would be stalled. If you reduced the weight a tiny bit, the motor would rotate. If you increased the weight even by a tiny bit, the motor would no longer be able to fight it and hold its position. In other words, the torque rating, could also be called the “stall torque” of the motor.
- Speed – this is a measure of the maximum angular velocity the motor shaft can achieve – of how fast the motor shaft can rotate. While conventionally angular velocity would be measured in degrees per second (the number of degrees the motor shaft would rotate in one second), hobby servo motors are usually rated in units like 0.06 sec/60°. I guess the goal of the servo manufacturer is to give the reader a more intuitive feel for how far the motor moves. One can quickly appreciate that a motor that takes just 0.06 seconds to move 60°, must be really fast. The other thing to note about this rating, is that this is the no-load speed of the motor. I.e. if you actually use the motor to move something, the speed is going to be lower. Also, unfortunately, I have never seen a hobby servo motor manufacturer publish a load-velocity curve.
- Rotation Range – All the motors/engines that one typically encounters, can rotate round and round continuously. Hobby Servo Motors however, typically have a limited range of motion beyond which they will not move (e.g. a motor may only be able to move through a 180° range, no more!) so always check this before purchasing a motor. There are continuous rotation servo motors out there – people also modify servos with limited range of motion to have a full range of motion (which ofcourse invalidates the warranty on the motor)
- Resolution – this is a measure of the smallest angular movement that the motor can be commanded to make. This is pretty crucial because this determines how finely you can control the position of the thing you want to move using the motor (e.g. imagine if you were building a robot arm). However, things get quite tricky here, because most hobbys servo motors do not provide their angular resolution ratings – this can be quite infuriating, as servos will be rated as “super accurate”, but nothing more. Resolution is also confusing because in reality there are two resolutions at play here – the Servo Controller Resolution and the Servo Motor Resolution. The Servo Controller Resolution is the smallest change to pulse width that the servo controller can make. If the exact pulse width is specified to your servo controller, by a 16 bit number, you should be able to specify 216 distinct pulse widths. If the servo motor that you have, has a rotation range of 180° the controller should be able to command it to move to one of 216 positions, giving you an angular resolution of 0.003°. However in reality, because of the physical design of hobby servos, the servo motor resolution is much coarser than that. Depending on the motor, you should be able to get between 0.5° to 0.3° (an exception is the MX-28 which has a resolution of 0.088°). I.e. it would take a few step changes in the pulse width, before the change in pulse width got large enough for the hobby servo motor to actually detect it and move. Like a bunch of other properties, it turns out that resolution depends on the load that you are trying to move – at larger loads, the resolution of the motor could drop off (though you may be able to counter this by operating the motor at higher voltages – provided you stay within the rated motor voltages).
Electrical Properties
There are two categories of electrical properties – voltage and current properties.
Voltage: Hobby Servo motors can operate over a range of voltages ranging from ~4.8V to ~6V. Note that the servo torque and speed are rated at a particular voltage and that servo torque and speed are directly proportional to voltage and speed. So if you have a servo that is rated as providing 3 kg-cm at 6V, if you apply 4.8 V, you should expect to see less torque. The same is true of speed.
Current: Servo motors “draw” current from the servo controller. The amount of current that the servo motor pulls depends upon the load on the servo motor – the greater is the load, the greater is the current draw.
Current draw against load – note the large variation in the motors current draw
One needs to ensure that the servo controller that one will use for ones project, can satisfy the current needs of all your servo motors at the same time. So if you are going to use 3 servo motors in your project and you know that each servo motor will draw a peak current of 1A, then your servo board must be able to source well over 3A of current. If your servo board was not designed to source this much of current, the results could vary between the servo board getting burned out to the servo board rebooting – the latter will cause very random behavior where suddenly for seemingly no reason, your robot arm (assuming you are building one) would just flop.
Unfortunately, like many things hobby servo, you will not find the current draw on the typical hobby servo spec sheet! To figure out the current needs of your motor under load, you need to measure it – see this for more information. Some hobby servo motors provide power output ratings. Assuming that these ratings are for peak power output, one could compute the peak current requirements, at a particular voltage using the formula:
Physical Construction
You should take into consideration the following physical properties of the hobby servo motor, prior to purchasing it:
Dimensions: Hobby Servo Motors come in a range of dimensions and you need to ensure that the motor you pick is the right size.
Hobby motors come in a range of sizes. Smaller motors weigh less.
Brackets and mounts: Given that hobby servo motors come in standard sizes, one can also find pre-fabricated metallic brackets that can be used to mount the motor and transfer motion. An example is the servo erector set where the folks at Lynxmotion have thrown together a bunch of pre-cut aluminium parts from which a variety of robots can be built. Browse their website to expand your mind on what can be done with done with standard brackets.
The thing to be careful about is to make sure that the motors and mounts you buy match each other. For example the mounts that Dynamixel sells for their motors are not compatible with regular hobby servo motors. Also brackets and mounts for smaller hobby servo motors will not work with larger hobby servos.
Servo Horns: Servo horns are attachments to hobby servo motor shafts. Typically servo motors ship with a few different horns in the box. Horns can be used to transfer motion from the hobby servo to other mechanisms or as attachments for other parts.
Servo Horns come in a variety of sizes and shapes.
The images below show some examples of horn usage, some from the robotics world and some others from the radio control world.
Attaching servos to the servo bracket using screws. The servo horns do not have screw threads – you just turn a screw in and the screw will tap its own threads.
Use of a push rod in an RC aircraft to move the control flaps. The push rod connects to the hobby servo motor as shown in the picture, via a hole on the horn. A clevis could have been used for this purpose as well. The rod and the part on the other end can be purchased at an RC hobby store.
- Gearing/Servo Life: As gears turn the gear teeth constantly grind against each other and over time, wear off. Some applications like a biped robot, where the motors in the leg take a lot of load and impact as the robot walks, may wear out much gears faster compared to motors say in the elbow of the same robot, where the motors take less load and impact. As gears wear out, slop is introduced in the gear train which means that it will be possible for one gear to move a small amount, without the next gear in the train moving. This will obviously make the motor less precise.
It is possible to mitigate this problem, by shelling out for motors with more robust geat trains. As can be seen in the image below, there are a variety of materials that are used for the gear train inside the servo motor. The material determines the strength and the life of the gears. The trade off here is between strength and life, vs cost – equivalent motors with stronger and longer lasting gears, cost more.
-
Gear train materials and their impact on life and strength
One question you may have looking at the table above is what it means to have a gear that lasts “years”. Admittedly that is a vague statement – the thing to keep in mind is that these motors are built for hobby applications like radio control toys where people are expected to use these toys for at the most a few hours every week. So most likely when they say a life of a few years they mean a life of a few years under RC usage conditions. The only manufacturer that I have seen that actually specifies life in concrete terms is Firgelli (who BTW are the only manufacturers I know of who make linear servo motors) who rate their motor life time as 20,000 strokes. So that should give you another indication of the life of these motors.
Analog vs Digital Servos
Analog Servo and Digital Servo are confusing terms that you see on websites selling servo motors. All you need to know really are that digital servo are better than equivalent analog servos. The only con of digital servos are that they consume more power – this should be a concern if you are building something battery powered.
If you want to know more, a great explanation of the differences between analog and digital servos may be found here.
Another advantage of digitial servo motors is that SOME of them (note that most aren’t) are actually programmable. If you recall earlier we mentioned that the control algorithm in the hobby servo motors is PID control. PID control is a complex topic, worth its own separate post. However, for the purpose of this post, the PID control algorithm takes 3 numbers as parameters – the proportional gain, the integral gain and the derivative gain. Most hobby servo motors, come from the factory with these numbers hard coded in. Programmable servo motors allow you to change the numbers allowing you to change the behavior of the servo motor as it moves to its commanded position. So if you see issues like the motor in some positions moves exactly the position you commanded it to move to and not in other positions, or if you see the motor swing around the position you commanded it to move to, you may want to look at programmable motors.
Conclusion
Hopefully you found this tutorial helpful in getting your head into the hobby servo motor space. At the end of the day, there is no substitute to actually buying some motors and playing with them – I would urge you to do that – happy motoring 🙂