You are on page 1of 45

Networked Control Systems

Using Matlab\Simulink
Electronics and Communication Engineering

under the Supervision of


Dr. Rajiv Kumar
By

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

5.4 Smith Predictor


5.5 Controllers over the network
8
9
10

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.

Chapter1: Networked Control Systems


1.

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.

Fig.1.1. Typical Structure of an NCS

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

4. Communication network, to enable exchange of information.


The most important feature of a NCS is that it connects cyberspace to physical space thus,
enabling execution of several tasks from long distance. In addition, networked control
systems eliminate unnecessary wiring thus, reducing the complexity and the overall cost in
designing and implementing the control systems. They can also be easily modified or
upgraded by adding sensors, actuators and controllers to them with relatively low cost and
no major changes in their structure. Moreover, featuring efficient sharing of data between
their controllers, NCS are able to easily fuse global information to make intelligent
decisions over large physical spaces.

1.1. Categories of NCS


Generally speaking, the two major types of control systems that utilize communication
networks are:

Shared-network control systems.


Remote control systems.

Shared-network control systems: Using shared-network resources to transfer


measurements, from sensors to controllers and control signals from controllers to actuators,
can greatly reduce the complexity of connections. This method as shown in fig 1.2, is
systematic an structured, provides more flexibility in installation, and eases maintenance
and troubleshooting. Furthermore, networks enable communication among control loops.
This feature is extremely useful when a control loop exchanges information with other
control loops to perform more sophisticated controls, such as fault accommodation and
control. Similar structures for network-based control have been applied to automobiles and
industrial plants.

Fig. 1.2 Shared-networks connections

Remote Control Systems: A remote control system can be thought of as a system


controlled by a controller located far away from it. This is sometimes referred to as teleoperation control. Remote data acquisition systems and remote monitoring systems can also
be included in this class of systems. The place where a central controller is installed is
typically called a local site, while the place where the plant is located is called a remote
site. An example of tele-operation is tele-surgery which has been shown in Fig.1.3.

Fig.1.3. An implementation of NCS in tele-surgery

1.2. Components of NCS


Whatever the arrangement or modalities used for connecting and configuring the hardware
and the software assets in order to actualize a networked control system that has certain
capabilities, the components used have to enable four functions which form the basis of the
function an NCS is required to project. These basis functions are information acquisition
(sensors), command (controllers), and communication and control (actuators).

Fig.1.4. NCS components.

Sensors, to acquire information,


Controllers, to provide decision and commands,
Actuators, to perform the control commands and
Communication network, to enable exchange of information.

1.3. Information Acquisition in a Network


As the name suggests information acquisition requires us to study sensors, data processing,
and signal processing. There is a growing excitement about the potential application of
large-scale sensor networks in diverse applications such as precision agriculture,
geophysical and environment monitoring, remote health care, and security . Rapid progress
in sensing hardware, communications and low-power computing has resulted in a profusion
of commercially available sensor nodes. NCS suggests collecting the relevant data using
distributed sensors in the network to study the system under control. Sensor data can be in
any form starting from small numbers representing temperature, pressure, weight, etc. or in
chunk form such as images, arrays, videos streams, etc.
This raises important questions like:
(a) Bandwidth requirements for the data transfer in the network.
(b) Data collection strategies in the case of a number of sensors.
(c) Cheap, reliable and energy efficient sensors which can easily be added to the NCS.

1.3.1. Control of Actuators over a Network


One of the biggest advantages of a system controlled over a network is scalability.
As we talk about adding many sensors connected through the network at different locations,
we can also have one or more actuators connected to one or more controllers through the
network.
There are optimum control strategies emerging from classical control theory, starting from
PID control, optimal control, adaptive control, robust control, intelligent control and many
other advanced forms of these control algorithms.

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.

1.4. Issues and Challenges in NCS


NCS performance and the response of the system are important factors for both types of
systems. The network can introduce unreliable and time-dependent levels of service in
terms of, for example, delays, jitter, or losses. The Networked Control Systems issues and
challenges have been discussed below:
1. Stability in Control and Delay Compensation:
The basic problem in NCSs includes network-induced delays, single-packet or multiplepacket transmission of plant input and outputs, and dropping of network packets. The
network-induced delays in NCSs occur when sensors, actuators, and controllers exchange
data packet across the communication network. This delay can degrade the performance of
control systems designed without considering it and can even destabilize the system.
Instability of the system due to the network delay is therefore a very important factor to be
considered in NCS. Different mathematical, heuristic and statistical-based approaches are
taken for delay compensation in NCS. A gain scheduler middleware (GSM) has been
developed by Tipsuwan and Chow to alleviate the network time delay effect on networkbased control systems. GSM methodology estimates the network traffic and controls the
gain of the whole system using a feedback processor.
2. Bandwidth Allocation and Scheduling:
As we talk about having multi-sensor and controlling multi-actuator systems in a network,
important consideration should be given to the available bandwidth in the network. With the
finite amount of bandwidth available, we want to utilize it optimally and efficiently. This
further raises the need for priority decisions and scheduling issues for controlling a series of
5

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.

2.2. Defining variables and arrays in Matlab


2.2.1. Variables
Variables are defined using the assignment operator =. MATLAB is a weakly
typed programming language. It is a weakly typed language because types are implicitly
converted. It is a dynamically typed language because variables can be assigned without
8

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

(the terminator value).


2.2.3. Structures
MATLAB has structure data types. Since all variables in MATLAB are arrays, a more
adequate name is "structure array", where each element of the array has the same field
names. In addition, MATLAB supports dynamic field names (field look-ups by name, field
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.3. Script Files


Group of Matlab commands placed in a text file with a text editor. Matlab can open and
execute the commands exactly as if they were entered at the Matlab prompt. The term
script indicates that Matlab reads from the script found in the file. Also called M-files,
as the filenames must end with the extension .m, e.g. example1.m.
M-files are text files and may be created and modified with any text editor. You need to
know how to open, edit, and save a file with the text editor you are using. On a PC or
Macintosh, an M-file editor may be brought up by choosing New from the File menu in the
Matlab Command window and selecting M-file.
The script M-file is executed by choosing Run Script... from the File menu on a PC or
Macintosh, or simply typing the name of the script file at the prompt in the Matlab
command window.

2.3. 1.Script M-files


For simple problems, entering commands at the Matlab prompt in the Command window is
simple and efficient. However, when the number of commands increases, or you want to
change the value of one or more variables, re evaluate a number of commands, typing at the
Matlab becomes tedious.
You will find that for most uses of Matlab, you will want to prepare a
script, which is a sequence of commands written to a file. Then, by
simply typing the script file name at a Matlab prompt, each command in
the script file is executed as if it were entered at the prompt.

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.

2.5 Characteristics of Simulink

High-level language for technical computing

Development environment for managing code, files, and data

Interactive tools for iterative exploration, design, and problem solving


Mathematical functions for linear algebra, statistics, Fourier analysis, filtering,

optimization, and numerical integration


2-D and 3-D graphics functions for visualizing data
Tools for building custom graphical user interfaces
Functions for integrating MATLAB based algorithms with external applications and
languages, such as C, C++, Fortran, Java, COM, and Microsoft Excel.

11

Chapter 3: Network Simulator-2


3.1. Introduction
Network Simulator (Version 2), widely known as NS2, is simply an event
driven simulation tool that has proved useful in studying the dynamic
nature of communication networks. Simulation of wired as well as
wireless network functions and protocols (e.g., routing algorithms, TCP,
UDP) can be done using NS2. In general, NS2 provides users with a way
of specifying such network protocols and simulating their corresponding
behaviours. Due to its flexibility and modular nature, NS2 has gained
constant popularity in the networking research community since its birth
in 1989.

3.2. Characteristics of NS-2


NS-2 implements the following features
1. Router queue Management Techniques Drop Tail, RED, CBQ,
2. Multicasting
3. Simulation of wireless networks
Developed by Sun Microsystems + UC Berkeley (Daedalus Project)
Terrestrial (cellular, adhoc, GPRS, WLAN, BLUETOOTH), satellite
IEEE 802.11 can be simulated, Mobile-IP, and adhoc protocols
4. Traffic Source Behaviour- www, CBR, VBR
5. Transport Agents- UDP/TCP
6. Routing
7. Packet flow
8. Network Topology
9. Applications- Telnet, FTP, Ping
10. Tracing Packets on all links/specific links

3.3. Basic Architecture


NS2 provides users with an executable command ns which takes on input argument, the
name of a Tcl simulation scripting file. Users are feeding the name of a Tcl simulation script
(which sets up a simulation) as an input argument of an NS2 executable command ns. In
most cases, a simulation trace file is created, and is used to plot graph and/or to create
animation.NS2 consists of two key languages: C++ and Object-oriented Tool Command
Language (OTcl). While the C++ defines the internal mechanism (i.e., a backend) of the
simulation objects, the OTcl sets up simulation by assembling and configuring the objects as
well as scheduling discrete events (i.e., a frontend). The C++ and the OTcl are linked
together using TclCL.
After simulation, NS2 outputs either text-based or animation-based simulation results. To
interpret these results graphically and interactively, tools such as NAM (Network Animator)
and XGraph are used. To analyze a particular behaviour of the network, users can extract a
relevant subset of text-based data and transform it to a more conceivable presentation.
12

3.4 Running NS-2


After the installation and/or recompilation an executable file ns is created in the NS2 home
directory. NS2 can be invoked by executing the following statement from the shell
environment:
>>ns [<file>] [<args>] where <file> and <args> are optional input argument. If no
argument is given, the command will bring up an NS2 environment, where NS2 waits to
interpret commands from the keyboard line-by-line. If the first input argument <file> is
given, NS2 will interpreted the input scripting <file> (i.e., a so-called Tcl simulation script)
according to the Tcl syntax. Finally, the input arguments <args>, each separated by a white
space, are fed to the Tcl file <file>. From within the file <file>, the input argument is stored
in the built-in variable argv.

3.4.1. Main NS2 Simulation Steps


The following show the three key step guideline in defining a simulation
scenario in a NS2:
Step 1: Simulation Design
The first step in simulating a network is to design the simulation. In this step, the users
should determine the simulation purposes, network configuration and assumptions, the
performance measures, and the type of expected results.
Step 2: Configuring and Running Simulation
This step implements the design in the first step. It consists of two phases:
Network configuration phase: In this phase network components (e.g., node, TCP and UDP)
are created and configured according to the simulation design. Also, the events such as data
transfer are scheduled to start at a certain time.
Simulation Phase: This phase starts the simulation which was configured in the Network
Configuration Phase. It maintains the simulation clock and executes events chronologically.
This phase usually runs until the simulation clock reached a threshold value specified in the
Network Configuration Phase.
In most cases, it is convenient to define a simulation scenario in a Tcl scripting file (e.g.,
<file>) and feed the file as an input argument of an NS2 invocation (e.g., executing ns
<file>).
Step 3: Post Simulation Processing
The main tasks in this step include verifying the integrity of the program and evaluating the
performance of the simulated network. While the first task is referred to as debugging, the
second one is achieved by properly collecting and compiling simulation results.

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.

3.5.1. An Invocation of a Make Utility


A make utility can be invoked form a UNIX shell with the following command:
>>make [-f my descriptor] where make is mandatory, while the text inside the bracket is
optional. By default (i.e., without optional input arguments), the make utility recompiles and
relinks the source codes according to what specified in the default descriptor file Make file.
If the descriptor file my descriptor is specified, the utility is use this file in place of the
default file Make file.

3.6. A Make Descriptor File


A descriptor file contains an instructor of how the codes should be recompiled and relinked.
Again, the default descriptor file is the file named Make file. A descriptor file contains the
names of the files that make up the executable, their interdependencies, and how each file
should be rebuilt or recompiled.
Such descriptions are specified through a series of so-called dependency rules. Each rule
takes three components, i.e., targets, dependencies, and commands.
The following is the format of the dependency rule:
<target1> [<target2> ...]: [<dependency1> ...]
[<Command>]
A target with a colon sign is mandatory. Everything else inside the brackets is optional. A
target is usually the name of the file which needs to be remade if any modification is done to
dependency files specified after the mandatory colon (:). If any change is noticed, the
second line executes to regenerate the target file.

3.7. NS2 Descriptor File


The NS2 descriptor file is defined in a file Make file located in the home directory of NS2.
It contains the details needed to recompile and relink NS2. The key relevant details are those
beginning with the following keywords.
INCLUDES =: The items behind this keyword are the directory which should be included
into the NS2 environment.
OBJ_CC = and OBJ_STL =: The items behind these two keywords constitute the entire
NS2 object files. When a new C++ module is developed, its corresponding object file name
should be added here.
NS_TCL_LIB =: The items bind this keywords are the Tcl file of NS2. Again, when a new
OTcl module is developed, its corresponding Tcl file name should be added here.

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.

4.2. PiccSIM Architecture


The architecture of the PiccSIM simulation platform is depicted in Figure 4.1 PiccSIM uses
Simulink and the network simulator ns-2 for NCS co-simulation. Simulink and ns-2 can run
on the same or, more easily, on different computers. The PiccSIM Tool chain GUI runs on
MATLAB and controls both the network simulator and the Simulink model.
In Figure 4.1 the simulation of a control loop where process output measurements are
transmitted over the simulated network is depicted. The respective port numbers used for
communication between the simulators are also included. There are also ports for node
position updates from Simulink to ns-2, suitable for mobile control simulations, and ports
for the time-synchronization mechanism between the simulators.

15

Figure 4.1: Architecture

4.3. PiccSIM Reference


4.3.1. Simulation GUI
The main GUI of the Tool chain is shown in Figure 4.2.It is used for selecting simulation
models, accessing the other design tools, such as network configuration, controller tuning
and code generation, and running simulations.
The Simulink model and ns-2 TCL-script are selected with the Browse buttons. The
simulated network is configured with the ns-2 scriptor accessed with the Network Settings
button.
There are buttons for starting and stopping simulations. They will start the Simulink model
and ns-2 simultaneously. With the Get ns-2 results button, some simple statistics over packet
drops and delay are calculated from the simulation trace-file. Debug ns-2 will show the text
output of ns-2. Get ns-2 trace file will download the ns-2 simulation trace-file.

Figure 4.2

16

4.4. Known Problems or Bugs

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

4.5. Remote User Interface


For those who do not have the possibility to setup the PiccSIM platform or do not want to,
there is the possibility to use PiccSIM remotely. Simulation models can be uploaded through
a Java applet interface and the simulation results are displayed in a scope. You need only to
install the PiccSIM Tool chain on a computer with Matlab.
There is the additional benefit, that all the simulation runs are stored in a database for later
retrieval. The remote user interface is based on the MoCoNet platform

17

Methodology

18

Chapter 5: Work Done(Step by


Step)
5.1. DC Motor
5.1.1.Physical setup
A common actuator in control systems is the DC motor. It directly provides rotary motion
and, coupled with wheels or drums and cables, can provide translational motion. The
electric circuit of the armature and the free-body diagram of the rotor are shown in the
figure 5.1:

Figure 5.1 DC Motor

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)

motor viscous friction constant 0.1 N.m.s

(Ke)

electromotive force constant

0.01 V/rad/sec

(Kt)

motor torque constant

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:

5.1.2. Simulink Block

20

Output-

21

Linear model dc motor(Transfer Function of Dc Motor)

[A,B,C,D]=linmod('linmodeldcmoter')
[num,den]=ss2tf(A,B,C,D)
num = 0

2.0000

den = 1.0000 12.0000 20.0200


so our transfer function is
2

H(S) =

S^2 +12S^1+20

5.2. Lag Compensators


5.2.1. Why Use Lag Compensators?
Lag compensators are sometimes the best controller to use to get a system to do what
you want it to do. Like other compensators, lag compensators can be used to adjust
frequency response by adding equal numbers of poles and zeroes to a system. Those added
singularities may possibly be manipulated to give better stability, better performance and
general improvement.

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

5.2.3 Using Lag Compensators


Usually, a lag network is used as part of the controller in a feedback system. Here's
where the lag network would be used.

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:

Gc(s) = Kc(s + a)/(s + b)

And we must have a > b, for a lag compensator.

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

5.2.4. Simulink Block -

23

Output

5.3. PID controller

A proportionalintegralderivative controller (PID controller) is a generic control


loop feedback mechanism (controller) widely used in industrial control systems a PID is
the most commonly used feedback controller. A PID controller calculates an "error" value as
the difference between a measured process variable and a desired set point. The controller
attempts to minimize the error by adjusting the process control inputs.
The PID controller calculation involves three separate constant parameters, and is
accordingly sometimes called three-term control: the proportional,
24

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.

Figure 5.3 PID Controller

5.3.1 PID controller theory


The PID control scheme is named after its three correcting terms, whose sum constitutes
the manipulated variable (MV). The proportional, integral, and derivative terms are
summed to calculate the output of the PID controller. Defining u(t) as the controller
output, the final form of the PID algorithm is:

where
: Proportional gain
: Integral gain
: Derivative gain
:

Error

: Time or instantaneous time (the present)


:

Variable of integration; takes on values from time 0 to the present .

25

5.3.2. Proportional term


The proportional term produces an output value that is proportional to the current error
value. The proportional response can be adjusted by multiplying the error by a constant Kp,
called the proportional gain constant. The proportional term is given by:

5.3.3. Integral term


The contribution from the integral term is proportional to both the magnitude of the error
and the duration of the error. The integral in a PID controller is the sum of the instantaneous
error over time and gives the accumulated offset that should have been corrected previously.
The accumulated error is then multiplied by the integral gain ( ) and added to the
controller output.
The integral term is given by:

5.3.4. Derivative term


The derivative of the process error is calculated by determining the slope of the error over
time and multiplying this rate of change by the derivative gain
. The magnitude of the
contribution of the derivative term to the overall control action is termed the derivative
gain,
.
The derivative term is given by:

For our design we have taken values as


Kp=449;
Ki=1707;
Kd=21.6;

5.3.5. Simulink Block

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

5.4. Smith Predictor


O.J Smith developed in 1950 controller structure to compensate process time delay. The
Smith Predictor controller structure contains the process mathematical model in the
feedback loop. The Smith Predictor consists of building a corrector which virtually hides
the time Delay in the closed loop response of the process. It is basically a mix of a PID
corrector with an internal model. The aim of the corrector is to provide a virtual system
without time delay To the PID. But the idea can be generalized to all control processes that
have long loop delays. Figure shows a block diagram of the scheme, in which a plant lies in
a negative-feedback loop with both feed forward and feedback delays. The Smith Predictor
is very simple. The controller operates on two separate models of the plant, both lying on
internal Feedback loops.

28

Figure 5.4. Smith Predictor

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.

5.4.1. Smith Predictor In Frequency Domain

5.5. Controllers over the network


User Datagram Protocol (UDP) is one of the core members of the Internet Protocol Suite,
the set of network protocols used for the Internet. With UDP, computer applications can
send messages, in this case referred to as data grams, to other hosts on an Internet Protocol
(IP) network without requiring prior communications to set up special transmission channels
or data paths.
The service provided by UDP is an unreliable service that provides no guarantees for
delivery and no protection from duplication (e.g. if this arises due to software errors within
an Intermediate System (IS)). The simplicity of UDP reduces the overhead from using the
protocol and the services may be adequate in many cases.
29

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

Sample time: You can set this parameter to -1 for an inheritable


sample time, but it is recommended that this be set to some specific
(large) value to eliminate chances of dropped packets. This is especially
true when you are using a small base sample time
UDP receive: The Receive block has two output ports. The first port is
the output of the received data as a vector of uint8 while the second one
is a flag indicating whether any new data has been received. This port
outputs a value of 1 for the sample when there is new data and a 0
otherwise. The default behavior of the Receive block is to keep the
previous output when there is no new data. You can modify this
behavior by using the second port to flag when there is new data.
Block Parameters:
IP address to receive from: If set to a specific IP address, only packets arriving from that IP
address are received.
IP port to receive from: Port that the block accepts data from.The other end of the
Communication sends data to the port specified here.
Output port width: Width of the acceptable packets. You can obtain this when designing
the other side (send side) of the communication.

5.5.1. PID controller with network


Simulink block

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

5.5.2. Smith Predictor with network


Simulink block

32

Output Block

33

5.6 Work on Ns-2


Creating a network on Ns-2

34

Transmitting data between two nodes

35

Transmitting data in a network:

Data transmission through shortest path:

36

Link breaking and verifying shortest path algorithm

After link break:

37

38

39

References

40

You might also like