RectangleMobility Class Reference

#include <RectangleMobility.h>

Inheritance diagram for RectangleMobility:

BasicMobility BasicModule INotifiable

List of all members.


Detailed Description

Rectangle movement model. See NED file for more info.

Author:
Andras Varga

Protected Member Functions

virtual void initialize (int)
 Initializes mobility model parameters.
virtual void handleSelfMsg (cMessage *msg)
 Called upon arrival of a self messages.
virtual void move ()
 Move the host.
virtual void calculateXY ()
 Maps d to (x,y) coordinates.

Protected Attributes

double x1
double y1
double x2
double y2
 rectangle bounds
double speed
 speed of the host
double updateInterval
 time interval to update the hosts position
bool stationary
 if true, the host doesn't move
double d
 distance from (x1,y1), measured clockwise on the perimeter
double corner1
double corner2
double corner3
double corner4

Member Function Documentation

void RectangleMobility::initialize ( int  stage  )  [protected, virtual]

Initializes mobility model parameters.

Reads the parameters. If the host is not stationary it calculates a random position and schedules a timer to trigger the first movement

Reimplemented from BasicMobility.

00031 {
00032     BasicMobility::initialize(stage);
00033 
00034     EV << "initializing RectangleMobility stage " << stage << endl;
00035 
00036     if (stage == 1)
00037     {
00038         x1 = par("x1");
00039         y1 = par("y1");
00040         x2 = par("x2");
00041         y2 = par("y2");
00042         updateInterval = par("updateInterval");
00043         speed = par("speed");
00044 
00045         // if the initial speed is lower than 0, the node is stationary
00046         stationary = (speed == 0);
00047 
00048         // calculate helper vars
00049         double dx = x2-x1;
00050         double dy = y2-y1;
00051         corner1 = dx;
00052         corner2 = corner1 + dy;
00053         corner3 = corner2 + dx;
00054         corner4 = corner3 + dy;
00055 
00056         // determine start position
00057         double startPos = par("startPos");
00058         startPos = fmod(startPos,4);
00059         if (startPos<1)
00060             d = startPos*dx; // top side
00061         else if (startPos<2)
00062             d = corner1 + (startPos-1)*dy; // right side
00063         else if (startPos<3)
00064             d = corner2 + (startPos-2)*dx; // bottom side
00065         else
00066             d = corner3 + (startPos-3)*dy; // left side
00067         calculateXY();
00068         WATCH(d);
00069         updatePosition();
00070 
00071         // host moves the first time after some random delay to avoid synchronized movements
00072         if (!stationary)
00073             scheduleAt(simTime() + uniform(0, updateInterval), new cMessage("move"));
00074     }
00075 }

void RectangleMobility::handleSelfMsg ( cMessage *  msg  )  [protected, virtual]

Called upon arrival of a self messages.

The only self message possible is to indicate a new movement. If host is stationary this function is never called.

Implements BasicMobility.

00083 {
00084     move();
00085     updatePosition();
00086     scheduleAt(simTime() + updateInterval, msg);
00087 }

void RectangleMobility::move (  )  [protected, virtual]

Move the host.

Referenced by handleSelfMsg().

00090 {
00091     d += speed * updateInterval;
00092     while (d<0) d+=corner4;
00093     while (d>=corner4) d-=corner4;
00094 
00095     calculateXY();
00096     EV << " xpos= " << pos.x << " ypos=" << pos.y << " speed=" << speed << endl;
00097 }

void RectangleMobility::calculateXY (  )  [protected, virtual]

Maps d to (x,y) coordinates.

Referenced by initialize(), and move().

00100 {
00101     if (d < corner1)
00102     {
00103         // top side
00104         pos.x = x1 + d;
00105         pos.y = y1;
00106     }
00107     else if (d < corner2)
00108     {
00109         // right side
00110         pos.x = x2;
00111         pos.y = y1 + d - corner1;
00112     }
00113     else if (d < corner3)
00114     {
00115         // bottom side
00116         pos.x = x2 - d + corner2;
00117         pos.y = y2;
00118     }
00119     else
00120     {
00121         // left side
00122         pos.x = x1;
00123         pos.y = y2 - d + corner3;
00124     }
00125 }


Member Data Documentation

double RectangleMobility::x1 [protected]

Referenced by calculateXY(), and initialize().

double RectangleMobility::y1 [protected]

Referenced by calculateXY(), and initialize().

double RectangleMobility::x2 [protected]

Referenced by calculateXY(), and initialize().

double RectangleMobility::y2 [protected]

rectangle bounds

Referenced by calculateXY(), and initialize().

double RectangleMobility::speed [protected]

speed of the host

Referenced by initialize(), and move().

time interval to update the hosts position

Referenced by handleSelfMsg(), initialize(), and move().

if true, the host doesn't move

Referenced by initialize().

double RectangleMobility::d [protected]

distance from (x1,y1), measured clockwise on the perimeter

Referenced by calculateXY(), initialize(), and move().

double RectangleMobility::corner1 [protected]

Referenced by calculateXY(), and initialize().

double RectangleMobility::corner2 [protected]

Referenced by calculateXY(), and initialize().

double RectangleMobility::corner3 [protected]

Referenced by calculateXY(), and initialize().

double RectangleMobility::corner4 [protected]

Referenced by initialize(), and move().


The documentation for this class was generated from the following files:

Generated on Fri Mar 20 18:51:20 2009 for INET Framework for OMNeT++/OMNEST by  doxygen 1.5.5