Networked Control Systems: Using Matlab/Simulink
Networked Control Systems: Using Matlab/Simulink
Networked Control Systems: Using Matlab/Simulink
Using Matlab\Simulink
Electronics and Communication Engineering
Prashant Khatri(081101)
Lucky Singh(091068)
Raviesha Chopra(091107)
TABLE OF CONTENTS
S.No.
1.
2.
3.
Topics
Abstract
Objective
Chapter1:Networked Control System
1.0 Introduction
1.1Categories of NCS
1.2Components of NCS
1.3 Information acquisition in a
network
1.4 Issues and challenges in NCS
1.5Applications
Chapter2: Matlab\Simulink
2.1 Introduction
2.2 Defining variables and arrays
in Matlab
2.3 Script Files
2.4 Simulink
2.5 Characteristics of Simulink
Chapter3:Network Simulator -2
3.1 Introduction
3.2 Characteristics of NS-2
3.3 Basic Architecture
3.4 Running NS-2
3.5 Including C++ modules into NS-2
and the make utility
3.6 A make descriptor file
3.7 NS-2 Descriptor file
Chapter4:PiccSIM
4.1 Introduction
4.2 PiccSIM Architecture
4.3 PiccSIM Reference
4.4 Known problems and bugs
4.5 Remote User Interface
Chapter5: Work Done
5.1 DC Motor
5.2 Lag Compensator
5.3 PID Controller
Page No.
i
ii
1
2
3
4
5
6
8
8
10
10
11
12
12
12
13
13
14
14
15
15
16
17
17
19
22
24
Result
Future Work
References
26
27
32
33
34
ABSTRACT
A Networked Control System (NCS) is a control system wherein the control loops are
closed through a real-time network. The defining feature of an NCS is that control and
feedback signals are exchanged among the system's components in the form of information
packages through a network. In this project we are going to control a device (dc motor) over
the network using various traditional controllers and then implement our systems on various
networks using NS-2 and improve their performance by improving quality of network.
OBJECTIVE
Networked control systems (NCSs) have been one of the main research focuses in academia
as well as in industry for many decades and have become a multidisciplinary area. When a
traditional feedback control system is closed via a communication channel (such as a
network), which may be shared with other nodes outside the control system, then the control
system is classified as a networked control system (NCS). All definitions found in literature
for an NCS have one key feature in common. This defining feature is that information
(reference input, plant output, control input, etc.) is exchanged among control system
components (sensor, controller, actuator, etc.) using a shared network. Control loops that are
closed over a communication network have become more and more common, with more and
more devices including embedded processors, sensors, and networking hardware. A major
trend in modern industrial and commercial systems is to integrate computing,
communication, and control into different levels of machine/factory operations. The primary
advantages of NCSs are remote data transfers and data exchange among users, reduced
complexity in wiring connections and the costs of media, and ease in maintenance. The
networked control systems operate over the networks. So, there are many challenging issues
which arise in the design process of NCS. The presence of network in networked control
systems can introduce severe problems like delays, jitter, packet losses, etc. on those
networks.
Introduction
A control system is a device or set of devices to manage, command, direct or
regulate the behaviour of other devices or systems. In engineering and mathematics, control
theory deals with the behaviour of dynamical systems.
For many years, researchers have given us precise and optimum control strategies emerging
from classical control theory, starting from open-loop control to sophisticated control
strategies based on genetic algorithms.
The advent of communication networks, however, introduced the concept
of remotely controlling a system, which gave birth to networked control systems (NCS). A
Networked Control System is defined as feedback control system wherein the control
loops are closed through a real-time network. The typical model of NCS is shown in fig. 1.
The defining feature of an NCS is that control and feedback signals are exchanged among
the system's components in the form of information packages through a network.
The functionality of a typical NCS is established by the use of four basic elements:
1. Sensors, to acquire information,
2. Controllers, to provide decision and commands,
3. Actuators, to perform the control commands and
1
1.3.2. Communication
The communication channel being the backbone of the NCS, reliability, security, ease of
use, and availability are the main focus when choosing the communication or data transfer
type. In todays world, plenty of communication modes are available from telephone lines,
cell phone networks, and satellite networks and, most widely used, Internet. Sure enough,
the choice of network depends upon the application to be served.
Internet is the most suitable and inexpensive choice for many applications where the plant
and the controller are far from each other.
actuators for a series of tasks. Different scheduling methods and bandwidth allocation
strategies have been developed for NCS over the past decade. In a wireless network, where
available bandwidth varies due to dynamic user behaviors and external interference sources,
dynamic adaptation of sampling rates is needed to achieve desirable NCS performance and
fully exploit the varying available bandwidth.
1.5. Applications
Networked control applications can be divided into two categories:
(1) Time-critical/time-sensitive applications.
(2) Time-delay-insensitive applications.
In time-delay-sensitive applications, time is critical, i.e., if the delay time exceeds the
specified tolerable time limit, the plant or the device can either be damaged or produce
inferior performance. The performance of the system deteriorates. An example of timedelay-sensitive applications is tele-operation via networks for fire-fighting operations ,
undersea operations, and automated highway driving.
On the other hand, time-delay insensitive applications are tasks or programs that run in real
time but whose deadlines are not critical. Examples of these applications are e-mail, ftp,
DNS, and http.
Most importantly, they connect cyber space to physical space making task execution from a
distance easily accessible (a form of tele-presence). These systems are becoming more
realizable today and have a lot of potential applications namely:
Manufacture automation factories
Electric factories
Advanced aircraft
Network control system (NCS) utilizing high-performance workstations with server/client
technologies are used widely for stable and efficient power system operation.
Energy management Systems (EMS) for generation control and network analysis.
Mobile sensor networks
Remote surgery
Haptics collaboration over the internet
Automated highway systems and unmanned aerial vehicles
Technical
Details
Chapter 2: MATLAB\Simulink
2.1. Introduction
(Matrix Laboratory) is a programming language for technical computing from The Math
Works, Natick, MA (www.mathworks.com). Used for a wide variety of scientific and
engineering calculations, especially for automatic control and signal processing, MATLAB
runs on Windows, Mac and a variety of Unix-based systems. Developed by Cleve Moler in
the late 1970s and based on the original LINPACK and EISPACK FORTRAN libraries, it
was initially used for factoring matrices and solving linear equations. Moler commercialized
the product with two colleagues in 1984. MATLAB is also noted for its extensive graphics
capabilities.
The Matlab environment is an interactive environment:
Single-line commands can be entered and executed, the results displayed and observed,
and then a second command can be executed that interacts with results from the first
command that remain in memory. This means that you can type commands at the Matlab
prompt and get answers immediately, which is very useful for simple problems.
Matlab is an executable program, developed in a high-level language, which interprets
user commands.
Portions of the Matlab program execute in response to the user input, results are displayed,
and the program waits for additional user input.
While this interactive, line-by-line execution of Matlab commands is convenient for simple
computational tasks, a process of preparation and execution of programs called scripts is
employed for more complicated computational tasks:
A script is list of Matlab commands, prepared with a text editor.
Matlab executes a script by reading a command from the script file, executing it, and then
repeating the process on the next command in the script file.
Errors in the syntax of a command are detected when Matlab attempts to execute the
command. A syntax error message is displayed and execution of the script is halted.
When syntax errors are encountered, the user must edit the script file to correct the error
and then direct Matlab to execute the script again.
The script may execute without syntax errors, but produce incorrect results when a logic
error has been made in writing the script, which also requires that the script be edited and
execution re-initiated.
Script preparation and debugging is thus similar to the compilelink/load-execution process required for in the development of programs
in a high-level language.
declaring their type, except if they are to be treated as symbolic objects and that their type
can change. Values can come from constants from computation involving values of other
variables, or from the output of a function. For example:
>> x = 17
x=
17
>> x = 'hat'
x=
hat
>> y = x + 0
y=
104
97
116
>> x = [3*4, pi/2]
x=
12.0000 1.5708
>> y = 3*sin(x)
y=
-1.6097 3.0000
2.2.2. Vectors\Matrices
As suggested by its name (a contraction of "Matrix Laboratory"), MATLAB can create and
manipulate arrays of 1 (vectors), 2 (matrices), or more dimensions. In the MATLAB
vernacular, a vector refers to a one dimensional (1N or N1) matrix, commonly referred to
as an array in other programming languages. A matrix generally refers to a 2-dimensional
array, i.e. an mn array where m and n are greater than 1. Arrays with more than two
dimensions are referred to as multidimensional arrays. Arrays are a fundamental type and
many standard functions natively support array operations allowing work on arrays without
explicit loops.
A simple array is defined using the syntax: init: increment: terminator. For instance:
>> array = 1:2:9
array =
13579
defines a variable named array (or assigns a new value to an existing
variable with the name array) which is an array consisting of the values
1, 3, 5, 7, and 9. That is, the array starts at 1 (the init value), increments
with each step from the previous value by 2 (the increment value), and
stops once it reaches (or to avoid exceeding) 9
manipulations, etc.). Unfortunately, MATLAB JIT does not support MATLAB structures,
therefore just a simple bundling of various variables into a structure will come at a cost.
2.2.4. Classes
Although MATLAB has classes, the syntax and calling conventions are significantly
different from other languages. MATLAB has value classes and reference classes,
depending on whether the class has handle as a super-class (for reference classes) or not (for
value classes).
Method call behaviour is different between value and reference classes. For example, a call
to a method
Object. Method (); can alter any member of object only if object is an instance of a reference
class.
2.4. Simulink
Simulink is a software package for modelling, simulating, and analyzing dynamical systems.
It supports linear and nonlinear systems, modelled in continuous time, sampled time, or a
hybrid of the two. Systems can also be multi rate, i.e., have different parts that are sampled
or updated at different rates. For modelling, Simulink provides a graphical user interface
(GUI) for building models as block diagrams, using click-and-drag mouse operations. With
this interface, you can draw the models just as you would with pencil and paper. This is a far
10
cry from previous simulation packages that require you to formulate differential equations
and difference equations in a language or program. Simulink includes a comprehensive
block library of sinks, sources, linear and nonlinear components, and connectors. You can
also customize and create your own blocks. For information on creating your own blocks,
see the separate Writing S-Functions guide. Models are hierarchical, so you can build
models using both top-down and bottom-up approaches. You can view the system at a high
level, and then double-click on blocks to go down through the levels to see increasing levels
of model detail. This approach provides insight into how a model is organized and how its
parts interact.
After you define a model, you can simulate it, using a choice of integration methods, either
from the Simulink menus or by entering commands in MATLABs command window. The
menus are particularly convenient for interactive work, while the command-line approach is
very useful for running a batch of simulations (for example, if you are doing Monte Carlo
simulations or want to sweep a parameter across a range of values). Using scopes and other
display blocks, you can see the simulation results while the simulation is running. In
addition, you can change parameters and immediately see what happens, for what if
exploration. The simulation results can be put in the MATLAB workspace for post
processing and visualization.
Model analysis tools include linearization and trimming tools, which can be accessed from
the MATLAB command line, plus the many tools in MATLAB and its application
toolboxes. And because MATLAB and Simulink are integrated, you can simulate, analyze,
and revise your models in either environment at any point.
11
3.5. Including C++ Modules into NS2 and the make Utility
In developing an NS2 simulation, very often it is necessary to create the customized C++
modules to complement the existing libraries. As such, the developer is faced with the task
of keeping track of all the created files as a part of NS2. When a change is made to one file,
usually it requires recompilation of some other files that depend on it. Manual recompilation
13
of each of such files may not be practical. In UNIX, a utility tool called make is available to
overcome such difficulties. As a UNIX utility tool make is very useful for managing the
development of software written in any compilable programming language including C++.
Generally, the make program automatically keeps track of all the files created throughout
the development process. By keeping track, we mean recompiling or relinking wherever
interdependencies exist among these files, which may have been modified as a part of the
development process.
14
Chapter 4: PiccSim
4.1. Introduction
PiccSIM stands for Platform for integrated communications and control design, simulation,
implementation and modelling. The aim of PiccSIM is to deliver, as the name suggests, a
complete toolset for design, simulation and implementation of networked control systems. It
is a co-simulator for network and control system simulation in a networked control system
(NCS) setting with several network and control design tools. It is intended for research on
NCS or Wireless NCS (WiNCS).
PiccSIM consists of Simulink for the dynamical system simulation and the network
simulator ns-2 for the network simulation. The advantage of integrating all into one tool
chain is that it is easy to study all aspects of communication and control, including the
interaction between them. There is an advantage of using well known and powerful tools
such as Simulink and ns-2, integrating them into one toolset, compared to using several
individual tools for studying different aspects separately, or building add-ons for existing
network or control simulators. With PiccSIM both the network and control system is
simulated simultaneously and the interaction between them can be studied.
The PiccSIM Tool chain includes, in addition to NCS simulation, a graphical user interface
for modelling and designing the network and the control system. With it the management of
both simulators is made easy. The Tool chain can also automatically convert the simulation
model to C-code, using Matlab Target Language Compiler and Real-Time Workshop
toolboxes, for implementation on actual wireless node hardware. The simulated system can
thus be tested in real-life with no extra programming effort.
15
Figure 4.2
16
Ns2 may need to run with administration privileges (super user) to access the
network interfaces. Do e.g. sudo bash java RunNS2Server /home/ns2/Desktop/PiccSIM/
Simulink can have a hard time determining dimensions of signals to send. Add a
Signal Specification block and specify the signal dimension on the signal before the
Send to node input port. When sending multiple signals of the same type, the cell
array must contain equally many elements as the signal dimension, i.e. one per signal
in the bus.
Java program on the ns-2 computer needs the Sun Java virtual machine, not the open
source implementation to function properly. Otherwise it will hang on simulation
start (differences in implementation of XML parsing).
For large simulation models, it may take some time to start the Simulink model. The
GUI might think that the simulation has stalled and will stop the ns-2 simulation.
This can be fixed by increasing the counter limit in Toolchain.m, function update
Time.
The Network Scriptor is not very user friendly, e.g. settings cannot be saved. This
will be improved in future releases.
When using the node position updating mechanism, ns-2 may throw a segmentation
fault. The reason is at the moment still unknown.
When using the example files, remember to change your Simulink IP address in the
tcl files, otherwise the simulations will not work (get stuck).
Close the scriptor and answer yes to the message box asking if you want to save the
node positions to the Simulink model file. Now you can simulate the model by
pressing Start Simulation
17
Methodology
18
We will assume that the input of the system is the voltage source (V) applied to the motor's
armature, while the output is the rotational speed of the shaft d(theta)/dt. The rotor and shaft
are assumed to be rigid. We further assume a viscous friction model, that is, the friction
torque is proportional to shaft angular velocity.The physical parameters for our example are:
(J) Moment of inertia of the rotor 0.01 kg.m^2
(b)
(Ke)
0.01 V/rad/sec
(Kt)
0.01 N.m/Amp
19
(R)
electric resistance
1 Ohm
(L)
electric inductance
0.5 H
The torque generated by a DC motor is proportional to the armature current and the strength
of the magnetic field. We will assume that the magnetic field is constant and, therefore, that
the motor torque is proportional to only the armature current i by a constant factor Kt as
shown in the equation below. This is referred to as an armature-controlled motor.
(1)
The back emf, e, is proportional to the angular velocity of the shaft by a constant factor Ke.
(2)
By applying Newton's law and Kirchoff's law to the motor system to generate the
following equations:
20
Output-
21
[A,B,C,D]=linmod('linmodeldcmoter')
[num,den]=ss2tf(A,B,C,D)
num = 0
2.0000
H(S) =
S^2 +12S^1+20
5.2.2. Theory
22
lag compensators introduce a pole-zero pair into the open loop transfer function. The
transfer function can be written in the Laplace domain as
where X is the input to the compensator, Y is the output, s is the complex Laplace
transform variable, z is the zero frequency and p is the pole frequency. The pole and zero
are both typically negative. In a lag compensator
In this system, we assume that you have a lag network, and an adjustable gain in the
lag network.
o In that case, the compensator transfer function would be:
Now, let's look at how the lag network affects how the system behaves. We'll look at
root locus effects and then Bode' plot effects.
Transfer function of our lag compensator is
G(s) =
50s+50
S+0.01
23
Output
the integral and derivative values, denoted P, I, and D .Heuristically, these values can be
interpreted in terms of time: P depends on the present error, I on the accumulation
of past errors, and D is a prediction of future errors, based on current rate of change. The
weighted sum of these three actions is used to adjust the process via a control element.
where
: Proportional gain
: Integral gain
: Derivative gain
:
Error
25
26
Output
Comparison
Parameter
DC Motor
compensat Pid
or
controller
27
Rise time
1.5271
.2183
.0425
Settling
time
2.0676
1.7389
.2387
Over shoot 0
5.6966
7.0785
Undershoo
t
Peak
.0999
1.0549
1.0708
Peak time
3.7593
.3595
.0957
28
Note that there are two feedback loops. The outer control loop feeds the output back to the
input, as usual. However, this loop alone would not provide satisfactory control, because of
the delay; this loop is feeding back outdated information. Intuitively, for the k seconds
during which no fresh information is available, the system is controlled by the inner loop
which contains a predictor of what the (unobservable) output of the plant G currently is.
In this section we are find the process delay in feedback loop, this delay measurement will
perform using two computer PCs. One is acts a host pc and anther is acts as remote pc,
these both PCs are connected through a Local Area Network (LAN) and communicating
each other as shown.
HOSTPC
REMOTE PC
L
A
N
UDP send: The Send block has only one input port, which receives the uint8 vector that is
sent as a UDP packet.
Block Parameters:
IP address to send to: Specify the IP address to send the
packet.
IP port to send to: Specify the port to which to send the
packet.
Use the following local IP port: Set this parameter to -1
(default) to allow the networking stack to automatically
determine the local IP port that is used for sending.
Otherwise, specify a particular port to send a packet from
that port.
30
2
s2+12s+20.02
lag compensater2
Step
PID(z)
Pack
PID Controller1
Pack1
UDP
Send
Binary
Send1
Scope1
UDP
Receive
Binary
Unpack
Receive
Unpack1
T erminator
31
Output
32
Output Block
33
34
35
36
37
38
39
References
40