INET Framework for OMNeT++/OMNEST
MassMobility Class Reference

Models the mobility of with mass, making random motions. See NED file for more info. More...

#include <MassMobility.h>

Inheritance diagram for MassMobility:
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.

Protected Attributes

cPar * changeInterval
cPar * changeAngleBy
cPar * speed
double currentSpeed
 speed of the host
double currentAngle
 angle of linear motion
double updateInterval
 time interval to update the hosts position
Coord step
 calculated from speed, angle and updateInterval

Detailed Description

Models the mobility of with mass, making random motions. See NED file for more info.

Author:
Emin Ilker Cetinbas, Andras Varga

Member Function Documentation

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

Called upon arrival of a self messages.

The only self message possible is to indicate a new movement.

Implements BasicMobility.

{
    switch (msg->getKind())
    {
    case MK_UPDATE_POS:
        move();
        updatePosition();
        scheduleAt(simTime() + updateInterval, msg);
        break;
    case MK_CHANGE_DIR:
        currentAngle += changeAngleBy->doubleValue();
        currentSpeed = speed->doubleValue();
        step.x = currentSpeed * cos(PI * currentAngle / 180) * updateInterval;
        step.y = currentSpeed * sin(PI * currentAngle / 180) * updateInterval;
        scheduleAt(simTime() + changeInterval->doubleValue(), msg);
        break;
    default:
        opp_error("Unknown self message kind in MassMobility class");
        break;
    }

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

Initializes mobility model parameters.

Reads the updateInterval and the velocity

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 MassMobility stage " << stage << endl;

    if (stage == 0)
    {
        updateInterval = par("updateInterval");

        changeInterval = &par("changeInterval");
        changeAngleBy = &par("changeAngleBy");
        speed = &par("speed");

        // initial speed and angle
        currentSpeed = speed->doubleValue();
        currentAngle = uniform(0, 360);
        step.x = currentSpeed * cos(PI * currentAngle / 180) * updateInterval;
        step.y = currentSpeed * sin(PI * currentAngle / 180) * updateInterval;

        scheduleAt(simTime() + uniform(0, updateInterval), new cMessage("move", MK_UPDATE_POS));
        scheduleAt(simTime() + uniform(0, changeInterval->doubleValue()), new cMessage("turn", MK_CHANGE_DIR));
    }
}
void MassMobility::move ( ) [protected, virtual]

Move the host.

Move the host if the destination is not reached yet. Otherwise calculate a new random position

Referenced by handleSelfMsg().

{
    pos += step;

    // do something if we reach the wall
    Coord dummy;
    handleIfOutside(REFLECT, dummy, step, currentAngle);

    EV << " xpos= " << pos.x << " ypos=" << pos.y << " speed=" << currentSpeed << endl;
}

Member Data Documentation

cPar* MassMobility::changeAngleBy [protected]

Referenced by handleSelfMsg(), and initialize().

cPar* MassMobility::changeInterval [protected]

Referenced by handleSelfMsg(), and initialize().

double MassMobility::currentAngle [protected]

angle of linear motion

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

double MassMobility::currentSpeed [protected]

speed of the host

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

cPar* MassMobility::speed [protected]

Referenced by handleSelfMsg(), and initialize().

calculated from speed, angle and updateInterval

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

double MassMobility::updateInterval [protected]

time interval to update the hosts position

Referenced by handleSelfMsg(), and initialize().


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