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.
void move ()
 Move the host.
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::calculateXY (  )  [protected]

Maps d to (x,y) coordinates.

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

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.

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

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.

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

void RectangleMobility::move (  )  [protected]

Move the host.

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


Member Data Documentation

double RectangleMobility::corner1 [protected]

double RectangleMobility::corner2 [protected]

double RectangleMobility::corner3 [protected]

double RectangleMobility::corner4 [protected]

double RectangleMobility::d [protected]

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

double RectangleMobility::speed [protected]

speed of the host

bool RectangleMobility::stationary [protected]

if true, the host doesn't move

double RectangleMobility::updateInterval [protected]

time interval to update the hosts position

double RectangleMobility::x1 [protected]

double RectangleMobility::x2 [protected]

double RectangleMobility::y1 [protected]

double RectangleMobility::y2 [protected]

rectangle bounds


The documentation for this class was generated from the following files:
Generated on Wed Apr 4 13:20:23 2007 for INET Framework for OMNeT++/OMNEST by  doxygen 1.4.7