Real-time systems are defined as systems with timing constraints that must be met to avoid failure. They are designed to be more reliable than standard software systems, such as those running on Windows, in addition to providing deterministic timing characteristics. For example, the airbag system in your car requires a real-time system to recognize a crash and deploy within a fixed amount of time. If the airbag fails to deploy in time, a driver or passenger could be seriously hurt. Therefore, an airbag system must possess the reliability to guarantee a response to a crash and determinism to guarantee that this response occurs within a fixed amount of time. The most common misunderstanding associated with real-time performance is that it increases the execution speed of your program. However, real time does not necessarily mean “real fast.” Quickly acquiring test data at 1MS/s may not require real-time software support, but controlling an aircraft’s autopilot system does require real-time software to ensure precise updates to the plane’s altitude, direction, and speed, even if these updates only need to occur a few times per second (Figure 1). Some real-time systems are indeed fast, but many are designed specifically to run reliably for very long periods of time, such as those used in environmental tests lasting weeks, months, or years.
Figure 1: An autopilot system requires a real-time closed-loop control system to reliably and deterministically measure and control the plane’s flight.
You can achieve real-time performance using hardware or software, or both. To implement a hardware real-time system, you need an accurate clock driving hardware circuitry. For example, NI data acquisition devices have onboard timing circuitry that regulates the acquisition rate. With these technologies, the PC processor does not participate in data retrieval; therefore, your application can achieve precise I/O timing on any OS. Alternatively, a real-time OS (RTOS) and programming environment can create a real-time software solution. This software solution offers more flexibility and convenient debugging tools than relying on real-time hardware only. With a real-time software solution, you can incorporate real-time decision making into your application with advanced algorithms, such as proportional integral derivative (PID) control, instead of depending on predefined hardware circuitry. Furthermore, hybrid systems combine both real-time hardware and software, so you can achieve the precise timing of hardware-controlled real time combined with the flexibility of software real time.
See Also:
LabWindows/CVI Real-Time Home Page
Consider the difference between a general-purpose OS and a RTOS. General-purpose OSs such as Windows, Mac OS, and Linux are designed to run a variety of applications in parallel, ensuring that all applications receive some processing time. These OSs also must respond to interrupts from peripherals such as keyboards and mice and you have limited control regarding how these tasks are handled and prioritized by the processor. Subsequently, high-priority tasks can be preempted by lower priority tasks, resulting in unbounded jitter, meaning that a particular software task is not guaranteed to finish within a certain time period.
The reliability offered by general-purpose versus real-time OSs also varies greatly. The millions of lines of code required to implement a general-purpose OS, in addition to the large number of parallel tasks and programs running (i.e. automatic updates, virus scans, and user interface updates) makes occasional computer crashes likely. In contrast, RTOSs implement the minimal amount of code and background programs to achieve a high degree of reliability. This is possible because RTOSs focus exclusively on running mission-critical applications, not on peripheral activities such as user interface management, mouse and keyboard interrupts, and login management.
General-purpose OSs, however, are ideal choices for many test and measurement applications such as data acquisition, offline analysis, and data presentation. With technologies such as bus mastering, direct memory access (DMA) transfer, and data buffering, the I/O devices can collect data and automatically transfer it to RAM without involving the CPU and OS. When the application is ready to receive the data, it is retrieved from RAM without interrupting the operation of the hardware. After you have acquired your data, you typically can use a general-purpose OS to perform offline analysis of this data because there usually are not strict time constraints on when the operation must end. Finally, the user-interface focus of these general-purpose OSs makes them ideal for visually representing data results, particularly with the rich 3D graphics available in modern OSs.
In contrast, RTOSs provide the ability to prioritize tasks so that the most critical task can always preempt other tasks when needed. In addition, RTOSs are often used to implement applications requiring extended run times or stand-alone, headless operation because they guarantee uptime. RTOSs are required when the processor is involved in operations such as closed-loop control. These applications need timely decisions to be made based on incoming data to avoid failure. For example, common PID control applications must acquire a single measurement value (i.e. velocity), then perform a PID algorithm based on the measured signal and a user defined set point, and finally output the appropriate response value (i.e. throttle) to the I/O device (Figure 2). In these applications, the software must be involved in the loop; therefore, you need a RTOS to guarantee response within a fixed amount of time. Software jitter in RTOSs is bounded, which means the OS guarantees that a task finishes within a certain amount of time.
Figure 2: A simple PID controller for closed-loop control.
The automotive, industrial, defense and aerospace industries often use real-time systems for both test and control. In the area of test, applications range from life-cycle endurance testing of aircraft components, to destructive test, to autonomous instruments with stand-alone operation in remote areas. In these mission-critical applications, a computer crash is not acceptable because the relevant data may be available only for a few milliseconds during destructive tests or require months of observation during environmental testing. Re-running such tests is potentially expensive or even impossible.
Figure 3: Real-time software solutions are needed for a range of applications, from reliable test, to control, to everything in between.
In the area of control, determinism and reliability are essential. For example, closed-loop control applications, such as a cruise control system, require precise updates to the engine throttle based on the measured speed and the results of a control algorithm such as PID. For automation and industrial control applications, deterministic timing is required to ensure appropriate motion paths and responses during the manufacturing process.
Many other applications require test and control to be tightly integrated, such as operational testing. For example, testing a computer hard drive first requires controlling the operation of the hard drive controller, setting such test parameters as rotation speed and arm position. Only after the appropriate control signals have been sent to the hard drive can testing begin on parameters such as temperature and bit errors. Test and control integration is also required for hardware-in-the-loop (HIL) testing. For example, testing an engine control unit (ECU) first requires simulating real-world stimuli to the ECU, then measuring and validating its response.
When developing real-time systems, however, there are various challenges to overcome. Programming embedded systems require expertise and knowledge of specialized tool chains, programming techniques, and hardware/software integration. This constitutes a steep learning curve for engineers that need real-time performance but are not experienced real-time developers. Additionally, while there are a growing number of products available for real-time use, there is still much integration and programming left for developers to make the software and hardware work together seamlessly.
Another obstacle of real-time development occurs when working with applications that require both test and deterministic control. Using disjoint test and control tools requires additional domain expertise and further integration work to synchronize these separate application pieces.
Fortunately, LabWindows/CVI Real-Time provides an ideal platform that makes real-time programming, hardware integration, and combining test and control easier. LabWindows/CVI also has a long history of reliability that begins with version A0 in 1987. Since then, LabWindows/CVI has continued to add the latest programming technologies such as ActiveX and .NET while focusing on stability and backward compatibility. LabWindows/CVI includes built-in I/O libraries, advanced analysis libraries, and a complete suite of scientific user interface controls, making it the ideal platform for test and control applications. Because LabWindows/CVI is based on open ANSI C standards, you can easily create new applications as well as port existing code to real-time hardware targets with minimal modifications, while continuing to use the familiar LabWindows/CVI integrated development environment. This ability to incorporate existing code drastically reduces development time for real-time applications through code reuse.
Figure 4: LabWindows/CVI provides an integrated development environment, ideal for creating applications that combine software and hardware.
Also, because LabWindows/CVI Real-Time is tightly integrated with National Instruments hardware, developing applications for a real-time hardware targets is as simple as developing applications for Windows targets. Using existing National Instruments drivers such as NI-DAQmx and NI-VISA, you can access thousands of data acquisition devices and instruments without spending time creating your own real-time target drivers or worrying about low-level, register-level programming.
As previously discussed, combining test and control functionality in the same system can be difficult. Yet, with expertise in test and control for nearly 30 years, National Instruments provides a real-time platform that includes tightly coupled software and hardware that helps you develop test and control components using a single development environment. With NI real-time solutions, you can combine the determinism and reliability of real-time software with the high-accuracy measurements of instrument-grade PXI and PCI devices.
A typical real-time system includes a development machine, called the host computer, and a deployment machine, called the real-time target. Generally, you develop your application with LabWindows/CVI on the host computer running a general-purpose OS such as Windows, download it to the real-time target over Ethernet, and execute the application on the real-time target (Figure 5).
Figure 5: Use LabWindows/CVI Real-Time to develop, download, and deploy real-time systems.
LabWindows/CVI Real-Time currently supports two real-time targets – PXI (PCI eXtensions for Instrumentation) and PCs. PXI is a rugged PC-based platform for measurement and automation systems. PXI combines PCI electrical-bus features with the rugged, modular, Eurocard packaging of CompactPCI, and then adds specialized synchronization buses. PXI is both a high-performance and low-cost deployment platform for measurement and automation systems. A typical system consists of a chassis, embedded controller, and your choice of I/O modules. The controller performs the same function as a desktop CPU, but in a rugged, industrial form factor. When used as a real-time system, the LabWindows/CVI application is downloaded to the embedded processor on the PXI controller. As the application runs, it accesses data from the I/O modules in the system. When you are ready for deployment, you can disconnect the development machine and run you system headless, that is, without a monitor, keyboard, or mouse.
Figure 6: PXI systems are available in 4, 8, and 18 slot options.
With LabWindows/CVI Real-Time, you can also target standard desktop PCs. With this option, you can use existing PC hardware to create reliable and deterministic applications. With this solution, you can take advantage of the latest PC desktop technology, including PCI Express and Pentium 4 processors to achieve real-time performance on a variety of PCI hardware.
Figure 7: Turn standard PCs or single-board computers in LabWindows/CVI Real-Time targets.
In order to truly take advantage of real-time support, you will need to add I/O to your system. LabWindows/CVI supports a variety of National Instruments I/O, including data acquisition devices, serial devices, digitizers, function generators, high-speed digital devices, DMMs, switches, and CAN controllers. Communication to these devices is enabled with full-functional device drivers, specifically NI-DAQmx, NI-VISA, NI-CAN, NI-DMM, NI-Scope, NI-HSDIO, and NI-Switch.
Figure 8: A variety of National Instruments I/O options are available with LabWindows/CVI Real-Time.
With the introduction of the LabWindows/CVI Real-Time module, you can use the features of LabWindows/CVI with many new real-time features including tight software and hardware integration, RTmain code generation, direct deployment to real-time targets over Ethernet, real-time threading libraries, File Copy Utility, remote debugging, Measurement & Automation Explorer (MAX) configurations, and the PID Control Toolkit.
National Instruments provides a tightly integrated real-time platform that offers commercial off-the-shelf (COTS) software and hardware components that seamlessly work together to create complete solutions. Each real-time hardware target uses standard components such as a microprocessor, volatile and nonvolatile memory, an I/O bus interface, and an RTOS. The embedded software consists of a RTOS, driver software and a specialized version of the LabWindows/CVI run-time engine. Because all LabWindows/CVI Real-Time deployment platforms are based on this common hardware and software architecture, integration is easy between the two components.
Figure 9: National Instruments provides a complete COTS software and hardware platform for real-time.
In addition to the integrated NI-DAQmx Library discussed previously, LabWindows/CVI provides DAQ Assistant, an interactive interface to the data acquisition driver framework. DAQ Assistant interactively defines a measurement task, determines the measurement capabilities of the DAQ device you specify, and generates C code modules that perform the acquisition. The tight integration of DAQ Assistant and NI-DAQmx with LabWindows/CVI gives engineers who perform data acquisition the most efficient, productive way to take measurements in an ANSI C environment.
Figure 10: Creating Data Acquisition Task Using DAQ Assistant
LabWindows/CVI is an industry leader in instrument control and connectivity, along with NI LabVIEW software, through an Instrument Driver Network of more than 4,000 instrument drivers from more than 200 vendors. You can use these drivers to easily program instrument control applications. LabWindows/CVI takes instrument control to the next level of productivity with Instrument I/O Assistant. With Instrument I/O Assistant, you can generate code to communicate with devices such as serial, Ethernet, and GPIB instruments without using an instrument driver.
Instrument I/O Assistant offers a simple interface for quickly prototyping applications and autoparsing instrument data without any programming. You can easily import the code generated into any existing application, which removes the tedium of writing instrument connectivity, basic communication, and string parsing code.
Use RTmain code generation to automatically create a code template for your real-time applications. The template provides convenient starting points to add initialization and cleanup code. The RTmain function is automatically loaded and executed upon deployment to a real-time hardware target. You can insert the RTMain function to your application from the Edit » Insert Construct » RTmain menu item.
Figure 11: Use the Insert Construct menu item to automatically create RTmain initialization code and a template to begin writing your code.
You can directly deploy your application to your real-time hardware target over Ethernet using the LabWindows/CVI Real-Time Select Target with Options window. With this option, you can specify the target by machine name or IP address without ever leaving the LabWindows/CVI development environment. If you are unsure of the available targets or need to change hardware configurations, you can also launch Measurement and Automation Explorer (MAX) to view all available targets on the network subnet. After you press the run button, LabWindows/CVI automatically builds your real-time application and copies it the real-time target over Ethernet.
Figure 12: You can target and deploy real-time directly from LabWindows/CVI.
One important aspect of a real-time system is the ability to control thread priorities so higher-priority tasks are not interrupted by lower-priority tasks on the system. With the ability to set thread priority in LabWindows/CVI Real-Time, you have control over the execution of tasks in your application. There are seven different thread priorities exposed by the LabWindows/CVI threading API, which map to three different levels – high, normal, and low. In order to simplify threading, LabWindows/CVI also includes thread pool functions to simplify creating, transferring, and disposing threads (Figure 13).
LabWindows/CVI also includes thread safe queues to safely pass data between different threads, thus preventing race conditions. A thread safe queue is commonly used in PID control applications to pass data between time-critical PID loop and the low-priority communication loop.
Figure 13: Set the thread priorities to ensure that your time-critical tasks are not preempted by lower priority tasks.
Once you create real-time applications, LabWindows/CVI automatically downloads your application and any statically linked DLLs to the target. However, if you wish to manually download other files such as configuration files or dynamically called DLLs, you can use the File Copy utility. This utility also allows you to specify which DLLs should run at system startup.
Figure 14: Use the LabWindows/CVI Real-Time File Copy utility to copy files to the hardware target.
Once you have developed a real-time application, you may want to do debug it while it is executing on the real-time target with actually I/O. This task is typically not trivial. With LabWindows/CVI, you can simply create a debuggable DLL, and then debug the DLL from a local instance of LabWindows/CVI. All of the features available when you are debugging locally, such as breakpoints, step into functions, or watch variable values are fully functional. On the fly, you can even change the values of variables on your real-time target from your local machine. All debugging information is automatically passed over TCP between the real-time application and the local instance of LabWindows/CVI.
Figure 15: Remotely debug your real-time application over Ethernet.
Locating and configuring your real-time hardware target with the appropriate software and drivers is easy using MAX. MAX automatically finds any supported targets on your local subnet, or you can specify an IP address or network name. From MAX, you can download the LabWindows/CVI Real-Time runtime engine and hardware drivers such as NI-DAQmx to the target. You can also interactively configure the hardware on the target, including defining data acquisition tasks, terminal configurations, and even running test panels to remotely to view live data.
The PID Control Toolkit, included with LabWindows/CVI Real-Time, enables you to create sophisticated closed-loop control applications. The toolkit includes functions for PID control, external reset feedback and error-squared PID algorithms.
Figure 16: Add sophisticated PID algorithms to your control applications.
Once you have determined that your application needs real-time reliability and control, LabWindows/CVI Real-Time makes it easy to develop and deploy your application. With features such as direct deployment, thread prioritization, and tightly integrated hardware, development of a real-time system is as simple as developing for a nonreal-time system.
Related Links:
LabWindows/CVI Real-Time Home Page