You are on page 1of 11

Using NI System Identification, Control Design, and Simulation Products for Design

Publish Date: Apr 19, 2010 | 57 Ratings | 3.89 out of 5

Overview
For engineers who need to identify system behavior and design controllers to obtain the best possible closed-loop system characteristics, National Instruments provides software tools and flexible, low-cost hardware solutions based on NI LabVIEW. 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
1. 1. Introduction 2. 2. Identifying the System 3. 3. Controller Design 4. 4. Simulating the Closed-Loop System 5. 5. Driving the Motor with the Closed-Loop System 6. 6. Conclusions 7. Related Resources

1. 1. Introduction
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 is the plant (Figure 1).

Figure 1. In this example, the Quanser Engineering Trainer (QET) is the plant for which you design a closed-loop controller.

Use the Quanser Engineering Trainer (QET) in velocity mode. A voltage signal commands the motor to move and the tachometer output determines the velocity. The motor system is connected to an NI CompactDAQ device, shown in Figure 2, where Analog Input Channel 0 of an NI 9211 analog input module (AI0) is connected to the tachometer, and Analog Output Channel 0 of an NI 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. NI CompactDAQ System

This example uses the following LabVIEW add-ons: LabVIEW System Identification Toolkit 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 set point (the command voltage you specify). The controller then determines the next voltage level to command the motor to meet the specifications defined while designing the controller. Figure 3 shows the final closed-loop system.

1/11

www.ni.com

Figure 3. Final Closed-Loop System (The plant model is the QET as shown in 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 LabVIEW 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. 2. Identifying the System


To identify an open-loop system, you 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, and square waves overlaid with white noise. For this example, the stimulus signal is a 3 V pp triangular wave. You create this signal using the Create Signal step in the LabVIEW SignalExpress environment. Figure 4 shows how this signal was created. And Table 1 shows where to find the settings for this particular step and which values to use.

Figure 4. Creating a 3 Vpp Triangular Wave

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

2/11

www.ni.com

Figure 5. The Created Signal in the Data Viewer in Express Workbench

Next, you must use an NI CompactDAQ device to generate this signal as an analog output. Use the DAQmx Generate step to perform this function, which is shown in Figure 6.

Figure 6. Use the 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 Signal Input/Output -> Generate Signals -> DAQmx Generate

Settings/Actions Config Tab: Device: Make sure to select the 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 NI 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 is 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.

3/11

www.ni.com

Figure 7. Use the DAQmx Acquire step to acquire the response back from the DC motor plant as an analog signal to the DAQ card.

Step Signal Input/Output -> Acquire Signals -> DAQmx Acquire

Settings / Actions Config Tab: Device: Make sure to select device and channel Config Tab: Acq. Timing: 5,000 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 begins as soon as possible, go to 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

Moving back to the Data View, you next need to plot the data acquired. To do so, hit the "add display" button at the top of the Data View 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 5,000 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.

4/11

www.ni.com

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 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 the settings for this step:

Step System Identification -> Model Estimation -> Parametric Estimation

Settings/Actions Input Signals and Model Tab: Stimulus Signal: Calculated signal Response Signal: Device and channel from DAQmx Acquire step

Add display under DAQmx Acquire 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 are typically not in perfect mechanical balance) and the several time steps required for the numerical algorithm identifying the model to initialize itself. For example, the disk that this particular QET DC motor spins has two 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

5/11

www.ni.com

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. Figure 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)

Figure 12. Making the Discrete Model Continuous

To display the step shown in Figure 12, select Control DesignModel TransformationDiscretize Model. On the Configuration page of this step, select Make Continuous from the Operation pull-down list.

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 change slightly. This is due to the spinning wheel and other mechanics of the motor itself (and the tachometer, the fact that AI and AO are not 100 percent synchronized, and so on), as explained above in Estimation of the Parametric Model.

6/11

www.ni.com

Model.

3. 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 completes the closed-loop system. This example designs a simple proportional-integral (PI) controller using the PID Synthesis step, which is shown in Figure 14. Although not shown in this example, the tools to perform a root locus or interactive Bode design are present in the assistant and the LabVIEW palette.

Figure 14. Designing a PI Controller for the DC Motor

Table 5 lists the settings for designing a PI controller.

Step Control Design -> Controller Design -> PID Synthesis

Settings/Actions 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 percent 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 use the LabVIEW Control Design and Simulation Module to enforce a limit on the valid range of the output. After you have properly adjusted the P and I gains, save both the controller and the plant models by using the Save Control Design Model step, located at Control DesignImport-Export Model. Figure 15 shows how this step is used to save the plant model.

Figure 15. Saving the Plant Model

7/11

www.ni.com

4. 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 LabVIEW Control Design and Simulation to verify that the controller behaves as you expect. LabVIEW Control Design and Simulation 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 you can use LabVIEW Control Design and Simulation to directly implement feedback and complete the closed-loop system.

Figure 16. Using LabVIEW Control Design and Simulation 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. You can set them up manually or read from disk. In this example, read the models saved from LabVIEW SignalExpress, as shown in Figure 17.

Figure 17. Read Model into Simulation Block Configure the simulation to run at the same speed it runs in the real world so you can better analyze the system performance. To do so, double-click on the simulation loop and match the parameters, as shown in figures 19 and 20.

Figure 18. Configure Simulation Parameters

8/11

www.ni.com

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. 5. Driving the Motor with the Closed-Loop System


Now that you have verified the closed-loop response of the plant and controller models, 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.5 ms with 1000 kS/s analog input and output) ensures that the output does not display any significant difference. Leverage the same work you did during the previous steps to implement a real-time controller. To do so, use NI CompactRIO hardware with the same input/output modules. CompactRIO was chosen as the control platform because you can achieve better determinism than with a Windows-/USB-based system such as NI CompactDAQ.

9/11

www.ni.com

Figure 21. CompactRIO System CompactRIO is set up to use the RIO Scan Engine so you can reuse code. Figure 22 shows the modified code to use real-world I/O instead of the simulation plant, and Figure 23 shows the overall project configuration.

Figure 22. Closed-Loop Control

Figure 23. 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 24 shows this increase in response time and accuracy.

10/11

www.ni.com

Figure 24. 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, as shown in Figure 14.) The integration term in the PI controller minimizes the steady-state error by taking the history of the error into account.

6. 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 hardware, you can use the LabVIEW Real-Time Module with the LabVIEW Control Design and Simulation Module to deploy a controller to any National Instruments RT Series hardware. Refer to "Using CompactRIO" 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. In addition, you can translate an Express Workbench Project Script into LabVIEW code by launching LabVIEW and selecting ToolsExpress WorkbenchConvert 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 LabVIEW Control Design and Simulation Module and the System Identification Toolkit support these design methods.

7. Related Resources
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

11/11

www.ni.com

You might also like