INET Framework for OMNeT++/OMNEST
|
Controls all movement related things of a host. More...
#include <ConstSpeedMobility.h>
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 |
Controls all movement related things of a host.
Parameters to be specified in omnetpp.ini
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().
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; }
int ConstSpeedMobility::numSteps [protected] |
Referenced by move(), and setTargetPosition().
bool ConstSpeedMobility::stationary [protected] |
If true, the host doesn't move.
Referenced by initialize().
int ConstSpeedMobility::step [protected] |
Referenced by move(), and setTargetPosition().
Coord ConstSpeedMobility::stepSize [protected] |
Referenced by move(), and setTargetPosition().
Coord ConstSpeedMobility::targetPos [protected] |
parameters to handle the movement of the host
Referenced by setTargetPosition().
double ConstSpeedMobility::updateInterval [protected] |
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().