INET Framework for OMNeT++/OMNEST
LinearMobility Class Reference

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

#include <LinearMobility.h>

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

double speed
 speed of the host
double angle
 angle of linear motion
double acceleration
 acceleration of linear motion
double updateInterval
 time interval to update the hosts position
bool stationary
 if true, the host doesn't move

Detailed Description

Linear movement model. See NED file for more info.

Author:
Emin Ilker Cetinbas

Definition at line 32 of file LinearMobility.h.


Member Function Documentation

void LinearMobility::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.

Definition at line 54 of file LinearMobility.cc.

{
    move();
    updatePosition();
    if (!stationary)
        scheduleAt(simTime() + updateInterval, msg);
}
void LinearMobility::initialize ( int  stage) [protected, virtual]

Initializes mobility model parameters.

Reimplemented from BasicMobility.

Definition at line 26 of file LinearMobility.cc.

{
    BasicMobility::initialize(stage);

    EV << "initializing LinearMobility stage " << stage << endl;

    if (stage == 0)
    {
        updateInterval = par("updateInterval");
        speed = par("speed");
        angle = par("angle");
        acceleration = par("acceleration");
        angle = fmod(angle,360);

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

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

Move the host.

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

Definition at line 66 of file LinearMobility.cc.

Referenced by handleSelfMsg().

{
    pos.x += speed * cos(PI * angle / 180) * updateInterval;
    pos.y += speed * sin(PI * angle / 180) * updateInterval;

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

    // accelerate
    speed += acceleration * updateInterval;
    if (speed <= 0)
    {
        speed = 0;
        stationary = true;
    }

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

Member Data Documentation

double LinearMobility::acceleration [protected]

acceleration of linear motion

Definition at line 37 of file LinearMobility.h.

Referenced by initialize(), and move().

double LinearMobility::angle [protected]

angle of linear motion

Definition at line 36 of file LinearMobility.h.

Referenced by initialize(), and move().

double LinearMobility::speed [protected]

speed of the host

Definition at line 35 of file LinearMobility.h.

Referenced by initialize(), and move().

bool LinearMobility::stationary [protected]

if true, the host doesn't move

Definition at line 39 of file LinearMobility.h.

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

double LinearMobility::updateInterval [protected]

time interval to update the hosts position

Definition at line 38 of file LinearMobility.h.

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


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