#include <LineSegmentsMobilityBase.h>
Inheritance diagram for LineSegmentsMobilityBase:
Subclasses must redefine setTargetPosition() which is suppsed to set a new target position and target time once the previous one is reached.
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 | |
double | 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 |
void LineSegmentsMobilityBase::beginNextMove | ( | cMessage * | msg | ) | [protected, virtual] |
Begin new line segment after previous one finished.
00040 { 00041 // go to exact position where previous statement was supposed to finish 00042 pos = targetPos; 00043 simtime_t now = targetTime; 00044 00045 // choose new targetTime and targetPos 00046 setTargetPosition(); 00047 00048 if (targetTime<now) 00049 error("LineSegmentsMobilityBase: targetTime<now was set in %s's beginNextMove()", className()); 00050 00051 if (stationary) 00052 { 00053 // end of movement 00054 step.x = step.y = 0; 00055 delete msg; 00056 } 00057 else if (targetPos==pos) 00058 { 00059 // no movement, just wait 00060 step.x = step.y = 0; 00061 scheduleAt(Max(targetTime,simTime()), msg); 00062 } 00063 else 00064 { 00065 // keep moving 00066 double numIntervals = (targetTime-now) / updateInterval; 00067 // int numSteps = floor(numIntervals); -- currently unused, 00068 // although we could use step counting instead of comparing 00069 // simTime() to targetTime each step. 00070 00071 // Note: step = speed*updateInterval = distance/time*updateInterval = 00072 // = (targetPos-pos) / (targetTime-now) * updateInterval = 00073 // = (targetPos-pos) / numIntervals 00074 step = (targetPos - pos) / numIntervals; 00075 scheduleAt(simTime() + updateInterval, msg); 00076 } 00077 }
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.
void LineSegmentsMobilityBase::handleSelfMsg | ( | cMessage * | msg | ) | [protected, virtual] |
Called upon arrival of a self messages.
Implements BasicMobility.
00080 { 00081 if (stationary) 00082 { 00083 delete msg; 00084 return; 00085 } 00086 else if (simTime()+updateInterval >= targetTime) 00087 { 00088 beginNextMove(msg); 00089 } 00090 else 00091 { 00092 scheduleAt(simTime() + updateInterval, msg); 00093 } 00094 00095 // update position 00096 pos += step; 00097 00098 // do something if we reach the wall 00099 fixIfHostGetsOutside(); 00100 00101 //EV << " xpos=" << pos.x << " ypos=" << pos.y << endl; 00102 00103 updatePosition(); 00104 }
void LineSegmentsMobilityBase::initialize | ( | int | ) | [protected, virtual] |
Initializes mobility model parameters.
Reimplemented from BasicMobility.
Reimplemented in ANSimMobility, BonnMotionMobility, RandomWPMobility, and TurtleMobility.
00024 { 00025 BasicMobility::initialize(stage); 00026 00027 if (stage == 1) 00028 { 00029 updateInterval = par("updateInterval"); 00030 stationary = false; 00031 targetPos = pos; 00032 targetTime = simTime(); 00033 00034 // host moves the first time after some random delay to avoid synchronized movements 00035 scheduleAt(simTime() + uniform(0, updateInterval), new cMessage("move")); 00036 } 00037 }
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.
bool LineSegmentsMobilityBase::stationary [protected] |
if set to true, host won't move
Coord LineSegmentsMobilityBase::step [protected] |
step size (added to pos every updateInterval)
Coord LineSegmentsMobilityBase::targetPos [protected] |
end position of current linear movement
double LineSegmentsMobilityBase::targetTime [protected] |
end time of current linear movement
double LineSegmentsMobilityBase::updateInterval [protected] |
time interval to update the host's position