Public Types | Public Member Functions | Protected Member Functions | Protected Attributes

MassMobility Class Reference
[mobility - modules handling the mobility of the hosts]

Models the mobility of with mass, making random motions. See NED file for more info. More...

#include <MassMobility.h>

Inherits BaseMobility.

Collaboration diagram for MassMobility:
Collaboration graph
[legend]

List of all members.

Public Types

enum  MassMobilityMsgKinds { MK_CHANGE_DIR = BaseMobility::LAST_BASE_MOBILITY_KIND, LAST_MASS_MOBILITY_KIND }
 

The kind field of messages.

More...

Public Member Functions

virtual void initialize (int)
 Initializes mobility model parameters.

Protected Member Functions

virtual void handleSelfMsg (cMessage *msg)
 Called upon arrival of a self messages.
virtual void makeMove ()
 Move the host.
virtual void fixIfHostGetsOutside ()
 Should be redefined in subclasses.

Protected Attributes

cPar * changeInterval
cPar * changeAngleBy
double currentSpeed
 speed of the host
double currentAngle
 angle of linear motion
Coord step
 calculated from speed, angle and updateInterval
Coord targetPos

Detailed Description

Models the mobility of with mass, making random motions. See NED file for more info.

NOTE: Does not yet support 3-dimensional movement.

Author:
Emin Ilker Cetinbas, Andras Varga

Definition at line 37 of file MassMobility.h.


Member Enumeration Documentation

The kind field of messages.

that are used internally by this class have one of these values

Definition at line 57 of file MassMobility.h.

                              {
  MK_CHANGE_DIR = BaseMobility::LAST_BASE_MOBILITY_KIND,
  LAST_MASS_MOBILITY_KIND
    };


Member Function Documentation

void MassMobility::fixIfHostGetsOutside (  )  [protected, virtual]

Should be redefined in subclasses.

Should invoke handleIfOutside() and pass the references to the parameters to be modified.

Additional action after border handling (such as choosing a new target position if the BorderPolicy is PLACERANDOMLY) should be implemented here.

See also:
HandleIfOutside

Reimplemented from BaseMobility.

Definition at line 114 of file MassMobility.cc.

References currentAngle, BaseMobility::handleIfOutside(), BaseMobility::REFLECT, step, BaseWorldUtility::use2D(), and BaseMobility::world.

Referenced by makeMove().

{
    Coord dummy(world->use2D());

    handleIfOutside( REFLECT, targetPos, dummy, step, currentAngle );
}

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.

Reimplemented from BaseMobility.

Definition at line 76 of file MassMobility.cc.

References currentAngle, Move::getSpeed(), Move::getStartPos(), BaseMobility::move, Move::setDirectionByTarget(), Coord::setX(), Coord::setY(), step, BaseMobility::updateInterval, BaseWorldUtility::use2D(), and BaseMobility::world.

{
    Coord dummy(world->use2D());

    switch (msg->getKind()){
    case MOVE_HOST:
    BaseMobility::handleSelfMsg( msg );
    break;
    case MK_CHANGE_DIR:
    currentAngle += changeAngleBy->doubleValue();

    step.setX(move.getSpeed() * cos(PI * currentAngle / 180) * updateInterval.dbl());
    step.setY(move.getSpeed() * sin(PI * currentAngle / 180) * updateInterval.dbl());

    move.setDirectionByTarget(move.getStartPos() + step);

    scheduleAt(simTime() + changeInterval->doubleValue(), msg);
    break;
    default:
    opp_error("Unknown self message kind in MassMobility class");
    break;
    }

}

void MassMobility::initialize ( int  stage  )  [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 BaseMobility.

Definition at line 36 of file MassMobility.cc.

References currentAngle, Move::getSpeed(), Move::getStartPos(), BaseMobility::move, Move::setDirectionByTarget(), Move::setSpeed(), Move::setStart(), Coord::setX(), Coord::setY(), step, BaseMobility::updateInterval, BaseWorldUtility::use2D(), and BaseMobility::world.

{
    BaseMobility::initialize(stage);

    debugEV << "initializing MassMobility stage " << stage << endl;

    if (stage == 0)
    {
        changeInterval = &par("changeInterval");
        changeAngleBy = &par("changeAngleBy");

        // initial speed and angle
        move.setSpeed(par("speed"));
        currentAngle = uniform(0, 360);

        step.setX(move.getSpeed() * cos(PI * currentAngle / 180) * updateInterval.dbl());
        step.setY(move.getSpeed() * sin(PI * currentAngle / 180) * updateInterval.dbl());

    }
    else if( stage == 1 )
    {
      if(!world->use2D()) {
      opp_warning("This mobility module does not yet support 3 dimensional movement."\
            "Movements will probably be incorrect.");
    }

    // start moving: set direction and start time
    move.setDirectionByTarget(move.getStartPos() + step);
    move.setStart(move.getStartPos(), simTime());

    targetPos = move.getStartPos();

    scheduleAt(simTime() + uniform(0, changeInterval->doubleValue()), new cMessage("turn", MK_CHANGE_DIR));
    }
}

void MassMobility::makeMove (  )  [protected, virtual]

Move the host.

Move the host if the destination is not reached yet. Otherwise calculate a new random position

Reimplemented from BaseMobility.

Definition at line 105 of file MassMobility.cc.

References fixIfHostGetsOutside(), BaseMobility::move, Move::setStart(), and step.

{
    move.setStart(targetPos, simTime());
    targetPos += step;

    // do something if we reach the wall
    fixIfHostGetsOutside();
}


The documentation for this class was generated from the following files: