#include <ConstSpeedMobility.h>
Inheritance diagram for ConstSpeedMobility:
Parameters to be specified in omnetpp.ini
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. | |
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 |
|
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 }
|
|
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 }
|
|
Move the host. Move the host if the destination is not reached yet. Otherwise calculate a new random position 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 }
|
|
Calculate the target position to move to. Calculate a new random position and the number of steps the host needs to reach this position 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 }
|
|
|
|
If true, the host doesn't move.
|
|
|
|
|
|
parameters to handle the movement of the host
|
|
Time interval to update the hosts position.
|
|
Velocity of the host.
|