INET Framework for OMNeT++/OMNEST
|
Base class for mobility models where movement consists of a sequence of linear movements of constant speed. More...
#include <LineSegmentsMobilityBase.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 | beginNextMove (cMessage *msg) |
Begin new line segment after previous one finished. | |
virtual void | setTargetPosition ()=0 |
Should be redefined in subclasses. This method gets called when targetPos and targetTime has been reached, and its task is to set a new targetPos and targetTime. At the end of the movement sequence, it should set targetTime=0. | |
virtual void | fixIfHostGetsOutside ()=0 |
Should be redefined in subclasses. Should invoke handleIfOutside(), or directly one of the methods it relies on. | |
Protected Attributes | |
double | updateInterval |
time interval to update the host's position | |
simtime_t | targetTime |
end time of current linear movement | |
Coord | targetPos |
end position of current linear movement | |
Coord | step |
step size (added to pos every updateInterval) | |
bool | stationary |
if set to true, host won't move |
Base class for mobility models where movement consists of a sequence of linear movements of constant speed.
Subclasses must redefine setTargetPosition() which is suppsed to set a new target position and target time once the previous one is reached.
void LineSegmentsMobilityBase::beginNextMove | ( | cMessage * | msg | ) | [protected, virtual] |
Begin new line segment after previous one finished.
Referenced by handleSelfMsg().
{ // go to exact position where previous statement was supposed to finish pos = targetPos; simtime_t now = targetTime; // choose new targetTime and targetPos setTargetPosition(); if (targetTime<now) error("LineSegmentsMobilityBase: targetTime<now was set in %s's beginNextMove()", getClassName()); if (stationary) { // end of movement step.x = step.y = 0; delete msg; } else if (targetPos==pos) { // no movement, just wait step.x = step.y = 0; scheduleAt(std::max(targetTime,simTime()), msg); } else { // keep moving double numIntervals = SIMTIME_DBL(targetTime-now) / updateInterval; // int numSteps = floor(numIntervals); -- currently unused, // although we could use step counting instead of comparing // simTime() to targetTime each step. // Note: step = speed*updateInterval = distance/time*updateInterval = // = (targetPos-pos) / (targetTime-now) * updateInterval = // = (targetPos-pos) / numIntervals step = (targetPos - pos) / numIntervals; scheduleAt(simTime() + updateInterval, msg); } }
virtual void LineSegmentsMobilityBase::fixIfHostGetsOutside | ( | ) | [protected, pure virtual] |
Should be redefined in subclasses. Should invoke handleIfOutside(), or directly one of the methods it relies on.
Implemented in ANSimMobility, BonnMotionMobility, RandomWPMobility, and TurtleMobility.
Referenced by handleSelfMsg().
void LineSegmentsMobilityBase::handleSelfMsg | ( | cMessage * | msg | ) | [protected, virtual] |
Called upon arrival of a self messages.
Implements BasicMobility.
{ if (stationary) { delete msg; return; } else if (simTime()+updateInterval >= targetTime) { beginNextMove(msg); } else { scheduleAt(simTime() + updateInterval, msg); } // update position pos += step; // do something if we reach the wall fixIfHostGetsOutside(); //EV << " xpos=" << pos.x << " ypos=" << pos.y << endl; updatePosition(); }
void LineSegmentsMobilityBase::initialize | ( | int | stage | ) | [protected, virtual] |
Initializes mobility model parameters.
Reimplemented from BasicMobility.
Reimplemented in ANSimMobility, BonnMotionMobility, RandomWPMobility, and TurtleMobility.
{ BasicMobility::initialize(stage); if (stage == 1) { updateInterval = par("updateInterval"); stationary = false; targetPos = pos; targetTime = simTime(); // host moves the first time after some random delay to avoid synchronized movements scheduleAt(simTime() + uniform(0, updateInterval), new cMessage("move")); } }
virtual void LineSegmentsMobilityBase::setTargetPosition | ( | ) | [protected, pure virtual] |
Should be redefined in subclasses. This method gets called when targetPos and targetTime has been reached, and its task is to set a new targetPos and targetTime. At the end of the movement sequence, it should set targetTime=0.
Implemented in ANSimMobility, BonnMotionMobility, RandomWPMobility, and TurtleMobility.
Referenced by beginNextMove().
bool LineSegmentsMobilityBase::stationary [protected] |
if set to true, host won't move
Referenced by beginNextMove(), handleSelfMsg(), RandomWPMobility::initialize(), initialize(), TurtleMobility::resumeScript(), BonnMotionMobility::setTargetPosition(), and ANSimMobility::setTargetPosition().
Coord LineSegmentsMobilityBase::step [protected] |
step size (added to pos every updateInterval)
Referenced by beginNextMove(), TurtleMobility::fixIfHostGetsOutside(), and handleSelfMsg().
Coord LineSegmentsMobilityBase::targetPos [protected] |
end position of current linear movement
Referenced by beginNextMove(), TurtleMobility::executeStatement(), ANSimMobility::extractDataFrom(), TurtleMobility::fixIfHostGetsOutside(), TurtleMobility::initialize(), initialize(), BonnMotionMobility::initialize(), ANSimMobility::initialize(), RandomWPMobility::setTargetPosition(), and BonnMotionMobility::setTargetPosition().
simtime_t LineSegmentsMobilityBase::targetTime [protected] |
end time of current linear movement
Referenced by beginNextMove(), TurtleMobility::executeStatement(), ANSimMobility::extractDataFrom(), handleSelfMsg(), TurtleMobility::initialize(), initialize(), TurtleMobility::resumeScript(), RandomWPMobility::setTargetPosition(), and BonnMotionMobility::setTargetPosition().
double LineSegmentsMobilityBase::updateInterval [protected] |
time interval to update the host's position
Referenced by beginNextMove(), handleSelfMsg(), and initialize().