INET Framework for OMNeT++/OMNEST
ConstSpeedMobility Class Reference

Controls all movement related things of a host. More...

#include <ConstSpeedMobility.h>

Inheritance diagram for ConstSpeedMobility:
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 setTargetPosition ()
 Calculate the target position to move to.
virtual void move ()
 Move the host.

Protected Attributes

double vHost
 Velocity of the host.
double updateInterval
 Time interval to update the hosts position.
bool stationary
 If true, the host doesn't move.
Coord targetPos
 parameters to handle the movement of the host
Coord stepSize
int numSteps
int step

Detailed Description

Controls all movement related things of a host.

Parameters to be specified in omnetpp.ini

  • vHost : Speed of a host [m/s]
  • updateInterval : Time interval to update the hosts position
  • x, y : Starting position of the host, -1 = random
Author:
Steffen Sroka, Marc Loebbers, Daniel Willkomm
See also:
ChannelControl

Member Function Documentation

void ConstSpeedMobility::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 ConstSpeedMobility::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 ConstSpeedMobility stage " << stage << endl;

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

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

        //calculate the target position of the host if the host moves
        if (!stationary)
        {
            setTargetPosition();
            //host moves the first time after some random delay to avoid synchronized movements
            scheduleAt(simTime() + uniform(0, updateInterval), new cMessage("move"));
        }
    }
}
void ConstSpeedMobility::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().

{
    step++;

    if (step <= numSteps)
    {
        EV << "stepping forward. step #=" << step << " xpos= " << pos.x << " ypos=" << pos.
            y << endl;

        pos += stepSize;
    }
    else
    {
        EV << "destination reached.\n xpos= " << pos.x << " ypos=" << pos.y << endl;

        setTargetPosition();
    }
}
void ConstSpeedMobility::setTargetPosition ( ) [protected, virtual]

Calculate the target position to move to.

Calculate a new random position and the number of steps the host needs to reach this position

Referenced by initialize(), and move().

{
    targetPos = getRandomPosition();
    double distance = pos.distance(targetPos);
    double totalTime = distance / vHost;
    numSteps = FWMath::round(totalTime / updateInterval);

    stepSize = (targetPos - pos) / numSteps;

    step = 0;

    EV << "distance=" << distance << " xpos= " << targetPos.x << " ypos=" << targetPos.y
        << "totalTime=" << totalTime << " numSteps=" << numSteps << " vHost=" << vHost << endl;
}

Member Data Documentation

Referenced by move(), and setTargetPosition().

If true, the host doesn't move.

Referenced by initialize().

int ConstSpeedMobility::step [protected]

Referenced by move(), and setTargetPosition().

parameters to handle the movement of the host

Referenced by setTargetPosition().

Time interval to update the hosts position.

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

double ConstSpeedMobility::vHost [protected]

Velocity of the host.

Referenced by initialize(), and setTargetPosition().


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