ni tutorial 14138 en
DESCRIPTION
Lab View tutorialsTRANSCRIPT
1/2 www.ni.com
1.
2.
3.
4.
5.
6.
7.
Real-Time Control on CompactRIO Sample Project DocumentationPublish Date: Aug 21, 2012
OverviewThe Real-Time Control on CompactRIO (RIO Scan Interface) sample project implements deterministic, software-based control of a plant. This sample project uses the RIO Scan Interface (RSI),which is an alternative to programming with the LabVIEW FPGA Module, to perform I/O on the FPGA. The RSI programming mode is available on most CompactRIO and Single-Board RIO devicesand is sufficient for applications that require single-point access to I/O at rates of a few hundred Hertz.
Table of ContentsDeveloper Walkthrough
Features
Basis
System Requirements
Overview
Running this Sample Project
Modifying this Sample Project
1. Developer WalkthroughSee a of the RIO sample projects.developer walkthrough
2. FeaturesDeterministic, software-based control—The real-time controller executes parallel control algorithms that run at different rates.
RIO Scan Interface—The RIO Scan Interface provides single-point updates to I/O variables at rates up to a few hundred Hertz without requiring FPGA programming.
User interface—The user interface VI interacts with the CompactRIO device and displays data. This VI can disconnect from the device and reconnect at any time without affecting the controlloop.
Error handling—The application reports and logs all errors from the CompactRIO device, shutting down on any critical error.
3. BasisThis sample project is based on the and templates. Refer to the Simple State Machine and Queued Message Handler templates and theirSimple State Machine Queued Message Handlerdocumentation, available from the dialog box, for information about how these templates work.Create Project
4. System Requirements
Development SystemLabVIEW Full or Professional Development System
LabVIEW Real-Time Module
NI-RIO device driver software
NI CompactRIO Device in Scan Interface ModeThis sample project is designed for an NI cRIO-9074 with the following components:
Software:LabVIEW Real-Time
Network Streams
Network Variable Engine
NI System Configuration
NI-RIO
NI-Watchdog
NI-RIO IO Scan
I/O modules:Analog input module. This sample project is designed for an NI 9205 in slot 1.
Analog output module. This sample project is designed for an NI 9263 in slot 2.
Thermocouple input module. This sample project is designed for an NI 9213 in slot 3.
Sinking/sourcing digital input module. This sample project is designed for an NI 9422 in slot 4.
Solid-state relay sinking/sourcing digital output module. This sample project is designed for an NI 9485 in slot 5.
5. OverviewThis sample project consists of nine parallel loops across two execution targets. The following loops run in parallel on the desktop computer:
Handling events from the user interface (UI Main.vi - Event Handling Loop)—Produces messages to the UI Message Loop based on front panel events.
Handling messages from the user interface and other loops on the desktop computer (UI Main.vi - UI Message Loop)
Displaying messages and data from the CompactRIO device (UI Main.vi - Monitoring Loop)—Displays the latest values of information acquired from RT Loop - System Health and Monitoring.vi.
The following loops run in parallel on the real-time controller:
Controlling the plant (RT Loop - RSI Control.vi)—Reads from the NI 9205 inputs, applies a control algorithm to each channel, and writes to the NI 9263 outputs. The control algorithm usessetpoint data and PID gains sent from the user interface.
Monitoring temperature and stopping the control loop (RT Loop - RSI Low Speed.vi)—Reads temperature data from the NI 9213 and a DI line from the NI 9422 and determines whether to stopthe control loop and write to DO lines on the NI 9485.
Handling commands from the user interface (RT Loop - UI Commands.vi)—Reads commands that are sent from UI Main.vi on the development computer and produces the appropriatemessages.
Handling messages from all loops on the real-time controller (RT Main.vi - Message Handling Loop)—Consumes messages from all loops that run on the real-time controller.
Ensuring the RT controller remains responsive (RT Loop - Watchdog.vi)—Pets the watchdog, ensuring the RT controller remains responsive.
Monitoring diagnostic information from the real-time controller (RT Loop - System Health and Monitoring.vi)—Monitors CPU and memory usage of the real-time controller and information about
2/2 www.ni.com
1.
2.
3.
4.
5.
6.
7.
1.
2.
3.
4.
5.
6.
7.
8.
Monitoring diagnostic information from the real-time controller (RT Loop - System Health and Monitoring.vi)—Monitors CPU and memory usage of the real-time controller and information aboutthe RSI. This information is written to network-published shared variables and appears on the and tabs of UI Main.vi.Data Monitoring System Monitoring
No LabVIEW code runs on the FPGA. Instead, the RSI runs on the FPGA, scans the C Series modules for input and output changes, and passes updated values to the NI Scan Engine. The NI ScanEngine, which is running on the real-time controller, updates the I/O variables with data from the RSI. This update provides single-point data from C Series I/O to both the real-time VI and the userinterface.
6. Running this Sample ProjectAdapt the sample project to your hardware.
In the window, run . This VI begins acquiring data and executing the control loop.Project Explorer RT CompactRIO Target»RT Main.vi
Open and run .My Computer»UI Main.vi
Enter the IP address of the CompactRIO chassis in the text box and click .Controller Address Connect
After you are connected, click to start the control loop.Run Control
Adjust the channel values on the page and view the outputs on the page. Until you define a control algorithm, all will read 0.Control Settings Data Monitoring Control Output Values
Click to exit the application.Exit
7. Modifying this Sample Project
Adapting this Sample Project to Your HardwareThe following steps refer to NI CompactRIO devices, but you also can adapt this sample project to an NI Single-Board RIO device that supports the RIO Scan Interface.
Ensure all devices are configured and connected to the same network as the development computer.
In the window, add or discover your RT CompactRIO target to the top-level project item.Project Explorer
Add or discover your CompactRIO chassis to the RT Compact RIO target you added in the previous step. Ensure the chassis is set to Scan Interface mode.
Add or discover your C Series input module to the CompactRIO chassis you added in the previous step.
Drag the following project items from the default RT CompactRIO target to the one you added in step 2:Error Handlers folder
Globals folder
Support VIs folder
RT Loops folder
Type Definitions folder
Deterministic Loop Variables.lvlib
Shared Variables.lvlib
RT Main.vi
Delete the default RT CompactRIO Target project item that no longer has any VIs associated with it.
Open RT Loop - RSI Control.vi and replace the Shared Variable Nodes with ones that represent the I/O channels you want to use. For example, to use Mod5/AI2, drag this input channel fromthe window to the block diagram. The actual channels you read from and write to depend on your application.Project Explorer
Open RT Loop - RSI Low Speed.vi and replace the Shared Variable Nodes with ones that represent the I/O channels you want to use.
Defining a Control AlgorithmLocate the Control (PID) subdiagram of the Case structure in RT Loop - RSI Control.vi and modify this subdiagram to apply a control algorithm. For example, you can use the PID VI that is includedwith the NI LabVIEW PID & Fuzzy Logic Toolkit. By default, this algorithm returns a constant value of 0 on all output channels. You can perform a different algorithm on each individual channel.
Although this sample project is designed to implement a PID algorithm, you can modify the sample project to use any algorithm.
Defining Safe Values for Hardware Connected to the C Series ModulesModify the Safe State, Default subdiagram of the Case structure in RT Loop - RSI Control.vi to write safe values to output channels. The values you write here should be ones that you know theconnected hardware can safely handle. By default, this subdiagram writes a value of 0 to all output channels.
Configuring Sample Project SettingsIn the window, open and configure the sample project settings.Project Explorer My Computer»Globals»Global - Configuration Options.vi
Copyright
© 2012 National Instruments. All rights reserved.
For copyright notices, conditions, and disclaimers, including information regarding certain third-party components used in LabVIEW, refer to the topic of the .Copyright LabVIEW Help
Trademarks
LabVIEW, National Instruments, NI, , LabVIEW, the National Instruments corporate logo, and the Eagle logo are trademarks of National Instruments Corporation. Refer to the ni.com Trademark at for other National Instruments trademarks.Information ni.com/trademarks
Patents
For patents covering the National Instruments products/technology, refer to the appropriate location: in your software, the file on your media, or the National InstrumentsHelp»Patents patents.txtPatent Notice at .ni.com/patents