This tutorial shows the characteristics of the proportional (P), the integral (I), and the derivative (D) controls, and how to use them to obtain a desired response with the NI myDAQ or NI ELVIS II series. This tutorial uses LabVIEW and the LabVIEW Control Design and Simulation Module with the PID Toolkit.
This tutorial is based in part on the Control Tutorials developed by Professor Dawn Tilbury of the Mechanical Engineering department at the University of Michigan and Professor Bill Messner of the Department of Mechanical Engineering at Carnegie Mellon University and were developed with their permission.
Learn concepts of proportional, integral, and derivative control, and use the myDAQ or ELVIS II to adjust the speed of a DC motor with PID control in LabVIEW.
The Three-Term Controller
Consider the following unity feedback system:
Figure 1: Unity Feedback System
Plant: A system to be controlled
Controller: Provides the excitation for the plant; Designed to control the overall system behavior
The transfer function of the PID controller looks like the following:
First, let's take a look at how the PID controller works in a closed-loop system using the schematic shown above. The variable (e) represents the tracking error, the difference between the desired input value (R) and the actual output (Y). This error signal (e) will be sent to the PID controller, and the controller computes both the derivative and the integral of this error signal. The signal (u) just past the controller is now equal to the proportional gain (Kp) times the magnitude of the error plus the integral gain (Ki) times the integral of the error plus the derivative gain (Kd) times the derivative of the error.
This signal (u) will be sent to the plant, and the new output (Y) will be obtained. This new output (Y) will be sent back to the sensor again to find the new error signal (e). The controller takes this new error signal and computes its derivative and its integral again. This process goes on and on.
Characteristics of P, I, and D Controllers
A proportional controller (Kp) will have the effect of reducing the rise time and will reduce but never eliminate the steady-state error. An integral control (Ki) will have the effect of eliminating the steady-state error, but it may make the transient response worse. A derivative control (Kd) will have the effect of increasing the stability of the system, reducing the overshoot, and improving the transient response. Effects of each of controllers Kp, Kd, and Ki on a closed-loop system are summarized in the table shown below.
Note that these correlations may not be exactly accurate, because Kp, Ki, and Kd are dependent on each other. In fact, changing one of these variables can change the effect of the other two. For this reason, the table should only be used as a reference when you are determining the values for Ki, Kp and Kd.
The application demonstrated in this tutorial uses the myDAQ or ELVIS II to adjust the speed of a DC motor with PID control in LabVIEW. The tachometer (instrument measuring rotation speed of the motor) uses a Hall effect switch that turns on and off with the angular motion of a small magnet attached to the motor shaft. LabVIEW can then read a frequency from the switch, compare it to a desired frequency, and adjust the actual frequency with PID control to the desired frequency.
Figure 2: Control flow for our application
Set Up Hardware:
Wire the components to the myDAQ as shown below. If the ELVIS II is being used, all of the same ports can be used, with the exception of PFI9 in place of DI1. Both of these ports take in a digital frequency. The TIP120 is necessary to step up the current from the myDAQ or ELVIS II, as the analog outputs do not supply enough current to drive most DC motors. Make sure that the curved edge of the Hall effect sensor is directed towards the motor shaft, and that it is close enough to detect the magnet. The magnet may be hot glued on the shaft, or simply placed on, depending on its strength. It may be necessary to tape the motor to the board, depending on how much it moves.
Figure 3: NI myDAQ Wiring Diagram
*Note: Red wires are directly attached to a power source, brown wires are directly attached to ground, and blue wires are directly attached to neither.
LabVIEW User Interface
The user interface we created allows the user to manually adjust the setpoint of the motor speed, the PID gains, and the output voltage range. It also displays the desired motor speed and the actual motor speed.
Figure 4: 'PID.vi' Front Panel
The basic coding strategy for our program is shown below. For a more detailed description, check out the block diagram of ‘pid.vi.’
Figure 5: 'PID.vi' Coding Diagram
The LabVIEW block diagram shown below looks very similar to the coding block diagram
Figure 6: LabVIEW 2010 Block Diagram
How It Works:
Before running the PID control program, it is helpful to make sure that the Hall effect switch is working. To do so, hook up the output of the switch to AI0+ and AGND to AI0-. Run the oscilloscope from the NI ELVISmx Instrument Launcher, and move the small magnet close to and away from the sensor. Square wave pulses should be seen in the oscilloscope. Once proper operation of the Hall effect switch has been verified, and the circuit is set up to resemble Figure 4, we are ready it run the PID program. Open ‘pid.vi’ and click Run. The PID gains in place worked well for the motor we were testing, but yours may need adjustment. There are various methods of setting the PID gains, but one of the most common is simple trial and error. Adjust the setpoint motor speed, and observe the actual motor speed. Based on the effect of the PID gains on the system in Figure 2, adjust the gains to make the motor speed smoothly and quickly adjust to match the setpoint.
Tips and Tricks:
Webcasts, Tutorials, and Other How-To Resources