Overview
The heart of most machine control applications is a controller such as a programmable automation controller (PAC) or programmable logic controller (PLC). The controller is used to receive sensor data and to control the machine using analog and digital I/O signals. Traditionally PLCs have been used in machine control and programmed using tools such as ladder logic or sequential function charts. Increasingly machine control is moving to PACs because they offer higher performance and more functionality, allowing for operations such as high-speed data acquisition and processing, as well as motion control and vision which are not supported in traditional PLCs. In order to take advantage of all the features and capabilities of a PAC, the application code must be well designed, balancing and coordinating various controller processes such as I/O, process control logic, communication to a HMI and other tasks. This document provides an overview to the architecture for a machine controller running on a CompactRIO PAC using LabVIEW Real-Time as the development tool. Most of this information is equally applicable to other LabVIEW Real-Time based PACs such as Compact FieldPoint and PXI. The controller architecture described in this document is a subsystem of the larger Machine Control Reference Architecture described in other Developer Zone Articles.
Table of Contents
Introduction
The controller is one of two subsystems in a machine control application, the other being the HMI. The purpose of the HMI is to display machine status information and to accept machine control inputs from the operator. Additional tasks associated with the HMI in the Machine Control Reference Architecture are alarm and event detection and logging. The controller’s responsibilities include communication and interfacing to the machine and sensors, control of the current machine state and process, and communication with the HMI. Both systems are built around a tag engine which stores current data and handles communication to other systems and the machine.

Figure 1: High-level view of the local machine control architecture
Analyzing the operations of the controller we can break down the system into smaller components, each responsible for a specific task in the overall application. The following diagram shows the controller architecture and individual components of the machine control application. Some of these components are available ready-to-run as part of the machine control reference architecture, while others must be developed as part of designing and implementing a specific machine control application.

Figure 2: Controller architecture and components
Controller Operations
The core operations of a machine controller include I/O scans and process control. After an initialization phase, the controller will continuously read inputs, calculate control parameters for the machine process using application-specific logic based on the input data, and then update outputs to the machine. If the controller is turned off, some shutdown process may be completed.

Figure 3: Basic Controller Operations
To simplify the I/O process and access to data from different process control systems, a central data storage is commonly used that contains the current value of all tags or variables used in the application. This tag table is sometimes called a real-time database as it provides current instead of historical data. The following diagram looks at the basic controller in a more component/operations hybrid view. It adds a block for HMI communication so that data stored in the tag table on the controller can be accessed and viewed on the HMI. It also allows for multiple parallel control processes. Individual components such as I/O Scan Engine, HMI communication and process control blocks run in parallel in a multi-threaded environment. If necessary synchronization between components can be added, though for most applications this is not required if the I/O scan frequency is faster than the required control rate (loop rate of the process control blocks).

Figure 4: Controller components and operations
In the following section we will look in more detail at the individual components and operations of the controller and how they map to the elements of the machine control reference architecture. For more advanced information and installers for the individual components look in Developer Zone for their individual documents.
Tag Engine
The tag engine is the core controller subsystem. It combines the functionality of the tag table, I/O scan engine, and HMI communication components in the previous diagram. These operations in combination provide the data to the controller process logic, automating communication with the machine and HMI. As these operations are common to most machine control applications, the specific operations of these components are typically configured for an application rather than requiring custom programming from the application developer.
Current Value Table (CVT)
The Current Value Table (CVT) reference library is used to implement the tag table in the controller. It provides a common mechanism for storing data that can be accessed from other system elements. Tags in the Current Value Table are name-based to make the process control logic easy to design and implement, and more readable for maintenance and support. The list of tags stored in the Current Value Table is configured using the Tag Configuration Editor (TCE), an intuitive configuration tool.
The CVT is directly accessed by the cRIO I/O Engine (CIE)and CVT Client Communication (CCC) reference libraries to automate communication with the machine and HMI respectively.
I/O Scan Engine - cRIO I/O Engine
In the current implementation, the I/O scan engine is provided by the cRIO I/O Engine (CIE). This reference library is used to exchange data between the NI CompactRIO Scan Engine and the Current Value Table. Channels to be used by the cRIO I/O Engine can be configured for a specific application using the Tag Configuration Editor, which is also used to configure the CVT. The FPGA can be customized with additional code to support other I/O operations in parallel to the Scan Engine and cRIO I/O Engine.
HMI Communication - CVT Communication Client
During the controller operation, sensor readings, machine control parameters, and other intermediate values are placed in the CVT by the I/O engine and process control blocks for use by other sub-systems. All of this data is available to the HMI for display, logging and event/alarm detection. HMI communication is provided by the CVT Client Communication reference library, which provides a network interface to the local CVT. On the HMI, data read from the controller is placed in another Current Value Table hosted on the HMI. The mapping of data from the controller CVT to the HMI CVT is configured using the Tag Configuration Editor.
Machine Process Control
Once the framework to handle data and I/O in the controller is in place, developing an application is a matter of configuring the Tag Engine and implementing the process control logic. This portion of the controller is customized for each application as it greatly depends on the individual machine, the processes being automated, etc. The process control blocks interface to the Current Value Table for input and output data and therefore can be developed very quickly and easily without the need to interact directly with physical I/O. Even though this portion of the controller application is very much customized to each individual application, certain common design patters emerge across different application implementations.
State Machine – State Chart
The most common design pattern for process control implementation for machine control is some form of state machine. In a traditional state machine the process control block runs in a defined set of states that correspond to the state of the machine. As conditions change, time elapses or operator commands are received from the HMI, the process control block transitions from one state to another, updating the machine through the output values.
Using the LabVIEW Real-Time development tools you can implement state machines in a number of different ways. The most common methodology is the use of a Case structure inside of a While loop with a shift register to keep track of the state for the next iteration of the state machine. This implementation can be enhanced using a LabVIEW queue or FIFO in place of the shift register, to store multiple states and allow for one state to buffer up a series of subsequent states. Search Developer Zone for more information on building basic state machines in LabVIEW.
A derivative of the buffered state machine is a queued message handler (QMH) in which each entry of the queue or FIFO is considered an event or action and is only processed one time. The processor does not stay in the current state unless the event or action is placed repeatedly into the queue. If no event is present in the queue, no action is performed by the processor. A template of a queued message handler implementation is included in the Asynchronous Message Communication (AMC) reference library.
The LabVIEW State Chart module is an advanced tool for building complex state machines. Using state charts you can easily design parallel and nested state diagrams that can be executed on LabVIEW or LabVIEW Real-Time targets. You can assign LabVIEW code to each transition between states, and also place condition checking (guards) into the states and transitions. This tool can easily handle the implementation of industry standard state diagram such as the OMAC PackML standard for machine control. An implementation of this standard is offered as A State Chart Design Pattern for Machine Control. Additional information on using the LabVIEW State Chart module is available in Developing Applications with the LabVIEW State Chart Module.
High Speed I/O, Control and Processing
One of the biggest benefits of using a PAC is the ability to add other tasks to your application, which could not be handled by a traditional PLC. When using CompactRIO as your controller this may include high-speed data acquisition, motion control, hardware-based closed loop control in the microsecond range and more.
Using CompactRIO and its FPGA technology we have the ability to configure much more advanced functionality on the FPGA and in the LabVIEW real-time application than the cRIO I/O Engine described earlier. In parallel to the Scan Engine and cRIO I/O Engine, you can implement high-speed data acquisition from a different analog input module and stream the data using a DMA channel to a separate task on the controller running in LabVIEW Real-Time. On both the FPGA and the controller this code runs in parallel to the existing architecture and has no effect on the implementation or the configuration of the machine control application. Using high-speed analog data we can add vibration analysis, machine condition monitoring, frequency analysis and more to the machine control application. These additional tasks can reduce or eliminate the need for additional measurement equipment and by integrating these operations with the main machine control application better and more efficient control of the machine can be implemented.
Adding motion control directly to the machine controller allows further integration of different operations which have been traditionally handled by separate applications and equipment. Using the NI SoftMotion tools combined with the C series motion drive and digital I/O modules, high speed closed loop control of servo and stepper motors can be added. The FPGA target allows implementation of the motion controller with the reliability and determinism only offered by a hardware-based solution, while the LabVIEW RT based SoftMotion trajectory generator can create multi dimensional contours and blended moves to satisfy advanced motion control requirements. Like the high-speed DAQ operation, this functionality works in parallel to the fundamental machine control application.
Any additional task such as high-speed acquisition and motion control can interact with the rest of the machine control application using the Current Value Table and thus have access to the same data and information. Other communication paths can be added between these different components and the machine control application using queues, FIFOs, and notifiers. High-speed communication from these tasks back to the HMI can also be implemented in parallel to the CVT Client Communication interface.
Reference Application
A basic implementation of the machine control reference architecture is shown using a simple bioreactor tank control reference application that is available on Developer Zone as part of the architecture components. The tank control reference application integrates all of the components of the machine control reference architecture, so it can be used as a template for building other machine control applications using the architecture. It serves as a guide for developing an application but as with any development, customization of code and enhancements to the provided architecture and tools may be necessary to implement your specific application. Both the architecture and reference libraries should serve as a starting point and guide in development but should not be consider the only possible solution for a particular application.
Where to Go From Here
To learn more about LabVIEW-based machine control, we suggest that you read the following document:
A Reference Architecture for Local Machine Control - This is a reference architecture for building a local machine control system based on an NI Touchpanel Computer (TPC) HMI and a cRIO controller.
The following is a map of other documents that describe the machine control reference architecture. You can click on the image to navigate directly to each document.
Reader Comments | Submit a comment »
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/).
