Controls all movement related things of a host. More...
#include <ConstSpeedMobility.h>
Inherits BaseMobility.
Public Member Functions | |
virtual void | initialize (int) |
Initializes mobility model parameters. | |
Protected Member Functions | |
virtual void | setTargetPosition () |
Calculate the target position to move to. | |
virtual void | makeMove () |
Move the host. | |
Protected Attributes | |
Coord | targetPos |
Coord | stepTarget |
parameters to handle the movement of the host | |
Coord | stepSize |
Size of a step. | |
int | numSteps |
Total number of steps. | |
int | step |
Number of steps already moved. |
Controls all movement related things of a host.
Parameters to be specified in omnetpp.ini
Definition at line 39 of file ConstSpeedMobility.h.
void ConstSpeedMobility::initialize | ( | int | stage | ) | [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 BaseMobility.
Definition at line 35 of file ConstSpeedMobility.cc.
References Move::getSpeed(), Move::getStartPos(), Move::info(), BaseMobility::move, numSteps, Move::setSpeed(), step, and stepSize.
{ BaseMobility::initialize(stage); if (stage == 0) { move.setSpeed(par("speed").doubleValue()); if(move.getSpeed() <= 0) move.setSpeed(0); numSteps = 0; step = -1; stepSize = Coord(0,0,0); debugEV << "Initialize: move speed: " << move.getSpeed() << " (" << par("speed").doubleValue() << ")" << " pos: " << move.info() << endl; } else if( stage == 1 ){ stepTarget = move.getStartPos(); } }
void ConstSpeedMobility::makeMove | ( | ) | [protected, virtual] |
Move the host.
Move the host if the destination is not reached yet. Otherwise calculate a new random position
Reimplemented from BaseMobility.
Definition at line 97 of file ConstSpeedMobility.cc.
References Move::getStartPos(), Move::info(), Coord::info(), BaseMobility::move, numSteps, Move::setStart(), setTargetPosition(), step, and stepSize.
{ // increment number of steps step++; if( step == numSteps ){ // last step //stepSize.x = // step forward move.setStart(stepTarget, simTime()); debugEV << "stepping forward. step #=" << step << " startPos: " << move.getStartPos().info() << endl; // get new target position debugEV << "destination reached.\n" << move.info() << endl; setTargetPosition(); } else if( step < numSteps ){ // step forward move.setStart(stepTarget, simTime()); stepTarget += stepSize; debugEV << "stepping forward. step #=" << step << " startPos: " << move.getStartPos().info() << endl; } else{ error("step cannot be bigger than numSteps"); } // fixIfHostGetsOutside(); }
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
Definition at line 62 of file ConstSpeedMobility.cc.
References Coord::distance(), BaseMobility::getRandomPosition(), Move::getSpeed(), Move::getStartPos(), Coord::info(), Move::info(), BaseMobility::move, numSteps, FWMath::round(), Move::setDirectionByTarget(), step, stepSize, and BaseMobility::updateInterval.
Referenced by makeMove().
{ debugEV << "start setTargetPosistion: " << move.info() << endl; do{ targetPos = getRandomPosition(); double distance = move.getStartPos().distance(targetPos); simtime_t totalTime = distance / move.getSpeed(); numSteps = FWMath::round(totalTime / updateInterval); debugEV << "new targetPos: " << targetPos.info() << " distance=" << distance << " totalTime=" << totalTime << " numSteps=" << numSteps << endl; } while( numSteps == 0 ); stepSize = targetPos - move.getStartPos(); stepSize = stepSize / numSteps; stepTarget = move.getStartPos() + stepSize; debugEV << "stepSize: " << stepSize.info() << " target: " << (stepSize*numSteps).info() << endl; step = 0; move.setDirectionByTarget(targetPos); debugEV << "end setTargetPosistion: " << move.info() << endl; }