为复杂的机械设备构建实时软件的完全指南
机械系统的性能日益成为其控制软件的功能,因此,在系统设计和实现的每一个阶段,都必须考虑控制软件的计算能力及其所受到的限制。本书全面阐述了如何为今天日益复杂的机械设备构建实时控制软件。
本书介绍了实时软件开发的每一个步骤:性能说明书、设计文档、模拟、实验室和生产原型设计、生产系统的开发与维护等;讨论了任何一种机电环境下,如何最大限度地保持实时软件的可靠性和一致性。本书涵盖以下主题:
·为机电系统构建实时软件所面临的挑战
·如何有效实现任务内及任务间通信
·状态转换逻辑计时、任务调度、多任务以及基于中断的调试
·基于图形和字符的操作界面
·直接实现系统控制软件,包括MATLAB模拟
·分布式控制:多处理器体系结构、TCP/IP与UDP、应用层编程
·详细的案例分析同时采用Java和C++语言
本书中的详细实例和案例分析同时采用Java和C++语言,所涉及的应用领域非常广泛,如皮带传动、炉温控制以及成型加工等。
1 MECHATRONICS
1.1 A History of Increasing Complexity
1.2 Mechatronic System Organization
1.3 Amplifiers and Isolation
1.4 Scope: The Unit Machine
1.5 Control
1.6 Real-Time Software
1.7 Nasty Software Properties
1.8 Engineering Design and Computational Performance
1.9 Control System Organization
1.10 Software Portability
1.11 Operator Interface
1.12 Multicomputer Systems: Communication
1.13 The Design and Implementation Process
2 TASKS
2.1 Example: Task Selection in a Process System
2.2 Tasks and the Control Hierarchy
2.3 Task Structure Examples
2.4 Simulation
2.5 More Task Structure Examples
3 STATE TRANSITION LOGIC
3.1 States and Transitions
3.2 Transition Logic Diagrams
3.3 Tabular Form for Transition Logic
3.4 Example: Pulse-Width Modulation (PWM)
3.5 Transition Logic for the Process Control Example
3.6 Nonblocking State Code
3.7 State-Related Code
3.8 State Scanning: The Execution Cycle
3.9 Task Concurrency: Universal Real-Time Solution
4 DIRECT REALIZATION OF SYSTEM CONTROL SOFTWARE
4.1 Language
4.2 Time
4.3 Program Format
4.4 Simulation
4.5 Simulation in Matlab
4.6 Intertask Communication
4.7 Real-Time Realization
4.8 Real-Time Realization with Matlab
5 SOFTWARE REALIZATION IN C++
5.1 Simulation in C++
5.2 Templates for Simulation in C++ (group-priority)
5.3 PWM Simulation Using C++ (group-priority)
5.4 Simulation in C++ (with TranRun4)
5.5 Real-Time Realization with C++
6 INTERTASK COMMUNICATION
6.1 Communication Within a Process
6.2 Communication Across Processes
7 TIMING TECHNIQUES ON PC COMPATIBLES
7.1 Calibrated Time
7.2 Free-Running Timer
7.3 Interrupt-Based Timing
8 MULTITASKING: PERFORMANCE IN THE REAL WORLD
8.1 Priority-Based Scheduling--Resource Shifting
8.2 Matlab Template for Minimum-Latency Dispatcher
8.3 Cooperative Multitasking Using C++
8.4 Preemptive Multitasking Modes
8.5 Realization of Interrupt-Based Dispatching
9 A CHARACTER-BASED OPERATOR INTERFACE
9.1 Operator Interface Requirements
9.2 Context Sensitive Interfaces
9.3 User Interface Programming Paradigms
9.4 Mechatronics System Operator Interface
9.5 Operator Interface Programming
10 GRAPHICAL OPERATOR INTERFACES
10.1 Graphical Environments
10.2 The Times-2 Problem
10.3 Screen Change
10.4 Heat Exchanger Control in Bridgeview
10.5 Interprocess Communication: DDE
10.6 Putting It All Together
11 DISTRIBUTED CONTROL I: NET BASICS
11.1 Multiprocessor Architectures
11.2 TCP/IP Networking
11.3 Implementation of UDP
11.4 The Application Layer
12 DISTRIBUTED CONTROL II: A MECHATRONICS CONTROL
APPLICATION LAYER
12.1 Control System Application Protocol
12.2 Startup of Distributed Control Systems
12.3 Testing the Application Protocol
12.4 Using the Control Application Protocol
12.5 Compiling
13 JAVA FOR CONTROL SYSTEM SOFTWARE
13.1 The Java Language and API
13.2 Preconditions for Real-Time Programming in Java
13.3 Advantages of Java for Control Software Design
13.4 Java and the Task/State Design Method
13.5 The Current State of Real-Time Java
14 PROGRAMMABLE LOGIC CONTROLLERS (PLCs)
14.1 Introduction
14.2 Goals
14.3 PLC Programming
14.4 The Task/State Model
14.5 State Transition Logic for a PLC
14.6 PLC Multitasking
14.7 Modular Design
14.8 Example: Model Railroad Control
14.9 Simulation - Portability
15 ILLUSTRATIVE EXAMPLE: ASSEMBLY SYSTEM
15.1 The Assembly System
15.2 System Simulation
15.3 Development Sequence
15.4 Belt Motion Simulation (Glue00)
15.5 Oven Temperature Simulation (Glue01)
15.6 PID Control of Belt Position and Oven Temperature (Glue02)
15.7 Better Control of Motion (Glue03)
15.8 A Command Structure for Profiled Motion (Glue04)
15.9 Clamps (Glue05)
15.10 Robots (Glue06)
15.11 Cure/Unload (Glue07)
15.12 Making Widgets (Glue08)
16 THE GLUING CELL EXERCISE IN TRANRUN4
16.1 The Gluing System
16.2 Simulation and Prototyping
16.3 The Project Components
16.4 Glue00: Conveyor Simulation
16.5 Glue01: An Oven Simulation
16.6 Glue02: PID Control
16.7 Glue03: The Operator Interface
16.8 Glue04: Motion Profiling
16.9 Glue05: Belt Sequencing
16.10 Glue06: The Glue Application Machine
16.11 Glue07: Transport Task Supervision
16.12 Glue08: The Completed Assembly System
17 THE GLUING CELL EXERCISE IN TRANRUNJ
17.1 Getting Started
17.2 Writing Custom Tasks and States
17.3 Implementing State Transition Logic
17.4 Global Data and Intertask Messaging
17.5 Continuous vs. Intermittent Tasks
17.6 Scheduler Internals
17.7 Execution Profiling
17.8 Intertask Messaging Across Different Processes
17.9 Tips And Tricks
17.10 Additional Information
BIBLIOGRAPHY
INDEX
The control of complex mechanical systems often falls between the cracks of engineering curricula, but the topic occupies an extremely important place in the world of industrial control. Most courses and professional reference material cover the details of embedded control of very small systems using microcontrollers, as well as details of electronics and control theory. In contrast, this book addresses issues associated with the design of control software for mechanical systems consisting of significant numbers of sensors and actuators - systems whose activities must be coordinated. These systems often include a computer-based operator interface and internal as well as external network connections.
The term "mechanical system" in the context used here refers to a system in which real physical power must be delivered to a target object. The power could be in a form such as motion, heat, force, pressure, or many others, so the range of applicability is very large. The domain of complexity encompasses what we call a "unit machine," a mechanical system in which all parts either exchange physical power directly or exchange material with little or no buffering. This definition makes a distinction between the control of a specific unit machine or process on the one hand, and designing control software for work cells, entire process plants, or sections of a factory on the other.
The material we present was developed for teaching both undergraduate and graduate courses to classes consisting mostly of mechanical engineering students. Mechanical engineering students are often not experienced in computer programming and therefore have to learn an appropriate programming language (more on that in a moment), learn the design methodology, and develop the ability to apply both in a series of lab exercises and projects. While a 15 week semester makes for a somewhat compressed timetable to do all of this, the students seem to emerge with a good understanding of how the pieces fit together. It is not unusual for many students to progress directly to successful work in industrial applications based mostly on the exposure in this course. The material is usable in other configurations as well, including self study, multi-semester/quarter format with more emphasis on design or capstone projects, and so on.
The presentation in this text is based on a philosophy in which the control engineering insight is embedded in a design layer rather than in computer code. Thus, issues of portability, design review, and internal communication can be stressed. The generation of functioning computer code is a separate process where considerations of real time constraints, costs of computing hardware and software, and ease of maintenance can be considered. Maintaining this separation is crucial to the idea that production of control software for mechanical systems must be a predictable engineering process.
The methodology we use for design specification is based on finite state machines and semi-independent tasks. It has proved to be a methodology capable of handling the level of complexity needed for these systems. It has some common elements with more formal methodologies such as the universal modeling language (UML) but is considerably simpler. The choice of methodology is based on its ability to describe control behavior in a way that is easily explainable to a broad audience, as well as the complementary property of easy hand translation for computer implementation in almost any language or environment. Software portability to achieve maximum protection to software investment is emphasized throughout.
Choosing computer languages provokes as much vehement discussion as religion or politics! To neutralize some of that partisanship, we have kept the design layer as primary, with the actual software implementation kept as fluid as possible. Nonetheless, it is necessary to choose some language in which to implement actual control systems. While C is probably the most common language in use today, the structures of C++ and Java provide us with more assistance in building a reusable software infrastructure that makes the design model as obvious as possible. We have therefore used C++ and Java for most of the actual control implementation and for the example programs used throughout this text. Java has the advantage of greater portability and is a cleaner language than C++ because it does not need backward compatibility with C. Its syntax includes graphic user interface (GUI) constructs and TCP/IP networking, for example, which are not included in the C++ syntax and are thus not portable for C++ applications. Java's class files are executable on any platform supporting Java, so cross-development is greatly simplified. On the other hand, Java is considerably slower by virtue of its use of a virtual machine for execution; and features such as garbage collection are tricky to deal with in a high speed, real time environment.
The basic programming model, however, is easily adapted for other programming languages. Sample software for simulation using Matlab is given in the book and ad hoc implementations in C or other purely algorithmic languages are easily constructed.
We have three main software packages available to support development, two in C++ and one in Java. All of these support the basic task/state design model, and all can operate in a variety of environments to support simulation, prototyping, and even production versions of software. The two C++ packages differ in that one uses a much simpler scheduling module, so more of the decision-making about when tasks should execute is left to the programmer. The other C++ package, and the Java package, support a richer scheduling module. The simpler C++ package and
the Java package both support full TCP/IP networking in a manner that allows tasks to be distributed over multiple computers through very simple configuration changes, with no other changes needed in the control software.
The Windows NT family of operating systems (NT, 2000, and XP) have been used for a number of years as the main development environment. C++ and Java compilers are readily available as are cross-compilers for many target environments. They have also been used as real time execution environments for early prototyping and debugging. However, the timing in any of the Windows environments is not consistent to the sub-millisecond level needed for much mechanical system control, so other operating systems must be used for higher quality implementation (although it is surprising how much can actually be accomplished without leaving Windows). In the past several years we have used DOS, Windows NT modified with RTX (from VenturCom), and QNX as real time platforms.1 We are currently working with Java and using QNX as the real time platform, since neither DOS nor NT/RTX supports real-time Java effectively.
The operator interface is a critical part of many commercial control systems. Not only does the interface contribute to efficient use of the target system, but it often affects safety in critical ways. While a full discussion of human factors and other disciplines affecting operator interface design is beyond the scope of this book, we do discuss several means of constructing computer-based operator interfaces. The book shows samples based on using Bridgeview (an industrial relative of Labview, from National Instruments) and Visual Basic. These and other simplified GUI construction methods are important from an efficiency point of view in that they can often be used by control engineers to construct prototype operator interfaces without having to devote inordinate amounts of time to the process. The construction of GUIs in Java is not specifically discussed in the book, but available sample Java code demonstrates the use of Java's Swing components in rapid GUI development.
A detailed case study is provided to illustrate the use of the design and implementation methodology on a problem with reasonable complexity. The implementation is entirely a simulation, so it can be run anywhere Java or C++ can be installed - and thus it makes a good vehicle for use by a class or as a self-study example. Implementations are given for all three of the software infrastructures we have developed.