#include <MassMobility.h>
Inheritance diagram for MassMobility:

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