INET Framework for OMNeT++/OMNEST
RectangleMobility Class Reference

Rectangle movement model. See NED file for more info. More...

#include <RectangleMobility.h>

Inheritance diagram for RectangleMobility:
BasicMobility BasicModule INotifiable

List of all members.

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

Detailed Description

Rectangle movement model. See NED file for more info.

Author:
Andras Varga

Member Function Documentation

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

Maps d to (x,y) coordinates.

Referenced by initialize(), and move().

{
    if (d < corner1)
    {
        // top side
        pos.x = x1 + d;
        pos.y = y1;
    }
    else if (d < corner2)
    {
        // right side
        pos.x = x2;
        pos.y = y1 + d - corner1;
    }
    else if (d < corner3)
    {
        // bottom side
        pos.x = x2 - d + corner2;
        pos.y = y2;
    }
    else
    {
        // left side
        pos.x = x1;
        pos.y = y2 - d + corner3;
    }
}
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.

{
    move();
    updatePosition();
    scheduleAt(simTime() + updateInterval, msg);
}
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.

{
    BasicMobility::initialize(stage);

    EV << "initializing RectangleMobility stage " << stage << endl;

    if (stage == 1)
    {
        x1 = par("x1");
        y1 = par("y1");
        x2 = par("x2");
        y2 = par("y2");
        updateInterval = par("updateInterval");
        speed = par("speed");

        // if the initial speed is lower than 0, the node is stationary
        stationary = (speed == 0);

        // calculate helper vars
        double dx = x2-x1;
        double dy = y2-y1;
        corner1 = dx;
        corner2 = corner1 + dy;
        corner3 = corner2 + dx;
        corner4 = corner3 + dy;

        // determine start position
        double startPos = par("startPos");
        startPos = fmod(startPos,4);
        if (startPos<1)
            d = startPos*dx; // top side
        else if (startPos<2)
            d = corner1 + (startPos-1)*dy; // right side
        else if (startPos<3)
            d = corner2 + (startPos-2)*dx; // bottom side
        else
            d = corner3 + (startPos-3)*dy; // left side
        calculateXY();
        WATCH(d);
        updatePosition();

        // host moves the first time after some random delay to avoid synchronized movements
        if (!stationary)
            scheduleAt(simTime() + uniform(0, updateInterval), new cMessage("move"));
    }
}
void RectangleMobility::move ( ) [protected, virtual]

Move the host.

Referenced by handleSelfMsg().

{
    d += speed * updateInterval;
    while (d<0) d+=corner4;
    while (d>=corner4) d-=corner4;

    calculateXY();
    EV << " xpos= " << pos.x << " ypos=" << pos.y << " speed=" << speed << endl;
}

Member Data Documentation

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().

double RectangleMobility::d [protected]

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

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

double RectangleMobility::speed [protected]

speed of the host

Referenced by initialize(), and move().

if true, the host doesn't move

Referenced by initialize().

time interval to update the hosts position

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

double RectangleMobility::x1 [protected]

Referenced by calculateXY(), and initialize().

double RectangleMobility::x2 [protected]

Referenced by calculateXY(), and initialize().

double RectangleMobility::y1 [protected]

Referenced by calculateXY(), and initialize().

double RectangleMobility::y2 [protected]

rectangle bounds

Referenced by calculateXY(), and initialize().


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