Professional Documents
Culture Documents
WSN Localization Simulator Readme
WSN Localization Simulator Readme
1
Written by Abdelhady Mohammad Naguib May,2011
Thank you for using the WSN Localization Simulator.
INTRODUCTION
A wireless sensor network (WSN) is a network composed of a large number of sensor nodes,
which are deployed in the monitoring field. With the rapid development of WSNs, providing
development tools such as simulation environment before deploying real nodes in physical
environments is getting more important. A well simulation environment can help developers
build their prototype models to know the interactions and the behavior of each node. In addition,
most of WSN applications will deploy a large number of nodes in a simulation environment.
However, the simulation speed depends on the simulation fidelity and scale.
WSN localization is the operation of determining the position of sensor nodes; this
position is estimated and not accurate. Because GPS have high cost and works outdoors only,
there are many localization algorithm that tries to be more accurate in determining the position of
sensor nodes (i.e. have low localization error). In order to effectively design and develop new
localization algorithms targeted towards WSNs, there is a strong need to use an equally effective
and reliable simulation environment. Sensor nodes are, by design, tiny and inexpensive, but due
to their need to work in large numbers make full-scale testing a fairly expensive process to be
carried out using real hardware. Analytical modeling using tools such as MATLAB help in
acquiring a quick insight, but they fail to provide anything close to realistic results that can be
acquired through proper implementations and good simulation tools.
Framework Architecture
Our framework is composed of two main components: simulator and a
localization algorithm. A simulator includes two classes; the first one is
network DLL file which contains all simulator classes (e.g. sensor class,
locator class, packet class ...etc.) and the second one is developer interface
class which contains all control functions (e.g. run and stop simulator,
painting method, etc.). The second component of our framework is the
localization algorithm which is written by the developer into a DLL file and
referencing this file into our framework, so that the developer has the ability
to write his localization algorithm but under certain design specifications as
shown in Fig. 2.
Set_Parameters (locator range, beam width )
{
}
Connect (list of locators, list of sensors )
{
}
Send (list of sensors)
{
}
Localize (list of sensors, locator range )
{
}
Figure2: Localization Algorithm Design Specifications
The first method (Set_Parameters) is responsible to get all control data from user interface. The
second method is used to test the connectivity between a sensor node and a locator node. The
third method (Send), after a valid connection this method is used to transmit packets between
different nodes. Finally, after getting all necessary packets from locator nodes, a sensor node can
estimate its position using the fourth method (Localize).
As shown in Fig. 3, we illustrate the sequence diagram for submitting parameters from the user
through simulator and getting the response back from the localization algorithm. First, the user
set the required parameters via user interface and the simulator receives these parameters and
applies it using Set_Parameters method which gives the needed argument to the localization
algorithm. Second, the algorithm will reply to the simulator. Third, calling Connect method to
test the connectivity between different nodes, if there is a connection, fill array list of
connections between different nodes. Fourth, calling send method to carry out sending packets
between connected nodes by filling array list which contains the sent packets for each sensor
node. Finally, calling Localize method to estimate the position of a sensor node and returning the
results back to the user into an external text file.
User
Algorithm
Simulator
Input Parameters
Get Parameters
Set_Parameters
Parameters set
Connect
Connection established
Adding a Reference
Finally, the proposed framework is easy to use, scalable that supports 400x400 nodes and
extendable which allows developers to write their own localization algorithms and referencing it
to our framework.
1- Network Class
Which is used for initialization of user interface parameters.
public WirelessSensorNetwork(int NoSensors, int iMaxX, int iMaxY, int
LocatorRadius, int sangle1, int sangle2, int sangle3, int sangle4, int
sangle5, int sangle6, int sangle7, int sangle8, int Sweepangle, int stepx,
int stepy, bool radio1, bool radio2, int combo1, int combo2, int combo3,
int BeaconRadius, int noBeacons, bool checkBeacons, int noMobSensors, int
noRLocators){
this.radio1 = radio1;
this.radio2 = radio2;
this.combo1 = combo1;
this.combo2 = combo2;
this.combo3 = combo3;
this.stepx = stepx;
this.stepy = stepy;
this.noBeacons = noBeacons;
this.checkBeacons = checkBeacons;
this.noMobSensors = noMobSensors;
this.noRLocators = noRLocators;
this.NoSensors = NoSensors;
this.iMaxX = iMaxX;
this.iMaxY = iMaxY;
sensors = null;
locators = null;
r = new Random((int)System.DateTime.Now.Ticks);
this.LocatorRadius = LocatorRadius;
this.BeaconRadius = BeaconRadius;
this.sangle1 = sangle1;
this.sangle2 = sangle2;
this.sangle3 = sangle3;
this.sangle4 = sangle4;
this.sangle5 = sangle5;
this.sangle6 = sangle6;
this.sangle7 = sangle7;
this.sangle8 = sangle8;
this.Sweepangle = Sweepangle;
// build the network
BuildNetwork();
BuildNetwork() method allows deploying of various network objects: sensor, locator and beacon
nodes as follows:
public void BuildNetwork()
{
aSensors = new ArrayList();
aLocators = new ArrayList();
aBeacons = new ArrayList();
//Array of Locators
//Array of Beacons
}
int s = 0, x = 70, y = 70;
while (aSensors.Count < 25)
{
WirelessSensor sensor = new WirelessSensor(x, y);
aSensors.Insert(s, sensor);
if (x < 470) x += 100;
else { x = 70; y += 100; }
s++;
}
}
else
{
int s = 0;
while (aSensors.Count < NoSensors)
{
WirelessSensor sensor = new WirelessSensor(r.Next(iMaxX - 10) + 5,
r.Next(iMaxY - 10) + 5);
aSensors.Insert(s, sensor);
}
}
}
s++;
else if (m == 6)
{
x = 270; y = 520;
Locator locator = new Locator(m, x, y, LocatorRadius, sangle7);
aLocators.Insert(m, locator);
}
else if (m == 7)
{
x = 520; y = 520;
Locator locator = new Locator(m, x, y, LocatorRadius, sangle8);
aLocators.Insert(m, locator);
}
m++;
}
}
else if (combo1 == 2)
{
int x = 20, y = 20;
int m = 0;
while ((aLocators.Count) < 5)
{
if (m == 0)
{
x = 270; y = 20;
Locator locator = new Locator(m, x, y, LocatorRadius, sangle1);
aLocators.Insert(m, locator);
}
else if (m == 1)
{
x = 20; y = 270;
Locator locator = new Locator(m, x, y, LocatorRadius, sangle2);
aLocators.Insert(m, locator);
}
else if (m == 2)
{
x = 270; y = 270;
Locator locator = new Locator(m, x, y, LocatorRadius, sangle3);
aLocators.Insert(m, locator);
}
else if (m == 3)
{
x = 520; y = 270;
Locator locator = new Locator(m, x, y, LocatorRadius, sangle4);
aLocators.Insert(m, locator);
}
else if (m == 4)
{
x = 270; y = 520;
Locator locator = new Locator(m, x, y, LocatorRadius, sangle5);
aLocators.Insert(m, locator);
}
m++;
}
}
else if (combo1 == 3)
{
int x = 20, y = 20;
int m = 0;
while ((aLocators.Count) < 6)
{
if (m == 0)
{
x = 145; y = 100;
Locator locator = new Locator(m, x, y, LocatorRadius, sangle1);
aLocators.Insert(m, locator);
}
else if (m == 1)
{
x = 270; y = 100;
Locator locator = new Locator(m, x, y, LocatorRadius, sangle2);
aLocators.Insert(m, locator);
}
else if (m == 2)
{
x = 395; y = 100;
Locator locator = new Locator(m, x, y, LocatorRadius, sangle3);
aLocators.Insert(m, locator);
}
else if (m == 3)
{
x = 145; y = 400;
Locator locator = new Locator(m, x, y, LocatorRadius, sangle4);
aLocators.Insert(m, locator);
}
else if (m == 4)
{
x = 270; y = 400;
Locator locator = new Locator(m, x, y, LocatorRadius, sangle5);
aLocators.Insert(m, locator);
}
else if (m == 5)
{
x = 395; y = 400;
Locator locator = new Locator(m, x, y, LocatorRadius, sangle5);
aLocators.Insert(m, locator);
}
}
}
m++;
//Deployment of Beacons
if (checkBeacons == true)
{
int b = 0;
while (aBeacons.Count < noBeacons)
{
Beacon beacon = new Beacon(b, r.Next(iMaxX - 10), r.Next(iMaxY - 10),
BeaconRadius);
aBeacons.Insert(b, beacon);
b++;
}
}
}
public
public
public
public
ArrayList
ArrayList
ArrayList
int x, y,
}
}
Locator sLocator;
Beacon sBeacon;
WirelessSensor sSender; // the upstream sensor
WirelessSensor sReceiver; // the downstream sensor
pkt pkt = null;
int Sangle;
//start angle of locator sector
short Prlevel;
//Power levels for PTA algorithm
this.sLocator = sLocator;
this.sReceiver = sReceiver;
this.Sangle = Sangle;
// this function moves the sensors around, and removes those that have
traveled out of bounds
public void Update()
//traditional motion
{
ArrayList aRemoveSensors = new ArrayList();
foreach (WirelessSensor sensor in aSensors)
{
sensor.x += sensor.dx;
sensor.y += sensor.dy;
if ((sensor.x < -5) || (sensor.y < -5) || (sensor.x >
iMaxX + 5) || (sensor.y > iMaxY + 5))
aRemoveSensors.Add(sensor);
}
foreach (WirelessSensor sensor in aRemoveSensors)
aSensors.Remove(sensor);
}
}
5- Packet Class
public class pkt
{
public int x, y, sangle;
public int ID;
public short prlevel;
public pkt(int ID, int x, int y)
//Omnidirectional antenna
{
this.ID = ID;
this.x = x;
this.y = y;
}
public pkt(int ID, int x, int y, int sangle) //Directed antenna
{
this.ID = ID;
this.x = x;
this.y = y;
this.sangle = sangle;
}
public pkt(int ID, int x, int y, short prlevel) //omin-power levels
{
this.prlevel = prlevel;
this.ID = ID;
this.x = x;
this.y = y;
}
}
}
network.sensors.mutexSensor.ReleaseMutex();
Pen
Pen
Pen
Pen
Pen
Pen
locatorPen
sectorPen1
sectorPen2
sectorPen3
sectorPen4
sectorPen5
=
=
=
=
=
=
Pens.Black;
Pens.Green;
Pens.Brown;
Pens.Red;
Pens.Orange;
Pens.Olive;
if (locator.id == 0)
{
if (checkBox5.Checked) g.DrawPie(sectorPen1, locator.x - network.LocatorRadius,
locator.y - network.LocatorRadius, network.LocatorRadius * 2, network.LocatorRadius
* 2, network.sangle1, network.Sweepangle);
if (checkBox6.Checked) g.DrawEllipse(sectorPen1, locator.x - network.LocatorRadius,
locator.y - network.LocatorRadius, network.LocatorRadius * 2, network.LocatorRadius
* 2);
if (checkBox14.Checked)
{
g.DrawEllipse(sectorPen2, locator.x - network.LocatorRadius + prsep, locator.y network.LocatorRadius + prsep, (network.LocatorRadius - prsep) * 2,
(network.LocatorRadius - prsep) * 2);
g.DrawEllipse(sectorPen3, locator.x - network.LocatorRadius + 2 * prsep, locator.y network.LocatorRadius + 2 * prsep, (network.LocatorRadius - 2 * prsep) * 2,
(network.LocatorRadius - 2 * prsep) * 2);
g.DrawEllipse(sectorPen4, locator.x - network.LocatorRadius + 3 * prsep, locator.y network.LocatorRadius + 3 * prsep, (network.LocatorRadius - 3 * prsep) * 2,
(network.LocatorRadius - 3 * prsep) * 2);
g.DrawEllipse(sectorPen5, locator.x - network.LocatorRadius + 4 * prsep, locator.y network.LocatorRadius + 4 * prsep, (network.LocatorRadius - 4 * prsep) * 2,
(network.LocatorRadius - 4 * prsep) * 2);
}
}
if (locator.id == 1)
{
if (checkBox5.Checked) g.DrawPie(sectorPen1, locator.x - network.LocatorRadius,
locator.y - network.LocatorRadius, network.LocatorRadius * 2, network.LocatorRadius
* 2, network.sangle2, network.Sweepangle);
if (checkBox6.Checked) g.DrawEllipse(sectorPen1, locator.x - network.LocatorRadius,
locator.y - network.LocatorRadius, network.LocatorRadius * 2, network.LocatorRadius
* 2);
if (checkBox14.Checked)
{
g.DrawEllipse(sectorPen2, locator.x - network.LocatorRadius + prsep, locator.y network.LocatorRadius + prsep, (network.LocatorRadius - prsep) * 2,
(network.LocatorRadius - prsep) * 2);
g.DrawEllipse(sectorPen3, locator.x - network.LocatorRadius + 2 * prsep,
locator.y - network.LocatorRadius + 2 * prsep, (network.LocatorRadius - 2 * prsep) *
2, (network.LocatorRadius - 2 * prsep) * 2);
g.DrawEllipse(sectorPen4, locator.x - network.LocatorRadius + 3 * prsep, locator.y
- network.LocatorRadius + 3 * prsep, (network.LocatorRadius - 3 * prsep) * 2,
(network.LocatorRadius - 3 * prsep) * 2);
g.DrawEllipse(sectorPen5, locator.x - network.LocatorRadius + 4 * prsep, locator.y
- network.LocatorRadius + 4 * prsep, (network.LocatorRadius - 4 * prsep) * 2,
(network.LocatorRadius - 4 * prsep) * 2);
}
}
if (locator.id == 2)
{
if (checkBox5.Checked) g.DrawPie(sectorPen1, locator.x - network.LocatorRadius,
locator.y - network.LocatorRadius, network.LocatorRadius * 2, network.LocatorRadius
* 2, network.sangle3, network.Sweepangle);
if (checkBox6.Checked) g.DrawEllipse(sectorPen1, locator.x - network.LocatorRadius,
locator.y - network.LocatorRadius, network.LocatorRadius * 2, network.LocatorRadius
* 2);
if (checkBox14.Checked)
{
g.DrawEllipse(sectorPen2, locator.x - network.LocatorRadius + prsep, locator.y network.LocatorRadius + prsep, (network.LocatorRadius - prsep) * 2,
(network.LocatorRadius - prsep) * 2);
g.DrawEllipse(sectorPen3, locator.x - network.LocatorRadius + 2 * prsep, locator.y
- network.LocatorRadius + 2 * prsep, (network.LocatorRadius - 2 * prsep) * 2,
(network.LocatorRadius - 2 * prsep) * 2);
g.DrawEllipse(sectorPen4, locator.x - network.LocatorRadius + 3 * prsep, locator.y
- network.LocatorRadius + 3 * prsep, (network.LocatorRadius - 3 * prsep) * 2,
(network.LocatorRadius - 3 * prsep) * 2);
g.DrawEllipse(sectorPen5, locator.x - network.LocatorRadius + 4 * prsep, locator.y network.LocatorRadius + 4 * prsep, (network.LocatorRadius - 4 * prsep) * 2,
(network.LocatorRadius - 4 * prsep) * 2);
}
}
if (locator.id == 3)
{
if (checkBox5.Checked) g.DrawPie(sectorPen1, locator.x - network.LocatorRadius,
locator.y - network.LocatorRadius, network.LocatorRadius * 2, network.LocatorRadius
* 2, network.sangle4, network.Sweepangle);
if (checkBox6.Checked) g.DrawEllipse(sectorPen1, locator.x - network.LocatorRadius,
locator.y - network.LocatorRadius, network.LocatorRadius * 2, network.LocatorRadius
* 2);
if (checkBox14.Checked)
{
g.DrawEllipse(sectorPen2, locator.x - network.LocatorRadius + prsep, locator.y network.LocatorRadius + prsep, (network.LocatorRadius - prsep) * 2,
(network.LocatorRadius - prsep) * 2);
g.DrawEllipse(sectorPen3, locator.x - network.LocatorRadius + 2 * prsep, locator.y network.LocatorRadius + 2 * prsep, (network.LocatorRadius - 2 * prsep) * 2,
(network.LocatorRadius - 2 * prsep) * 2);
g.DrawEllipse(sectorPen4, locator.x - network.LocatorRadius + 3 * prsep, locator.y
- network.LocatorRadius + 3 * prsep, (network.LocatorRadius - 3 * prsep) * 2,
(network.LocatorRadius - 3 * prsep) * 2);
g.DrawEllipse(sectorPen5, locator.x - network.LocatorRadius + 4 * prsep, locator.y network.LocatorRadius + 4 * prsep, (network.LocatorRadius - 4 * prsep) * 2,
(network.LocatorRadius - 4 * prsep) * 2);
}
}
if (locator.id == 4)
{
if (checkBox5.Checked) g.DrawPie(sectorPen1, locator.x - network.LocatorRadius,
locator.y - network.LocatorRadius, network.LocatorRadius * 2, network.LocatorRadius
* 2, network.sangle5, network.Sweepangle);
if (checkBox6.Checked) g.DrawEllipse(sectorPen1, locator.x - network.LocatorRadius,
locator.y - network.LocatorRadius, network.LocatorRadius * 2, network.LocatorRadius
* 2);
if (checkBox14.Checked)
{
g.DrawEllipse(sectorPen2, locator.x - network.LocatorRadius + prsep, locator.y network.LocatorRadius + prsep, (network.LocatorRadius - prsep) * 2,
(network.LocatorRadius - prsep) * 2);
g.DrawEllipse(sectorPen3, locator.x - network.LocatorRadius + 2 * prsep, locator.y
- network.LocatorRadius + 2 * prsep, (network.LocatorRadius - 2 * prsep) * 2,
(network.LocatorRadius - 2 * prsep) * 2);
g.DrawEllipse(sectorPen4, locator.x - network.LocatorRadius + 3 * prsep, locator.y
- network.LocatorRadius + 3 * prsep, (network.LocatorRadius - 3 * prsep) * 2,
(network.LocatorRadius - 3 * prsep) * 2);
g.DrawEllipse(sectorPen5, locator.x - network.LocatorRadius + 4 * prsep, locator.y
- network.LocatorRadius + 4 * prsep, (network.LocatorRadius - 4 * prsep) * 2,
(network.LocatorRadius - 4 * prsep) * 2);
}
}
if (locator.id == 5)
{
if (checkBox5.Checked) g.DrawPie(sectorPen1, locator.x - network.LocatorRadius,
locator.y - network.LocatorRadius, network.LocatorRadius * 2, network.LocatorRadius
* 2, network.sangle6, network.Sweepangle);
if (checkBox6.Checked) g.DrawEllipse(sectorPen1, locator.x - network.LocatorRadius,
locator.y - network.LocatorRadius, network.LocatorRadius * 2, network.LocatorRadius
* 2);
if (checkBox14.Checked)
{
g.DrawEllipse(sectorPen2, locator.x - network.LocatorRadius + prsep, locator.y network.LocatorRadius + prsep, (network.LocatorRadius - prsep) * 2,
(network.LocatorRadius - prsep) * 2);
g.DrawEllipse(sectorPen3, locator.x - network.LocatorRadius + 2 * prsep, locator.y network.LocatorRadius + 2 * prsep, (network.LocatorRadius - 2 * prsep) * 2,
(network.LocatorRadius - 2 * prsep) * 2);
g.DrawEllipse(sectorPen4, locator.x - network.LocatorRadius + 3 * prsep, locator.y
- network.LocatorRadius + 3 * prsep, (network.LocatorRadius - 3 * prsep) * 2,
(network.LocatorRadius - 3 * prsep) * 2);
g.DrawEllipse(sectorPen5, locator.x - network.LocatorRadius + 4 * prsep, locator.y
- network.LocatorRadius + 4 * prsep, (network.LocatorRadius - 4 * prsep) * 2,
(network.LocatorRadius - 4 * prsep) * 2);
}
}
if (locator.id == 6)
{
if (checkBox5.Checked) g.DrawPie(sectorPen1, locator.x - network.LocatorRadius,
locator.y - network.LocatorRadius, network.LocatorRadius * 2, network.LocatorRadius
* 2, network.sangle7, network.Sweepangle);
if (checkBox6.Checked) g.DrawEllipse(sectorPen1, locator.x - network.LocatorRadius,
locator.y - network.LocatorRadius, network.LocatorRadius * 2, network.LocatorRadius
* 2);
if (checkBox14.Checked)
{
g.DrawEllipse(sectorPen2, locator.x - network.LocatorRadius + prsep, locator.y network.LocatorRadius + prsep, (network.LocatorRadius - prsep) * 2,
(network.LocatorRadius - prsep) * 2);
g.DrawEllipse(sectorPen3, locator.x - network.LocatorRadius + 2 * prsep, locator.y network.LocatorRadius + 2 * prsep, (network.LocatorRadius - 2 * prsep) * 2,
(network.LocatorRadius - 2 * prsep) * 2);
g.DrawEllipse(sectorPen4, locator.x - network.LocatorRadius + 3 * prsep, locator.y network.LocatorRadius + 3 * prsep, (network.LocatorRadius - 3 * prsep) * 2,
(network.LocatorRadius - 3 * prsep) * 2);
if (checkBox16.Checked)
{
HADLA.HADLA algorithm5 = new HADLA.HADLA(sender, e, network.aSensors,
network.aLocators, radioButton3.Checked, radioButton4.Checked,
int.Parse(textBox3.Text), int.Parse(textBox4.Text), int.Parse(textBox5.Text),
network.LocatorRadius, network.Sweepangle, network.sangle1, network.sangle2,
network.sangle3, network.sangle4, network.sangle5, network.sangle6, network.sangle7,
network.sangle8, txtOutputFolder.Text); //HADLA Algorithm
}
if (checkBox17.Checked)
{
DIL.DIL algorithm7 = new DIL.DIL(sender, e, network.aSensors, network.aLocators,
network.aBeacons, radioButton3.Checked, radioButton4.Checked,
int.Parse(textBox3.Text), double.Parse(textBox4.Text), int.Parse(textBox5.Text),
network.LocatorRadius, network.BeaconRadius, network.Sweepangle, network.sangle1,
network.sangle2, network.sangle3, network.sangle4, network.sangle5, network.sangle6,
network.sangle7, network.sangle8, txtOutputFolder.Text); //DIL Algorithm
}
if (checkBox18.Checked)
{
RAL.RAL algorithm8 = new RAL.RAL(sender, e, network.aSensors, network.aLocators,
checkBox1.Checked, network.LocatorRadius, network.Sweepangle,network.sangle1,
network.sangle2, network.sangle3, network.sangle4, network.sangle5, network.sangle6,
network.sangle7, network.sangle8, txtOutputFolder.Text); //RAL Algorithm
}
network.BeaconRadius = trackBar1.Value;
network.LocatorRadius = trackLocatorRadius.Value;
network.Sweepangle = trackSweepAngle.Value;
network.sangle1 = tracksangle1.Value;
network.sangle2 = tracksangle2.Value;
network.sangle3 = tracksangle3.Value;
network.sangle4 = tracksangle4.Value;
network.sangle5 = tracksangle5.Value;
network.sangle6 = tracksangle6.Value;
network.sangle7 = tracksangle7.Value;
network.sangle8 = tracksangle8.Value;
network.combo3 = comboBox3.SelectedIndex;
label1.Text = trackLocatorRadius.Value.ToString();
label2.Text = trackBar1.Value.ToString();
label3.Text = trackSweepAngle.Value.ToString();
}
}
if (radioButton2.Checked)
//Mobile
{
if (checkBox1.Checked)
//Estimate Position
{
network.sensors.mutexSensor.WaitOne();
if (checkBox11.Checked)
{
HiRLoc.HiRLoc algorithm3 = new HiRLoc.HiRLoc(sender, e, network.sensors.aSensors,
network.aLocators, checkBox2.Checked, checkBox3.Checked, checkBox4.Checked,
checkBox7.Checked, checkBox8.Checked, checkBox9.Checked, checkBox10.Checked,
network.LocatorRadius, network.Sweepangle, network.sangle1, network.sangle2,
network.sangle3, network.sangle4, network.sangle5, network.sangle6, network.sangle7,
network.sangle8, txtOutputFolder.Text); //HiRLoc Algorithm
}
if (checkBox12.Checked)
{
SeRLoc.SeRLoc algorithm2 = new SeRLoc.SeRLoc(sender, e, network.sensors.aSensors,
network.aLocators, checkBox2.Checked, checkBox3.Checked, checkBox4.Checked,
checkBox7.Checked, checkBox8.Checked, checkBox9.Checked, checkBox10.Checked,
network.LocatorRadius, network.Sweepangle, network.sangle1, network.sangle2,
network.sangle3, network.sangle4, network.sangle5, network.sangle6, network.sangle7,
network.sangle8, txtOutputFolder.Text); //SeRLoc Algorithm
}
if (checkBox13.Checked)
{
centroid.centroid algorithm1 = new centroid.centroid(sender, e,
network.sensors.aSensors, network.aLocators, checkBox2.Checked, checkBox3.Checked,
checkBox4.Checked, checkBox7.Checked, checkBox8.Checked, checkBox9.Checked,
checkBox10.Checked, network.LocatorRadius, txtOutputFolder.Text);//Centroid
//Algorithm
}
if (checkBox14.Checked)
{
PTA.PTA algorithm6 = new PTA.PTA(sender, e, network.sensors.aSensors,
network.aLocators, checkBox14.Checked, network.LocatorRadius,
comboBox3.SelectedIndex, txtOutputFolder.Text); //PTA Algorithm
}
if (checkBox15.Checked)
{
ADLA.ADLA algorithm4 = new ADLA.ADLA(sender, e, network.sensors.aSensors,
network.aLocators, radioButton3.Checked, radioButton4.Checked,
int.Parse(textBox3.Text), int.Parse(textBox4.Text), int.Parse(textBox5.Text),
network.LocatorRadius, network.Sweepangle, network.sangle1, network.sangle2,
network.sangle3, network.sangle4, network.sangle5, network.sangle6, network.sangle7,
network.sangle8, txtOutputFolder.Text); //ADLA Algorithm
}
if (checkBox16.Checked)
{
HADLA.HADLA algorithm5 = new HADLA.HADLA(sender, e, network.sensors.aSensors,
network.aLocators, radioButton3.Checked, radioButton4.Checked,
int.Parse(textBox3.Text), int.Parse(textBox4.Text), int.Parse(textBox5.Text),
network.LocatorRadius, network.Sweepangle, network.sangle1, network.sangle2,
network.sangle3, network.sangle4, network.sangle5, network.sangle6, network.sangle7,
network.sangle8, txtOutputFolder.Text); //HADLA Algorithm
}
if (checkBox17.Checked)
{
DIL.DIL algorithm7 = new DIL.DIL(sender, e, network.sensors.aSensors,
network.aLocators, network.aBeacons, radioButton3.Checked, radioButton4.Checked,
int.Parse(textBox3.Text), int.Parse(textBox4.Text), int.Parse(textBox5.Text),
network.LocatorRadius, network.BeaconRadius, network.Sweepangle, network.sangle1,
network.sangle2, network.sangle3, network.sangle4, network.sangle5, network.sangle6,
network.sangle7, network.sangle8, txtOutputFolder.Text); //DIL Algorithm
}
if (checkBox18.Checked)
{
RAL.RAL algorithm8 = new RAL.RAL(sender, e, network.sensors.aSensors,
network.aLocators, checkBox1.Checked, network.LocatorRadius, network.Sweepangle,
network.sangle1, network.sangle2, network.sangle3, network.sangle4, network.sangle5,
network.sangle6, network.sangle7, network.sangle8, txtOutputFolder.Text);
//RAL Algorithm
}
network.sensors.mutexSensor.ReleaseMutex();
network.BeaconRadius = trackBar1.Value;
network.LocatorRadius = trackLocatorRadius.Value;
network.Sweepangle = trackSweepAngle.Value;
network.sangle1 = tracksangle1.Value;
network.sangle2 = tracksangle2.Value;
network.sangle3 = tracksangle3.Value;
network.sangle4 = tracksangle4.Value;
network.sangle5 = tracksangle5.Value;
network.sangle6 = tracksangle6.Value;
network.sangle7 = tracksangle7.Value;
network.sangle8 = tracksangle8.Value;
network.combo3 = comboBox3.SelectedIndex;
label1.Text = trackLocatorRadius.Value.ToString();
label2.Text = trackBar1.Value.ToString();
label3.Text = trackSweepAngle.Value.ToString();
}
}
}
// finish painting
if (network != null)
network.bPainting = false;
2- Connect method, used to test the connectivity between sensor node and locator node.
public void connect(ArrayList asensor, ArrayList alocator)
{
for (int j = 0; j < asensor.Count; j++)
{
networkdll.Class1.WirelessSensor jSensor =
networkdll.Class1.WirelessSensor)asensor[j];
jSensor.apkts = new ArrayList();
jSensor.Connections = new ArrayList();
for (int i = 0; i < alocator.Count; i++)
{
networkdll.Class1.Locator iLocator =
(networkdll.Class1.Locator)alocator[i];
if (i == 0) iLocator.sangle = sangle1;
if (i == 1) iLocator.sangle = sangle2;
if (i == 2) iLocator.sangle = sangle3;
if (i == 3) iLocator.sangle = sangle4;
if (i == 4) iLocator.sangle = sangle5;
if (i == 5) iLocator.sangle = sangle6;
if (i == 6) iLocator.sangle = sangle7;
if (i == 7) iLocator.sangle = sangle8;
float lsRadius = (float)(Math.Sqrt(Math.Pow(iLocator.x - jSensor.x, 2) +
Math.Pow(iLocator.y - jSensor.y, 2)));
int theta1 = (int)Math.Floor((Math.Acos(Math.Abs(jSensor.x - iLocator.x) /
lsRadius) * (180 * 7 / 22)));
int theta = (int)Math.Floor((Math.Acos(Math.Abs(jSensor.y - iLocator.y) / lsRadius)
* (180 * 7 / 22)));
int theta2 = theta + 90;
int theta3 = theta1 + 180;
int theta4 = 270 + theta;
start = System.DateTime.Now.Ticks;
if (lsRadius <= locatorRadius)
{
int res = 5;
//resolution for rotation
if (jSensor.x >= iLocator.x && jSensor.y >= iLocator.y) //Region 1
{
if (theta1 >= iLocator.sangle && theta1 <= (iLocator.sangle + sweepangle))
{
if (theta1 == iLocator.sangle && theta1 <= (iLocator.sangle + sweepangle))
{
jSensor.Connections.Add(new networkdll.Class1.WirelessSensorConnection(iLocator,
jSensor, (iLocator.sangle - res)));
}
else
{
for (int k = 1; k < sweepangle; k++)
{
if (theta1 == iLocator.sangle)
{
jSensor.Connections.Add(new networkdll.Class1.WirelessSensorConnection(iLocator,
jSensor, (iLocator.sangle - res))); break;//,iLocator.sweep));
}
else iLocator.sangle = (iLocator.sangle + 1);
}
}
}
}
else if (jSensor.x < iLocator.x && jSensor.y >= iLocator.y) //Region 2
{
if (theta2 >= iLocator.sangle && theta2 <= (iLocator.sangle + sweepangle))
{
if (theta2 == iLocator.sangle && theta2 <= (iLocator.sangle + sweepangle))
{
jSensor.Connections.Add(new networkdll.Class1.WirelessSensorConnection(iLocator,
jSensor, (iLocator.sangle - res)));
}
else
{
for (int k = 1; k < sweepangle; k++)
{
if (theta2 == iLocator.sangle)
{
jSensor.Connections.Add(new networkdll.Class1.WirelessSensorConnection(iLocator,
jSensor, (iLocator.sangle - res))); break;
}
else iLocator.sangle = (iLocator.sangle + 1);
}
}
}
}
else if (jSensor.x <= iLocator.x && jSensor.y < iLocator.y) //Region 3
{
if (theta3 >= iLocator.sangle && theta3 <= (iLocator.sangle + sweepangle))
{
if (theta3 == iLocator.sangle && theta3 <= (iLocator.sangle + sweepangle))
{
jSensor.Connections.Add(new networkdll.Class1.WirelessSensorConnection(iLocator,
jSensor, (iLocator.sangle - res)));
}
else
{
for (int k = 1; k < sweepangle; k++)
{
if (theta3 == iLocator.sangle)
{
jSensor.Connections.Add(new networkdll.Class1.WirelessSensorConnection(iLocator,
jSensor, (iLocator.sangle - res))); break;
}
else iLocator.sangle = (iLocator.sangle + 1);
}
}
}
}
else if (jSensor.x > iLocator.x && jSensor.y < iLocator.y) //Region 4
{
if (theta4 >= iLocator.sangle && theta4 <= (iLocator.sangle + sweepangle))
{
if (theta4 == iLocator.sangle && theta4 <= (iLocator.sangle + sweepangle))
{
jSensor.Connections.Add(new networkdll.Class1.WirelessSensorConnection(iLocator,
jSensor, (iLocator.sangle - res)));
}
else
{
for (int k = 1; k < sweepangle; k++)
{
if (theta4 == iLocator.sangle)
{
jSensor.Connections.Add(new networkdll.Class1.WirelessSensorConnection(iLocator,
jSensor, (iLocator.sangle - res))); break;
}
else iLocator.sangle = (iLocator.sangle +
1);
}
}
}
}
}
}
}
3- send method, when the connection is established between sender and receiver, sender will
carry out sending packets using send method.
public void send(ArrayList asensor)
{
foreach (networkdll.Class1.WirelessSensor sensor in asensor)
{
foreach (networkdll.Class1.WirelessSensorConnection connection in
sensor.Connections)
{
sensor.apkts.Add(new
networkdll.Class1.pkt(connection.sLocator.id, connection.sLocator.x,
connection.sLocator.y, connection.Sangle));
}
}
}
4- localize method, is the core of localization algorithm, where all calculations run.
public void localize(object sender, PaintEventArgs e, ArrayList asensor, bool
checkBox2, bool checkBox3, bool checkBox4, bool checkBox5, bool checkBox6, bool
checkBox7, bool checkBox8, float locatorRadius, String textbox)
{
Graphics g = e.Graphics;
Brush sbrush = Brushes.BlueViolet;
String opc8 = "", opc7 = "", opc6 = "", opc5 = "", opc4 = "", opc3 = "", opc2 =
"";
//printing into Excel
String op8 = "", op7 = "", op6 = "", op5 = "", op4 = "", op3 = "", op2 = "";
String time = "";
//to calculate algorithm running time
int d = 0;
int ersum2 = 0, count2 = 0, ersum3 = 0, count3 = 0, ersum4 = 0, count4 = 0,
ersum5 = 0, count5 = 0, ersum6 = 0, count6 = 0, ersum7 = 0, count7 = 0, ersum8 =
0, count8 = 0;
foreach (networkdll.Class1.WirelessSensor sensor in asensor)
{
int[] hLHs = new int[9]; //Locators heard by sensor node
int[] hax = new int[9]; //x coordinate of locators heard
int[] hay = new int[9]; //y coordinate of locators heard
int[] hsa = new int[9]; //start angle of locators heard
int t2 = 0, Xest, Yest;
foreach (networkdll.Class1.pkt packet in sensor.apkts)
{
hLHs[t2] = packet.ID;
hax[t2] = packet.x;
hay[t2] = packet.y;
hsa[t2] = packet.sangle;
t2++;
if (sensor.apkts.Count == 8 && t2 == 8)
//eight
if (checkBox8)
{
float
float
float
float
float
float
float
float
float
float
float
float
float
if (sensor.apkts.Count == 8 && t2 == 8)
//eight sectors "locators"
{
int xg, yg = 20, MG = 0;
Xest = 0; Yest = 0;
for (int c = 1; c < 51; c++)
//columns
{
xg = 20;
for (int r = 1; r < 51; r++)
//rows
{
int gridscore = 0;
lp1Radius = (float)Math.Sqrt(Math.Pow(hax[0] - xg, 2) + Math.Pow(hay[0] - yg, 2));
lp2Radius = (float)Math.Sqrt(Math.Pow(hax[1] - xg, 2) + Math.Pow(hay[1] - yg, 2));
lp3Radius = (float)Math.Sqrt(Math.Pow(hax[2] - xg, 2) + Math.Pow(hay[2] - yg, 2));
lp4Radius = (float)Math.Sqrt(Math.Pow(hax[3] - xg, 2) + Math.Pow(hay[3] - yg, 2));
lp5Radius = (float)Math.Sqrt(Math.Pow(hax[4] - xg, 2) + Math.Pow(hay[4] - yg, 2));
lp6Radius = (float)Math.Sqrt(Math.Pow(hax[5] - xg, 2) + Math.Pow(hay[5] - yg, 2));
lp7Radius = (float)Math.Sqrt(Math.Pow(hax[6] - xg, 2) + Math.Pow(hay[6] - yg, 2));
lp8Radius = (float)Math.Sqrt(Math.Pow(hax[7] - xg, 2) + Math.Pow(hay[7] - yg, 2));
if (lp1Radius <= locatorRadius)
{
theta1 = (float)(Math.Acos(Math.Abs(hax[0] - xg) / lp1Radius) * (180 * 7 / 22));
theta = (float)(Math.Acos(Math.Abs(hay[0] - yg) / lp1Radius) * (180 * 7 / 22));
theta2 = theta + 90;
theta3 = theta1 + 180;
theta4 = 270 + theta;
if (xg >= hax[0] && yg >= hay[0]) //Region 1
{
if (theta1 >= hsa[0] && theta1 <= (hsa[0] + 10)) gridscore++;
}
else if (xg <= hax[0] && yg >= hay[0]) //Region 2
{
if (theta2 >= hsa[0] && theta2 <= (hsa[0] + 10)) gridscore++;
}
else if (xg <= hax[0] && yg <= hay[0]) //Region 3
{
if (theta3 >= hsa[0] && theta3 <= (hsa[0] + 10)) gridscore++;
}
else if (xg >= hax[0] && yg <= hay[0]) //Region 4
{
if (theta4 >= hsa[0] && theta4 <= (hsa[0] + 10)) gridscore++;
}
}
float
float
float
float
float
float
float
float
float
float
}
else if (xg >= hax[1] && yg <= hay[1]) //Region 4
{
if (theta4 >= hsa[1] && theta4 <= (hsa[1] + 10)) gridscore++;
}
}
if (lp3Radius <= locatorRadius)
{
theta1 = (float)(Math.Acos(Math.Abs(hax[2] - xg) / lp3Radius) * (180 * 7 / 22));
theta = (float)(Math.Acos(Math.Abs(hay[2] - yg) / lp3Radius) * (180 * 7 / 22));
theta2 = theta + 90;
theta3 = theta1 + 180;
theta4 = 270 + theta;
if (xg >= hax[2] && yg >= hay[2]) //Region 1
{
if (theta1 >= hsa[2] && theta1 <= (hsa[2] + 10)) gridscore++;
}
else if (xg <= hax[2] && yg >= hay[2]) //Region 2
{
if (theta2 >= hsa[2] && theta2 <= (hsa[2] + 10)) gridscore++;
}
else if (xg <= hax[2] && yg <= hay[2]) //Region 3
{
if (theta3 >= hsa[2] && theta3 <= (hsa[2] + 10)) gridscore++;
float
float
float
float
float
}
else if (xg >= hax[2] && yg <= hay[2]) //Region 4
{
if (theta4 >= hsa[2] && theta4 <= (hsa[2] + 10)) gridscore++;
}
}
if (lp4Radius <= locatorRadius)
{
theta1 = (float)(Math.Acos(Math.Abs(hax[3] - xg) / lp4Radius) * (180 * 7 / 22));
theta = (float)(Math.Acos(Math.Abs(hay[3] - yg) / lp4Radius) * (180 * 7 / 22));
theta2 = theta + 90;
theta3 = theta1 + 180;
theta4 = 270 + theta;
float
float
float
float
float
}
else if (xg >= hax[3] && yg <= hay[3]) //Region 4
{
if (theta4 >= hsa[3] && theta4 <= (hsa[3] + 10)) gridscore++;
}
}
if (lp5Radius <= locatorRadius)
{
theta1 = (float)(Math.Acos(Math.Abs(hax[4] - xg) / lp5Radius) * (180 * 7 / 22));
theta = (float)(Math.Acos(Math.Abs(hay[4] - yg) / lp5Radius) * (180 * 7 / 22));
theta2 = theta + 90;
theta3 = theta1 + 180;
theta4 = 270 + theta;
if (xg >= hax[4] && yg >= hay[4]) //Region 1
{
if (theta1 >= hsa[4] && theta1 <= (hsa[4] + 10)) gridscore++;
}
else if (xg <= hax[4] && yg >= hay[4]) //Region 2
{
if (theta2 >= hsa[4] && theta2 <= (hsa[4] + 10)) gridscore++;
}
else if (xg <= hax[4] && yg <= hay[4]) //Region 3
{
if (theta3 >= hsa[4] && theta3 <= (hsa[4] + 10)) gridscore++;
float
float
float
float
float
}
else if (xg >= hax[4] && yg <= hay[4]) //Region 4
{
if (theta4 >= hsa[4] && theta4 <= (hsa[4] + 10)) gridscore++;
}
}
if (lp6Radius <= locatorRadius)
{
theta1 = (float)(Math.Acos(Math.Abs(hax[5] - xg) / lp6Radius) * (180 * 7 / 22));
theta = (float)(Math.Acos(Math.Abs(hay[5] - yg) / lp6Radius) * (180 * 7 / 22));
theta2 = theta + 90;
theta3 = theta1 + 180;
theta4 = 270 + theta;
float
float
float
float
float
}
else if (xg >= hax[5] && yg <= hay[5]) //Region 4
{
if (theta4 >= hsa[5] && theta4 <= (hsa[5] + 10)) gridscore++;
}
}
if (lp7Radius <= locatorRadius)
{
theta1 = (float)(Math.Acos(Math.Abs(hax[6] - xg) / lp7Radius) * (180 * 7 / 22));
theta = (float)(Math.Acos(Math.Abs(hay[6] - yg) / lp7Radius) * (180 * 7 / 22));
theta2 = theta + 90;
theta3 = theta1 + 180;
theta4 = 270 + theta;
if (xg >= hax[6] && yg >= hay[6]) //Region 1
{
if (theta1 >= hsa[6] && theta1 <= (hsa[6] + 10)) gridscore++;
}
else if (xg <= hax[6] && yg >= hay[6]) //Region 2
{
if (theta2 >= hsa[6] && theta2 <= (hsa[6] + 10)) gridscore++;
}
else if (xg <= hax[6] && yg <= hay[6]) //Region 3
{
if (theta3 >= hsa[6] && theta3 <= (hsa[6] + 10)) gridscore++;
float
float
float
float
float
}
else if (xg >= hax[6] && yg <= hay[6]) //Region 4
{
if (theta4 >= hsa[6] && theta4 <= (hsa[6] + 10)) gridscore++;
}
}
if (lp8Radius <= locatorRadius)
{
theta1 = (float)(Math.Acos(Math.Abs(hax[7] - xg) / lp8Radius) * (180 * 7 / 22));
theta = (float)(Math.Acos(Math.Abs(hay[7] - yg) / lp8Radius) * (180 * 7 / 22));
theta2 = theta + 90;
theta3 = theta1 + 180;
theta4 = 270 + theta;
d++;
}
The above code is for eight locators' intersection, the rest of the code is the same but with seven,
six, five, four, three, and two locators' intersection. The estimated position is calculated and
painted, then it will be written to an Excel file a shown below:
end = System.DateTime.Now.Ticks;
executiontime = end - start;
time = " " + (double)(executiontime / 10000);
using (StreamWriter w = new StreamWriter (textbox,false,Encoding.UTF8))
{
w.WriteLine("LHs" + "," + "Node" + "," + "X Estimated" + "," + "Y Estimated" + "," +
"X Actual" + "," + "Y Actual" + "," + "Ex" + "," + "Ey" + "," + "Error");
w.WriteLine("Two" + op2 + "No. of Sensors =" + "," + opc2 + "\nThree" + op3 + "No. of
Sensors =" + "," + opc3 + "\nFour" + op4 + "No. of Sensors =" + "," + opc4 + "\nFive" +
op5 + "No. of Sensors =" + "," + opc5 + "\nSix" + op6 + "No. of Sensors =" + "," + opc6
+ "\nSeven" + op7 + "No. of Sensors =" + "," + opc7 + "\nEight" + op8 + "No. of Sensors
=" + "," + opc8 + "\n Execution Time = " + time + " ms");
}
}
9
2
6
8
3
4
10
Figure 5: Steps of HiRloc Localization
Output File:
2- The network can be deployed based on a wide range of parameters: network size, sensor nodes
communication distance, locator radius (communication range), sector angle (rotation angle) and
locator beam width.
3- Supports Multithreading, where the simulated algorithm runs on a separate thread from the
thread controlling the developer interface.
4- Packaging all simulator classes into a referenced DLL file for better modularity design.
5- Ease of implementing various localization algorithms by encapsulating each one into a
separate DLL file. Developers can write their own localization algorithm into a DLL file and
reference it into our framework.
6- Can be extended to implement many different localization algorithms with different categories
(range-free, range-based and a hybrid of both).
7- Suitable developer interface to enable deploying and moving sensor and locator nodes and
changing various simulation parameters.
CONCLUSION
We have presented a framework to develop WSN localization algorithms. The framework allows
developers to design the required localization algorithm by writing the code into a class library
file and referencing it to the framework. Our framework has been validated using different types
of localization algorithms: range-free, range-based and hybrid localization for WSNs. Our
framework results had been compared to the selected localization algorithms results and it was
found that they were compatible with the original results of these algorithms in their papers. Our
framework can be extended to implement other localization algorithms and can be used by future
researchers.
History
This is a Wireless Sensor Network Localization Simulator v1.1 written by Abdelhady
Mohammad Naguib in May 2011. Thank you for using the WSN Localization Simulator.