Create a PID Controller on the NI myRIO—The Hardware
In this short project article series, we will implement a simple PID controller using LabVIEW with a hobby DC servo motor and NI myRIO.
Learn how to implement your own simple PID controller. In this article, we will focus on the hardware: NI myRIO and a hobby DC servo motor.
In this short article series, we will implement a simple PID controller using LabVIEW with a Hobby DC Servo motor. We will customize the servo by removing its internal controller and substituting one we will make, ourselves. In this article, we quickly introduce you to the PID control and follow with the hardware work required. The next article will discuss software and implementation.
The world we live in is extremely dynamic and oftentimes hard to measure, let alone control.
Imagine an electric motor—when it was made, it had mechanical tolerances which add up to measurable inaccuracies. Moreover, as environmental variables change, so will the motors response and behaviour.
These changes or inaccuracies alone can result in a device that sometimes performs well and sometimes does not output what we expect. Therefore, our device needs to be able to adapt or it can simply be controlled.
Whenever we want to regulate processes or control moving devices such as the motor example above, we use an external device or a software module often referred to as the controller.
Arguably the most popular method of using a controller in academia and in industry is the PID controller.
PID stands for Proportional-Integral-Derivative. This control method uses a feedback loop which compares the desired value against the actual value to find any error, which it then tries to minimise. As the error becomes smaller and smaller, the process or device is approaching the desired state. If you would like to read about the technical details of PID control, please refer to this article.
To follow along, you should have the following hardware available:
- NI myRIO embedded hardware device
- Hobby DC servo motor that you're alright with disassembling and customizing
- Jumper wires
- 10kOhm resistors (x2)
- Soldering iron/station
Additionally, if you have heat-shrink tubing and/or insulation tape, it might also come in handy.
Figure 1. Setup for this experiment
About Our “Plant”
Often in the context of controllers, the device being controlled is referred to as the “plant”. This is a legacy term (imagine a large chemical plant with processes that need to be controlled) that you can still often find in literature.
The hobby servo is going to be our plant. But before we jump into how we use it, let’s discuss the customizations we need to perform first and cover some background.
In most cases, a standard analogue DC servo will have an op-amp-based controller contained within the casing. With addition to that it will have a rotary potentiometer to detect current position, which is required for feedback. We will customize this controller so that it can be used for something other than its original purpose.
If you have heard about modifying servos for “continuous rotation”, you might know where this is going. Our modification is slightly different in that we will keep the potentiometer in its original location rather than removing it altogether.
Our plan here is to customize the internal servo controller in such a way that we can control the velocity rather than position. To do this, we will replace the potentiometer wires with a pair of 10kOhm resistors connected as a voltage divider, which provides a fixed output voltage (as opposed to the potentiometer, which produces an output voltage that changes as the servo rotates). This will trick the internal controller into always detecting a positional offset.
By sending it typical servo pulses, we will gain the ability to control velocity rather than position.
Figure 2 and Table 1 below show how a standard servo motor would be expected to work without any customizations.
Figure 2. Simple servo control through PWM
Table 1. Standard servo behaviour
Table 2 shows how it would then respond after the customizations for the same inputs. T, in this case, is set to 20 mSec (50Hz refresh rate).
Table 2. Servo behaviour after customization
Now that we have an idea of what we need to do, let’s implement it in practice. Follow these steps to prepare the DC servo to be controlled externally:
1. Unscrew the bottom of the servo motor and remove the back casing. Then find the potentiometer (it should be connected to the rotary part of the servo) and identify the three wires it is connected to the board with.
2. De-solder these three wires from step 1, taking into account which solder pad each of the wires goes to (especially the middle one!). If you can, try to take pictures as you go in case you need to refer back to your work.
Figure 3. Servo with back cover removed.
3. Join the two 10kOhm resistors together as shown in Figure 4, making their middle joint a separate leg. Optionally, you can solder the joint to make sure it's fixed in place. This will form a voltage divider that provides half of the voltage across the two resistors.
Figure 4. Creating the voltage divider from two 10kOhm resistors.
4. Now we will replace the potentiometer connections with our newly made voltage divider. Solder the resistors to the same pads that the potentiometer wires were connected to. Ensure that the lead where the two resistors meet goes to the center pad (where the middle wire of the potentiometer was connected). This is indicated as (2) in Figure 5. The other two can go either way (1).
Figure 5. Replacing the potentiometer with the voltage divider.
5. Solder (or attach in some other way) the three hanging potentiometer connections to jumper wires so we can connect them to the myRIO in the next step.
Figure 6. Jumper connectors soldered on the potentiometer wires for easy interfacing to the myRIO.
6. Connect the previously soldered jumper wires to the NI myRIO MXP Extension board. The middle (wiper) wire from the potentiometer (white in my case) must go to AI0 of Port A. The remaining two must be connected to ground and 5V. Note that you can choose a different method to physically connect to the myRIO, as long as the wires are going to the correct connections.
7. Use three additional jumper wires to connect the black, red, and white wires on the servo connector to ground, 5V, and AO0, respectively. Again, you can use different means to physically interface to the myRIO as long as the connections are the same.
If you followed the instructions, you should have something that looks like the setup shown in Figure 7.
Figure 7. Full servo customization and connection setup of the experiment.
Figure 8. Modifying the servo enclosure.
Finally, you will want to close the servo enclosure. Since we now have extra wires coming out of the device, I had to make some extra space by clipping off part of the plastic cover (see Figure 8 above). I also used heat-shrink tubing to cover the wire connections so they do not accidently touch each other.
That is all we need for the hardware. In the next article, I will explain how to write the PID controller in software using NI LabVIEW and control the customized servo using our own custom PID controller.
Next Article in Series: Create a PID Controller on the NI myRIO—The Software
Give this project a try for yourself! Get the BOM.