From Saturday, Nov 23rd 7:00 PM CST - Sunday, Nov 24th 7:45 AM CST, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW Real-Time Control (NI-DAQmx) Sample Project Documentation

Overview

The LabVIEW Real-Time Control (NI-DAQmx) sample project uses NI-DAQmx code to implement deterministic, software-based control of a plant. The control algorithm runs on a real-time controller that reads data from DAQ input channels and writes data to DAQ output channels. You send commands and setpoint changes to the control algorithm from the user interface that runs on a desktop computer. The real-time controller also monitors the status of the application, such as CPU load and memory usage.

Contents

Features

  • Deterministic, software-based control—The real-time controller executes the control algorithm at rates exceeding 1 kHz.
  • User interface—The user interface VI interacts with the real-time controller and displays data from the control loop. This VI can disconnect from the device and reconnect at any time without affecting the control loop.
  • Error handling—The application reports and logs all errors from the real-time controller, shutting down on any critical error.

This sample project is based on the Simple State Machine and Queued Message Handler templates. Refer to the Simple State Machine and Queued Message Handler templates and their documentation, available from the Create Project dialog box, for information about how these templates work.

System Requirements

Development System

  • LabVIEW Full or Professional Development System
  • LabVIEW Real-Time Module
  • NI-DAQmx device driver software

Real-Time Target, such as an NI PXI Chassis with a Real-Time Controller

  • Software:
    • LabVIEW Real-Time
    • Network Streams
    • Network Variable Engine
    • NI System Configuration
    • NI-DAQmx
    • NI-Watchdog
  • Hardware: A DAQ device. This sample project is designed for an NI PXI DAQ device with at least four analog input channels and four analog output channels, such as the NI PXIe-6363.

Overview

This sample project consists of eight parallel loops on 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 the real-time controller (UI Main.vi - UI Message Loop)—Receives and responds to messages from the Event Handling Loop and, using network streams, the RT Message Handling Loop.
  • Displaying messages and data from the real-time controller (UI Main.vi - Monitoring Loop)—Displays the latest values of information acquired from RT Loop - System Health and FPGA Monitoring.vi.

The following loops run in parallel on the real-time controller:

  • Controlling the plant (RT Loop - DAQ Control.vi)—Reads from the DAQ input channels, applies a control algorithm to each channel, and writes to the DAQ output channels. The control algorithm uses setpoint data and PID gains sent from the user interface.
  • Handling commands from the user interface (RT Loop - UI Commands.vi)—Reads commands that are sent from UI Main.vi, using network streams, and produces the appropriate messages.
  • 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 the control algorithm. This information is written to network-published shared variables and appears on the Data Monitoring and System Monitoring tabs of UI Main.vi.

Running This Sample Project

  1. Adapt the sample project to your hardware.
  2. In the Project Explorer window, run RT PXI Target»RT Main.vi. This VI initializes the DAQ device and runs the control algorithm.
  3. Open and run My Computer»UI Main.vi.
  4. Enter the IP address of the RT controller in the Controller Address text box and click Connect.
  5. After you are connected, click either Run Control (on the Control Settings page) or Run Manual (on the Manual Settings page).
  6. Adjust the channel values as necessary and view the outputs on the Data Monitoring page. Until you define a control algorithm, all Control Output Values will read 0.

Modifying This Sample Project

Adapting the Sample Project to Your Hardware

  1. Ensure all devices are configured and connected to the same network as the development computer.
  2. In the Project Explorer window, add or discover your RT target to the to the top-level project item.
  3. Drag the following project items from the default RT target to the one you added in step 2:
    • Error Handlers folder
    • Globals folder
    • RT Loops folder
    • Support VIs folder
    • Type Definitions folder
    • Deterministic Loop Variables.lvlib
    • Shared Variables.lvlib
    • RT Main.vi
  4. Delete the default RT target project item that no longer has any VIs associated with it.
  5. Customize the code in the following places to communicate with your DAQ device:
    • DAQ Close.vi
    • DAQ Initialize.vi
    • DAQ Read.vi
    • DAQ Write Safe Outputs.vi
    • DAQ Write.vi
    • DAQ Tasks.ctl

Defining a Control Algorithm

Locate the Control (PID) subdiagram of the Case structure in RT Loop - DAQ Control.vi and modify this subdiagram to apply a control algorithm. For example, you can use the PID VI that is included with 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 DAQ Device

The Safe Output Value in Global - Configuration Options.vi defines the value that is considered safe for the hardware connected to the output channels of the DAQ device. The Safe State, Default subdiagram of the Case structure in RT Loop - DAQ Control.vi writes this value to all DAQ output channels. By default, this safe state is a value of 0.

Configuring the Application

In the Project Explorer window, open My Computer»Globals»Global - Configuration Options.vi and configure the sample project settings.

Was this information helpful?

Yes

No