INET Framework for OMNeT++/OMNEST
inet::RectangleMobility Class Reference

Rectangle movement model. More...

#include <RectangleMobility.h>

Inheritance diagram for inet::RectangleMobility:
inet::MovingMobilityBase inet::MobilityBase inet::IMobility

Public Member Functions

virtual double getMaxSpeed () const override
 Returns the maximum possible speed at any future time. More...
 
 RectangleMobility ()
 
- Public Member Functions inherited from inet::MovingMobilityBase
virtual const CoordgetCurrentPosition () override
 Returns the position at the current simulation time. More...
 
virtual const CoordgetCurrentVelocity () override
 Returns the velocity at the current simulation time. More...
 
virtual const CoordgetCurrentAcceleration () override
 Returns the acceleration at the current simulation time. More...
 
virtual const QuaterniongetCurrentAngularPosition () override
 Returns the angular position at the current simulation time. More...
 
virtual const QuaterniongetCurrentAngularVelocity () override
 Returns the angular velocity at the current simulation time. More...
 
virtual const QuaterniongetCurrentAngularAcceleration () override
 Returns the angular acceleration at the current simulation time. More...
 
- Public Member Functions inherited from inet::MobilityBase
virtual const CoordgetConstraintAreaMax () const override
 Returns the maximum position along each axes for. More...
 
virtual const CoordgetConstraintAreaMin () const override
 Returns the minimum position along each axes for. More...
 
- Public Member Functions inherited from inet::IMobility
virtual ~IMobility ()
 

Protected Member Functions

virtual int numInitStages () const override
 Returns the required number of initialize stages. More...
 
virtual void initialize (int stage) override
 Initializes mobility model parameters. More...
 
virtual void setInitialPosition () override
 Initializes the position according to the mobility model. More...
 
virtual void move () override
 Move the host. More...
 
- Protected Member Functions inherited from inet::MovingMobilityBase
 MovingMobilityBase ()
 
virtual ~MovingMobilityBase ()
 
virtual void initializePosition () override
 Initializes mobility position. More...
 
virtual void handleSelfMessage (cMessage *message) override
 Called upon arrival of a self messages, subclasses must override. More...
 
void scheduleUpdate ()
 Schedules the move timer that will update the mobility state. More...
 
void moveAndUpdate ()
 Moves and notifies listeners. More...
 
virtual void orient ()
 
- Protected Member Functions inherited from inet::MobilityBase
 MobilityBase ()
 
virtual int getId () const override
 
virtual void checkPosition ()
 Checks whether the position is valid or not. More...
 
virtual void initializeOrientation ()
 Initializes the orientation from module parameters. More...
 
virtual void refreshDisplay () const override
 Moves the visual representation module's icon to the new position on the screen. More...
 
virtual void updateDisplayStringFromMobilityState () const
 
virtual void handleParameterChange (const char *name) override
 Allows changing parameters from the GUI. More...
 
virtual void handleMessage (cMessage *msg) override
 This modules should only receive self-messages. More...
 
virtual void emitMobilityStateChangedSignal ()
 Emits a signal with the updated mobility state. More...
 
virtual Coord getRandomPosition ()
 Returns a new random position satisfying the constraint area. More...
 
virtual cModule * findSubjectModule ()
 Returns the module that represents the object moved by this mobility module. More...
 
virtual bool isOutside ()
 Returns true if the mobility is outside of the constraint area. More...
 
virtual void reflectIfOutside (Coord &targetPosition, Coord &velocity, rad &angle, rad &elevation, Quaternion &quaternion)
 Utility function to reflect the node if it goes outside the constraint area. More...
 
virtual void wrapIfOutside (Coord &targetPosition)
 Utility function to wrap the node to the opposite edge (torus) if it goes outside the constraint area. More...
 
virtual void placeRandomlyIfOutside (Coord &targetPosition)
 Utility function to place the node randomly if it goes outside the constraint area. More...
 
virtual void raiseErrorIfOutside ()
 Utility function to raise an error if the node gets outside the constraint area. More...
 
virtual void handleIfOutside (BorderPolicy policy, Coord &targetPosition, Coord &velocity)
 Invokes one of reflectIfOutside(), wrapIfOutside() and placeRandomlyIfOutside(), depending on the given border policy. More...
 
virtual void handleIfOutside (BorderPolicy policy, Coord &targetPosition, Coord &velocity, rad &heading)
 
virtual void handleIfOutside (BorderPolicy policy, Coord &targetPosition, Coord &velocity, rad &heading, rad &elevation)
 
virtual void handleIfOutside (BorderPolicy policy, Coord &targetPosition, Coord &velocity, rad &heading, rad &elevation, Quaternion &quaternion)
 

Protected Attributes

double speed
 speed of the host More...
 
double d
 distance from (x1,y1), measured clockwise on the perimeter More...
 
double corner1
 
double corner2
 
double corner3
 
double corner4
 
- Protected Attributes inherited from inet::MovingMobilityBase
cMessage * moveTimer
 The message used for mobility state changes. More...
 
simtime_t updateInterval
 The simulation time interval used to regularly signal mobility state changes. More...
 
bool stationary
 A mobility model may decide to become stationary at any time. More...
 
Coord lastVelocity
 The last velocity that was reported at lastUpdate. More...
 
Quaternion lastAngularVelocity
 The last angular velocity that was reported at lastUpdate. More...
 
simtime_t lastUpdate
 The simulation time when the mobility state was last updated. More...
 
simtime_t nextChange
 The next simulation time when the mobility module needs to update its internal state. More...
 
bool faceForward
 
- Protected Attributes inherited from inet::MobilityBase
cModule * subjectModule
 Pointer to visual representation module, to speed up repeated access. More...
 
const CanvasProjectioncanvasProjection
 The 2D projection used on the canvas. More...
 
Coord constraintAreaMin
 3 dimensional position and size of the constraint area (in meters). More...
 
Coord constraintAreaMax
 
Coord lastPosition
 The last position that was reported. More...
 
Quaternion lastOrientation
 The last orientation that was reported. More...
 
StringFormat format
 

Additional Inherited Members

- Public Types inherited from inet::MobilityBase
enum  BorderPolicy { REFLECT, WRAP, PLACERANDOMLY, RAISEERROR }
 Selects how a mobility module should behave if it reaches the edge of the constraint area. More...
 
- Static Public Attributes inherited from inet::IMobility
static simsignal_t mobilityStateChangedSignal = cComponent::registerSignal("mobilityStateChanged")
 A signal used to publish mobility state changes. More...
 

Detailed Description

Rectangle movement model.

See NED file for more info.

Constructor & Destructor Documentation

◆ RectangleMobility()

inet::RectangleMobility::RectangleMobility ( )
17 {
18  speed = 0;
19  d = 0;
20  corner1 = corner2 = corner3 = corner4 = 0;
21 }

Member Function Documentation

◆ getMaxSpeed()

virtual double inet::RectangleMobility::getMaxSpeed ( ) const
inlineoverridevirtual

Returns the maximum possible speed at any future time.

Reimplemented from inet::MobilityBase.

46 { return speed; }

◆ initialize()

void inet::RectangleMobility::initialize ( int  stage)
overrideprotectedvirtual

Initializes mobility model parameters.

If the host is not stationary it calculates a random position on the rectangle.

Reimplemented from inet::MovingMobilityBase.

24 {
26 
27  EV_TRACE << "initializing RectangleMobility stage " << stage << endl;
28  if (stage == INITSTAGE_LOCAL) {
29  speed = par("speed");
30  stationary = (speed == 0);
31 
32  // calculate helper variables
33  double dx = constraintAreaMax.x - constraintAreaMin.x;
34  double dy = constraintAreaMax.y - constraintAreaMin.y;
35  corner1 = dx;
36  corner2 = corner1 + dy;
37  corner3 = corner2 + dx;
38  corner4 = corner3 + dy;
39 
40  // determine start position
41  double startPos = par("startPos");
42  startPos = fmod(startPos, 4);
43  if (startPos < 1)
44  d = startPos * dx; // top side
45  else if (startPos < 2)
46  d = corner1 + (startPos - 1) * dy; // right side
47  else if (startPos < 3)
48  d = corner2 + (startPos - 2) * dx; // bottom side
49  else
50  d = corner3 + (startPos - 3) * dy; // left side
51  WATCH(d);
52  }
53 }

◆ move()

void inet::RectangleMobility::move ( )
overrideprotectedvirtual

Move the host.

Implements inet::MovingMobilityBase.

62 {
63  double elapsedTime = (simTime() - lastUpdate).dbl();
64  d += speed * elapsedTime;
65 
66  while (d < 0)
67  d += corner4;
68 
69  while (d >= corner4)
70  d -= corner4;
71 
72  if (d < corner1) {
73  // top side
76  lastVelocity = Coord(speed, 0, 0);
77  }
78  else if (d < corner2) {
79  // right side
82  lastVelocity = Coord(0, speed, 0);
83  }
84  else if (d < corner3) {
85  // bottom side
88  lastVelocity = Coord(-speed, 0, 0);
89  }
90  else {
91  // left side
94  lastVelocity = Coord(0, -speed, 0);
95  }
96 }

Referenced by setInitialPosition().

◆ numInitStages()

virtual int inet::RectangleMobility::numInitStages ( ) const
inlineoverrideprotectedvirtual

Returns the required number of initialize stages.

Reimplemented from inet::MobilityBase.

31 { return NUM_INIT_STAGES; }

◆ setInitialPosition()

void inet::RectangleMobility::setInitialPosition ( )
overrideprotectedvirtual

Initializes the position according to the mobility model.

Reimplemented from inet::MobilityBase.

56 {
58  move();
59 }

Member Data Documentation

◆ corner1

double inet::RectangleMobility::corner1
protected

Referenced by initialize(), move(), and RectangleMobility().

◆ corner2

double inet::RectangleMobility::corner2
protected

Referenced by initialize(), move(), and RectangleMobility().

◆ corner3

double inet::RectangleMobility::corner3
protected

Referenced by initialize(), move(), and RectangleMobility().

◆ corner4

double inet::RectangleMobility::corner4
protected

Referenced by initialize(), move(), and RectangleMobility().

◆ d

double inet::RectangleMobility::d
protected

distance from (x1,y1), measured clockwise on the perimeter

Referenced by initialize(), move(), and RectangleMobility().

◆ speed

double inet::RectangleMobility::speed
protected

speed of the host

Referenced by initialize(), move(), and RectangleMobility().


The documentation for this class was generated from the following files:
inet::MobilityBase::lastPosition
Coord lastPosition
The last position that was reported.
Definition: MobilityBase.h:73
inet::MovingMobilityBase::lastUpdate
simtime_t lastUpdate
The simulation time when the mobility state was last updated.
Definition: MovingMobilityBase.h:41
inet::RectangleMobility::move
virtual void move() override
Move the host.
Definition: RectangleMobility.cc:61
inet::MovingMobilityBase::stationary
bool stationary
A mobility model may decide to become stationary at any time.
Definition: MovingMobilityBase.h:32
inet::RectangleMobility::corner1
double corner1
Definition: RectangleMobility.h:28
inet::Coord::x
double x
Definition: Coord.h:36
inet::RectangleMobility::speed
double speed
speed of the host
Definition: RectangleMobility.h:24
inet::RectangleMobility::d
double d
distance from (x1,y1), measured clockwise on the perimeter
Definition: RectangleMobility.h:27
inet::RectangleMobility::corner4
double corner4
Definition: RectangleMobility.h:28
inet::MovingMobilityBase::initialize
virtual void initialize(int stage) override
Initializes mobility model parameters.
Definition: MovingMobilityBase.cc:26
inet::MobilityBase::constraintAreaMax
Coord constraintAreaMax
Definition: MobilityBase.h:70
inet::RectangleMobility::corner3
double corner3
Definition: RectangleMobility.h:28
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
NUM_INIT_STAGES
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
inet::MobilityBase::setInitialPosition
virtual void setInitialPosition()
Initializes the position from the display string or from module parameters.
Definition: MobilityBase.cc:122
inet::MovingMobilityBase::lastVelocity
Coord lastVelocity
The last velocity that was reported at lastUpdate.
Definition: MovingMobilityBase.h:35
inet::MobilityBase::constraintAreaMin
Coord constraintAreaMin
3 dimensional position and size of the constraint area (in meters).
Definition: MobilityBase.h:70
inet::RectangleMobility::corner2
double corner2
Definition: RectangleMobility.h:28
inet::Coord::y
double y
Definition: Coord.h:37