Using National Instruments System Identification, Control Design and Simulation Products for Design
Overview
For engineers who need to identify system behavior and design controllers to obtain the best possible closed loop system characteristics, National Instruments (NI) provides LabVIEW based software tools and flexible, low cost hardware solutions. This is a superior alternative to expensive fixed-functionality systems. Unlike these embedded, inflexible alternatives, NI products provide an easy to use, integrated graphical environment and built-in compatibility across a broad range of data acquisition and control hardware devices.
Table of Contents
This article describes the process of designing a closed loop control system, or plant, using the NI System Identification and Control Design Assistants. A DC Motor will be the plant (Figure 1).

Figure 1: The Quanser Engineering Trainer (QET) will be the plant for which we will design a closed loop controller.
The Quanser Engineering Trainer will be used in velocity mode. A voltage signal commands the motor to move and the tachometer output determines the velocity. The motor system is connected to a National Instruments CompactDAQ device, shown in figure 2, where Analog Input Channel 0 of a 9211 Analog input module (AI0) is connected to the tachometer and Analog Output Channel 0 of a 9233 Analog output channel (AO0) is connected to the motor command input. For demonstration purposes, you can replace the DC motor with an RC circuit.

Figure 2: CompactDAQ system
This example uses the following LabVIEW add-ons:
• NI LabVIEW System Identification Toolkit
• NI LabVIEW Control Design and Simulation Module
You can purchase these products together in the Control Design and Simulation Option of the NI Developer Suite.
The closed-loop system acts on the difference between two quantities: the process variable (the voltage output of the tachometer as a function of motor velocity) and the setpoint (the command voltage you specify). The controller then determines the next voltage level to command to the motor to meet the specifications defined while designing the controller. Figure 3 shows the final closed-loop system.

[+] Enlarge Image
3. The final closed loop system. The Plant Model is the QET (Figure 1).
This example describes the process of designing a simple PI controller for a system with unidentified dynamics. Note that all functionality described in the National Instruments SignalExpress environment is also available in LabVIEW. All project scripts and LabVIEW VIs described in this document are available as attachments to this document.
2. Identifying the System
To identify an open loop system we need to excite it with a signal that has voltage levels and frequency content that corresponds to its actual operating conditions.
You can use many different signal types to identify a system, including chirp signals, square waves, square waves overlaid with white noise, and so on. For this example, the stimulus signal is a 3V p-p triangular wave. You create this signal using the “Create Signal” step available in the SignalExpress environment. Figure 4 shows how this signal was created. And Table 1 shows where to find the settings for this particular step and what values to use:

Figure 4. Creating a 3 Volt p-p triangular wave.
Table 1 shows where to find the settings for this particular step and what values to use:
|
Step |
Settings / Actions |
|
Signal Input/Output |
Signal Type = Triangle Wave |
|
Frequency = 1 Hz |
|
|
Amplitude = 3 V |
|
|
Sample Rate = 1kS/s |
|
|
Block Size = 5000 samples |
Table 1. Settings for creating the signal
To display the created signal on the data viewer in SignalExpress, drag the "Triangle Wave" Output to the Data View (Figure 5).

[+] Enlarge Image
Figure 5. The created signal in the data viewer in Express Workbench.
Next, you must have the compactDAQ device generate this signal as an analog output. Use the “DAQmx Generate” step to perform this function, shown in Figure 6.

Figure 6. DAQmx Generate step to output the created signal as an analog signal on the DAQ card.
Table 2 shows the settings for this step:
|
Step |
Settings / Actions |
|
Signal Input/Output |
Config Tab: Device: Make sure to select appropriate DAQ Device and Channel |
Table 2. Settings for generating the signal on the appropriate “Device” and “Channel”
NOTE: This example does not synchronize the AO and AI channels of the compactDAQ device. Typically you should synchronize these channels, which you can accomplish using the Advanced Timing page, because any delays caused by the difference in timing between AI and AO would be described by the transfer function of the open loop system, resulting in some error in the identification. In this example, the sample rate for AI and AO is 1 kHz, so the maximum jitter between the two channels is 0.5 ms. This amount of jitter is negligible compared to the plant dynamics.
As shown in Figure 7 use the “DAQmx Acquire” step to acquire the response of the plant to the stimulus signal. Table 3 shows the parameters for the step

Figure 7. DAQmx Acquire step to acquire the response back from the DC motor plant as an analog signal to the DAQ card.
|
Step |
Settings / Actions |
|
Signal Input/Output |
Config Tab: Device: Make sure to select Device and Channel |
|
Config Tab: Acq. Timing: 5000 samples to read |
|
|
Config Tab: Acq. Timing: 1 kHz sample Rate |
Table 3. Settings for acquiring the signal on the appropriate “Device” and “Channel” (AI0 in this case).
Right click on the out of the step (Voltage) and select “Rename”. Type “Speed”
NOTE: To make sure the data acquisition step begin as soon as possible, go the the “Execution Control” tab and make sure to uncheck the option “Start this step after” as show in figure 8.

Figure 8. Execution control setup for data acquisition step
Going back to the Dataview, we are going to plot the data acquired. To do so, hit the “add display” button at the top of the Dataview and drag and drop “speed” to the new plot
Next, run the project script once by clicking the green run arrow. This project generates and acquires 5000 data points at 1 kS/s for a total of five seconds of plant response data. This response data appears in the display you added in the previous step. Figure 9 shows the stimulus signal and the plant response data.

[+] Enlarge Image
Figure 9. The stimulus signal is in the upper display. The plant response to this signal is in the lower display.
You can use the stimulus signal fed to the motor and the response data obtained from the tachometer output to define a transfer function for the open loop DC motor system. To define this model, you will use a parametric estimation of the motor model. In this example, you use the default settings of the Parametric Estimation step, shown in Figure 10, to create a first-order transfer function based on the plant dynamics.

Figure 10. Identifying a parametric estimation of the DC motor plant system.
Table 4 shows where to find and the settings for this step:
|
Step |
Settings / Actions |
|
System Identification |
Input Signals and Model Tab: Stimulus Signal: Calculated signal |
|
Add Display under "DAQmx Acq" Output Display |
|
|
Drag "Estimated Response" to new Display |
Table 4. Settings for identifying a parametric estimation of the QET DC motor plant system.
Notice that the largest prediction error typically occurs in the beginning of the signal. This error occurs for two reasons: the initiation effects of spinning up the system (which is typically not in perfect mechanical balance) and because the numerical algorithm used to identify the model requires several time steps to initialize itself. For example, the disc that this particular QET DC motor spins has 2 holes drilled through it, and depending on the location during startup the motor might start slower or faster. Therefore, the coefficients of the resulting transfer function change slightly every time you run the final Express Workbench Project Script.
At this step in the example, the transfer function is discrete. Although you can design a discrete proportional-integral (PI) controller in Express Workbench, this example converts the transfer function model to a continuous one because the motor is a continuous plant. To facilitate this design in the continuous domain, also known as the s-domain, this example transfers the model into a Control Design type function and then converts the model into continuous representation. Figures 11 shows how to convert a System Identification Model to a Control Design Model using the “Convert to Control Design” Step and then figure 12 shows how to convert a discrete model into a continuous model using the “Discretize Model” Step

Figure 11: Converting the System ID Model to a Control Design Model Type (Transfer Function)

[+] Enlarge Image
Figure 12. Making the discrete model continuous
To display the step shown in Figure 12, select Control Design»Model Transformation»Discretize Model. On the Configuration page of this step, select Make Continuous from the Operation pull-down list.

[+] Enlarge Image
Figure 13. Displaying the transfer function of the open-loop system plant in the s-domain.
The system has now been identified as a first order transfer function. Every time the Express Workbench project script is run, the coefficients of the transfer function will change slightly. This is due to the spinning wheel and other mechanics of the motor itself (and the tachometer, and the fact that AI and AO is not 100% synchronized etc.), as explained above during the Estimation of the Parametric Model.
3. Controller Design
Now that the transfer function of the plant is available, the next step is to design a controller for this plan. This example describes how to design a controller that meets requirements for rise time, settling time, overshoot, and so on. This controller will complete the closed-loop system.
This example designs a simple proportional-integral (PI) controller using the “PID Synthesis” step, shown in Figure 14. Although not shown in this example the tools to perform a root locus or interactive bode design are also present in the assistant and the LabVIEW palette.

[+] Enlarge Image
Figure 14. Designing a PI controller for the DC motor.
Table 5 lists the settings for designing a PI controller.
|
Step |
Settings / Actions |
|
Control Design -> |
Controller Synthesis Tab: Check “Gain” and "Integral (s)" boxes |
|
Adjust P and I gains to obtain desired step response. Refer to Figure 14 for the recommended settings. |
Table 5. Settings for designing a PI controller for the DC Motor Plant System.
As you adjust the values of the P and I gains, the step response graph changes to show the resulting rise time, overshoot, ringing, settling time, and so on. Adjust the P and I gains so the step response looks similar to the step response shown in Figure 14. This step response has a rise time of approximately 25 ms and overshoot of less than 50% of the steady state value. Optionally, you can check these time domain specifications by adding a Time Domain Analysis step after the PID Synthesis step.
WARNING: Too much overshoot can causes the output of the controller to command a voltage much higher than the Analog Output board and the motor can handle. However, later on in this example, you will use the Simulation Module to enforce a limit on the valid range of the output.
After you have properly adjusted the P and I gains, save the both the controller and the plant models by using the Save Control Design Model step, located at Control Design»Import-Export Model. Figure 15 shows how this step is used to save the plant model

[+] Enlarge Image
Figure 15. Saving the plant model.
4. Simulating the Closed Loop System
In this example, the previous sections provided information about identifying the plant model and designing a PI controller based on this plant model. Before you use this controller on the actual DC motor, you use the Simulation Module to verify the controller behaves as you expect. The Simulation Module includes several ordinary differential equation (ODE) solvers you use to integrate the continuous transfer function model over a period of time
Figure 16 shows the LabVIEW block diagram, including the Simulation Loop that defines the simulation diagram. Notice the pale yellow color of the simulation diagram to distinguish it from the LabVIEW block diagram. Also notice that the Simulation Module allows you to directly implement feedback, completing the closed-loop system.

[+] Enlarge Image
Figure 16. Using the Simulation Module to simulate the behavior of the identified plant and the PI controller in a closed-loop configuration.
Note: there are several ways to define both the Controller and the plant model. They can be set up manually or read from disk. In this example, we read the models saved from SignalExpress as shown in figure 17

Figure 17. Read model into simulation block.
We will configure the simulation to run at the same speed it would run on the real world so we can better analyze the system performance. To do so, doble-click on the simulation loop and match the parameters as shown in figures 19 and 20.
Figure 18 Configure Simulation Parameters
Figure 19 Configure Simulation Timing
Figure 20 shows the response of the closed-loop system to a square wave input. Refer to Figure 14 to verify that this is the expected behavior.
Figure 20. Simulated Closed Loop Response
Notice the knobs on the front panel of Figure 20. You use these knobs to change the type, amplitude, and frequency of the stimulus signal while immediately viewing the response of the closed-loop system.
5. Driving the Motor with the closed loop system
Now that you have verified the closed-loop response of the plant and controller models, the next step is to use this controller to drive the actual DC motor. First, this example demonstrates an open-loop system.
NOTE: This example does not synchronize the input and output values of the system, because, the short jitter (≤0.5ms with 1000 kS/s analog input and output) ensures that the output does not display any significant difference.
We will leverage the work done on the previous steps to implement a Real-Time controller. To do so, we will use a CompacRIO with the same input/output modules. CompactRIO was chosen as the control platform since it enable us to have better determinism that a windows-based usb-based system such as compactDAQ.

[+] Enlarge Image
Figure 21.CompactRIO System
CompactRIO is setup to use the RIO Scan Engine (RSE) so we can reuse the code used previously. Figure 20 shows the modified code to use real world I/O instead of the simulation plant and figure 21 shows the overall project configuration
Figure 20. Closed Loop Control

Figure 21. Project Configuration
By closing the loop and adding the PI controller to the open-loop system, the response of the motor becomes faster and more accurate with respect to the RPM you specify. The controller compares the actual speed of the motor with the speed you specified and adjusts the motor speed accordingly. Figure 22 shows this increase in response time and accuracy

Figure 22. Driving the plant (DC Motor) in a closed loop configuration. The response from the motor is fast, with overshoot, settling time characteristics as defined while designing the controller (Figure 14).
The integration term in the PI controller minimizes the steady-state error by taking the history of the error into account.
6. Conclusions
This tutorial has shown how you can use LabVIEW and related software to identify, control, and simulate a real-world dynamic system. Although this example did not use any real-time (RT) hardware, you can use the LabVIEW Real-Time Module in conjunction with the Control Design and Simulation Module to deploy a controller to any National Instruments RT Series hardware.
Refer to Using CompactRIO, located at http://sine.ni.com/csol/cds/item/vw/p/id/538/nid/124200, for an example that demonstrates how to build a full-authority FPGA-based engine control system for a high-performance motorcycle engine.
NOTE: You also can describe the simulation itself in the Express Workbench Project Script by adding a User-Defined Step. You also can translate an Express Workbench project script into LabVIEW code by launching LabVIEW and selecting Tools»Express Workbench»Convert Express Workbench Project from the pull-down menu.
More complex systems, such as the high performance motorcycle engine described above, may have multiple inputs and multiple outputs. In these situations, you can use state-space model identification and control design methods to operate in the multiple-input multiple-output (MIMO) environment. The Control Design and Simulation module and the System Identification Toolkit and support these design methods.
Related Links:
Identifying Plant and Designing Controller in Express Workbench
LabVIEW Simulation of Closed Loop DC Motor System
LabVIEW VI Translated from Express Workbench Script
Open and Closed Loop DC Motor Control VI
Reader Comments | Submit a comment »
Very good
Needs improvement: Simulation Module
- Mar 28, 2007
Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).


