|
INET Framework for OMNeT++/OMNEST
|
Rectangle movement model. See NED file for more info. More...
#include <RectangleMobility.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. | |
| virtual void | calculateXY () |
| Maps d to (x,y) coordinates. | |
Protected Attributes | |
| double | x1 |
| double | y1 |
| double | x2 |
| double | y2 |
| rectangle bounds | |
| double | speed |
| speed of the host | |
| double | updateInterval |
| time interval to update the hosts position | |
| bool | stationary |
| if true, the host doesn't move | |
| double | d |
| distance from (x1,y1), measured clockwise on the perimeter | |
| double | corner1 |
| double | corner2 |
| double | corner3 |
| double | corner4 |
Rectangle movement model. See NED file for more info.
| void RectangleMobility::calculateXY | ( | ) | [protected, virtual] |
Maps d to (x,y) coordinates.
Referenced by initialize(), and move().
| void RectangleMobility::handleSelfMsg | ( | cMessage * | msg | ) | [protected, virtual] |
Called upon arrival of a self messages.
The only self message possible is to indicate a new movement. If host is stationary this function is never called.
Implements BasicMobility.
{
move();
updatePosition();
scheduleAt(simTime() + updateInterval, msg);
}
| void RectangleMobility::initialize | ( | int | stage | ) | [protected, virtual] |
Initializes mobility model parameters.
Reads the parameters. If the host is not stationary it calculates a random position and schedules a timer to trigger the first movement
Reimplemented from BasicMobility.
{
BasicMobility::initialize(stage);
EV << "initializing RectangleMobility stage " << stage << endl;
if (stage == 1)
{
x1 = par("x1");
y1 = par("y1");
x2 = par("x2");
y2 = par("y2");
updateInterval = par("updateInterval");
speed = par("speed");
// if the initial speed is lower than 0, the node is stationary
stationary = (speed == 0);
// calculate helper vars
double dx = x2-x1;
double dy = y2-y1;
corner1 = dx;
corner2 = corner1 + dy;
corner3 = corner2 + dx;
corner4 = corner3 + dy;
// determine start position
double startPos = par("startPos");
startPos = fmod(startPos,4);
if (startPos<1)
d = startPos*dx; // top side
else if (startPos<2)
d = corner1 + (startPos-1)*dy; // right side
else if (startPos<3)
d = corner2 + (startPos-2)*dx; // bottom side
else
d = corner3 + (startPos-3)*dy; // left side
calculateXY();
WATCH(d);
updatePosition();
// host moves the first time after some random delay to avoid synchronized movements
if (!stationary)
scheduleAt(simTime() + uniform(0, updateInterval), new cMessage("move"));
}
}
| void RectangleMobility::move | ( | ) | [protected, virtual] |
double RectangleMobility::corner1 [protected] |
Referenced by calculateXY(), and initialize().
double RectangleMobility::corner2 [protected] |
Referenced by calculateXY(), and initialize().
double RectangleMobility::corner3 [protected] |
Referenced by calculateXY(), and initialize().
double RectangleMobility::corner4 [protected] |
Referenced by initialize(), and move().
double RectangleMobility::d [protected] |
distance from (x1,y1), measured clockwise on the perimeter
Referenced by calculateXY(), initialize(), and move().
double RectangleMobility::speed [protected] |
speed of the host
Referenced by initialize(), and move().
bool RectangleMobility::stationary [protected] |
if true, the host doesn't move
Referenced by initialize().
double RectangleMobility::updateInterval [protected] |
time interval to update the hosts position
Referenced by handleSelfMsg(), initialize(), and move().
double RectangleMobility::x1 [protected] |
Referenced by calculateXY(), and initialize().
double RectangleMobility::x2 [protected] |
Referenced by calculateXY(), and initialize().
double RectangleMobility::y1 [protected] |
Referenced by calculateXY(), and initialize().
double RectangleMobility::y2 [protected] |
rectangle bounds
Referenced by calculateXY(), and initialize().