#include <MassMobility.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 | move () |
Move the host. | |
Protected Attributes | |
cPar * | changeInterval |
cPar * | changeAngleBy |
cPar * | speed |
double | currentSpeed |
speed of the host | |
double | currentAngle |
angle of linear motion | |
double | updateInterval |
time interval to update the hosts position | |
Coord | step |
calculated from speed, angle and updateInterval |
void MassMobility::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.
00038 { 00039 BasicMobility::initialize(stage); 00040 00041 EV << "initializing MassMobility stage " << stage << endl; 00042 00043 if (stage == 0) 00044 { 00045 updateInterval = par("updateInterval"); 00046 00047 changeInterval = &par("changeInterval"); 00048 changeAngleBy = &par("changeAngleBy"); 00049 speed = &par("speed"); 00050 00051 // initial speed and angle 00052 currentSpeed = speed->doubleValue(); 00053 currentAngle = uniform(0, 360); 00054 step.x = currentSpeed * cos(PI * currentAngle / 180) * updateInterval; 00055 step.y = currentSpeed * sin(PI * currentAngle / 180) * updateInterval; 00056 00057 scheduleAt(simTime() + uniform(0, updateInterval), new cMessage("move", MK_UPDATE_POS)); 00058 scheduleAt(simTime() + uniform(0, changeInterval->doubleValue()), new cMessage("turn", MK_CHANGE_DIR)); 00059 } 00060 }
void MassMobility::handleSelfMsg | ( | cMessage * | msg | ) | [protected, virtual] |
Called upon arrival of a self messages.
The only self message possible is to indicate a new movement.
Implements BasicMobility.
00067 { 00068 switch (msg->getKind()) 00069 { 00070 case MK_UPDATE_POS: 00071 move(); 00072 updatePosition(); 00073 scheduleAt(simTime() + updateInterval, msg); 00074 break; 00075 case MK_CHANGE_DIR: 00076 currentAngle += changeAngleBy->doubleValue(); 00077 currentSpeed = speed->doubleValue(); 00078 step.x = currentSpeed * cos(PI * currentAngle / 180) * updateInterval; 00079 step.y = currentSpeed * sin(PI * currentAngle / 180) * updateInterval; 00080 scheduleAt(simTime() + changeInterval->doubleValue(), msg); 00081 break; 00082 default: 00083 opp_error("Unknown self message kind in MassMobility class"); 00084 break; 00085 } 00086 00087 }
void MassMobility::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().
00094 { 00095 pos += step; 00096 00097 // do something if we reach the wall 00098 Coord dummy; 00099 handleIfOutside(REFLECT, dummy, step, currentAngle); 00100 00101 EV << " xpos= " << pos.x << " ypos=" << pos.y << " speed=" << currentSpeed << endl; 00102 }
cPar* MassMobility::changeInterval [protected] |
Referenced by handleSelfMsg(), and initialize().
cPar* MassMobility::changeAngleBy [protected] |
Referenced by handleSelfMsg(), and initialize().
cPar* MassMobility::speed [protected] |
Referenced by handleSelfMsg(), and initialize().
double MassMobility::currentSpeed [protected] |
double MassMobility::currentAngle [protected] |
double MassMobility::updateInterval [protected] |
Coord MassMobility::step [protected] |
calculated from speed, angle and updateInterval
Referenced by handleSelfMsg(), initialize(), and move().