ConstSpeedMobility Class Reference

#include <ConstSpeedMobility.h>

Inheritance diagram for ConstSpeedMobility:

BasicMobility BasicModule INotifiable

List of all members.


Detailed Description

Controls all movement related things of a host.

Parameters to be specified in omnetpp.ini

Author:
Steffen Sroka, Marc Loebbers, Daniel Willkomm
See also:
ChannelControl

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

Member Function Documentation

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.

00036 {
00037     BasicMobility::initialize(stage);
00038 
00039     EV << "initializing ConstSpeedMobility stage " << stage << endl;
00040 
00041     if (stage == 0)
00042     {
00043         updateInterval = par("updateInterval");
00044         vHost = par("vHost");
00045 
00046         // if the initial speed is lower than 0, the node is stationary
00047         stationary = (vHost <= 0);
00048 
00049         //calculate the target position of the host if the host moves
00050         if (!stationary)
00051         {
00052             setTargetPosition();
00053             //host moves the first time after some random delay to avoid synchronized movements
00054             scheduleAt(simTime() + uniform(0, updateInterval), new cMessage("move"));
00055         }
00056     }
00057 }

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.

00065 {
00066     move();
00067     updatePosition();
00068     scheduleAt(simTime() + updateInterval, msg);
00069 }

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

00077 {
00078     targetPos = getRandomPosition();
00079     double distance = pos.distance(targetPos);
00080     double totalTime = distance / vHost;
00081     numSteps = FWMath::round(totalTime / updateInterval);
00082 
00083     stepSize = (targetPos - pos) / numSteps;
00084 
00085     step = 0;
00086 
00087     EV << "distance=" << distance << " xpos= " << targetPos.x << " ypos=" << targetPos.y
00088         << "totalTime=" << totalTime << " numSteps=" << numSteps << " vHost=" << vHost << endl;
00089 }

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

00097 {
00098     step++;
00099 
00100     if (step <= numSteps)
00101     {
00102         EV << "stepping forward. step #=" << step << " xpos= " << pos.x << " ypos=" << pos.
00103             y << endl;
00104 
00105         pos += stepSize;
00106     }
00107     else
00108     {
00109         EV << "destination reached.\n xpos= " << pos.x << " ypos=" << pos.y << endl;
00110 
00111         setTargetPosition();
00112     }
00113 }


Member Data Documentation

double ConstSpeedMobility::vHost [protected]

Velocity of the host.

Referenced by initialize(), and setTargetPosition().

Time interval to update the hosts position.

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

If true, the host doesn't move.

Referenced by initialize().

parameters to handle the movement of the host

Referenced by setTargetPosition().

Referenced by move(), and setTargetPosition().

Referenced by move(), and setTargetPosition().

int ConstSpeedMobility::step [protected]

Referenced by move(), and setTargetPosition().


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

Generated on Fri Mar 20 18:51:18 2009 for INET Framework for OMNeT++/OMNEST by  doxygen 1.5.5