INET Framework for OMNeT++/OMNEST
inet::MovingMobilityBase Class Referenceabstract

Base class for moving mobility modules. More...

#include <MovingMobilityBase.h>

Inheritance diagram for inet::MovingMobilityBase:
inet::MobilityBase inet::IMobility inet::CircleMobility inet::LinearMobility inet::LineSegmentsMobilityBase inet::RectangleMobility inet::VehicleMobility inet::ANSimMobility inet::BonnMotionMobility inet::ChiangMobility inet::ConstSpeedMobility inet::GaussMarkovMobility inet::MassMobility inet::MoBANCoordinator inet::MoBANLocal inet::Ns2MotionMobility inet::RandomWPMobility inet::TractorMobility inet::TurtleMobility

Public Member Functions

virtual Coord getCurrentPosition () override
 Returns the current position at the current simulation time. More...
 
virtual Coord getCurrentSpeed () override
 Returns the current speed at the current simulation time. More...
 
virtual EulerAngles getCurrentAngularPosition () override
 Returns the current angular position at the current simulation time. More...
 
- Public Member Functions inherited from inet::MobilityBase
virtual double getMaxSpeed () const override
 Returns the maximum possible speed at any future time. More...
 
virtual EulerAngles getCurrentAngularSpeed () override
 Returns the current angular speed at the current simulation time. More...
 
virtual Coord getConstraintAreaMax () const override
 Returns the current angular acceleration at the current simulation time. More...
 
virtual Coord getConstraintAreaMin () const override
 
- Public Member Functions inherited from inet::IMobility
virtual ~IMobility ()
 

Protected Member Functions

 MovingMobilityBase ()
 
virtual ~MovingMobilityBase ()
 
virtual void initialize (int stage) override
 Initializes mobility model parameters. More...
 
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 move ()=0
 Moves according to the mobility model to the current simulation time. More...
 
- Protected Member Functions inherited from inet::MobilityBase
 MobilityBase ()
 
virtual int numInitStages () const override
 Returns the required number of initialize stages. More...
 
virtual void setInitialPosition ()
 Initializes the position from the display string or from module parameters. More...
 
virtual void checkPosition ()
 Checks whether the position is valid or not. More...
 
virtual void initializeOrientation ()
 Initializes the orientation from module parameters. More...
 
virtual void handleMessage (cMessage *msg) override
 This modules should only receive self-messages. More...
 
virtual void updateVisualRepresentation ()
 Moves the visual representation module's icon to the new position on the screen. 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 * findVisualRepresentation ()
 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 &speed, double &angle)
 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 &speed, double &angle)
 Invokes one of reflectIfOutside(), wrapIfOutside() and placeRandomlyIfOutside(), depending on the given border policy. More...
 

Protected Attributes

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 lastSpeed
 The last speed 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...
 
- Protected Attributes inherited from inet::MobilityBase
cModule * visualRepresentation
 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...
 
EulerAngles lastOrientation
 The last position that was reported. More...
 

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

Base class for moving mobility modules.

Periodically emits a signal with the current mobility state.

Author
Levente Meszaros

Constructor & Destructor Documentation

inet::MovingMobilityBase::MovingMobilityBase ( )
protected
27  :
28  moveTimer(nullptr),
29  updateInterval(0),
30  stationary(false),
32  lastUpdate(0),
33  nextChange(-1)
34 {
35 }
simtime_t lastUpdate
The simulation time when the mobility state was last updated.
Definition: MovingMobilityBase.h:55
cMessage * moveTimer
The message used for mobility state changes.
Definition: MovingMobilityBase.h:39
simtime_t nextChange
The next simulation time when the mobility module needs to update its internal state.
Definition: MovingMobilityBase.h:60
simtime_t updateInterval
The simulation time interval used to regularly signal mobility state changes.
Definition: MovingMobilityBase.h:44
bool stationary
A mobility model may decide to become stationary at any time.
Definition: MovingMobilityBase.h:49
static const Coord ZERO
Definition: Coord.h:41
Coord lastSpeed
The last speed that was reported at lastUpdate.
Definition: MovingMobilityBase.h:52
inet::MovingMobilityBase::~MovingMobilityBase ( )
protectedvirtual
38 {
39  cancelAndDelete(moveTimer);
40 }
cMessage * moveTimer
The message used for mobility state changes.
Definition: MovingMobilityBase.h:39

Member Function Documentation

EulerAngles inet::MovingMobilityBase::getCurrentAngularPosition ( )
overridevirtual

Returns the current angular position at the current simulation time.

Reimplemented from inet::MobilityBase.

113 {
114  moveAndUpdate();
115  return lastOrientation;
116 }
void moveAndUpdate()
Moves and notifies listeners.
Definition: MovingMobilityBase.cc:59
EulerAngles lastOrientation
The last position that was reported.
Definition: MobilityBase.h:81
Coord inet::MovingMobilityBase::getCurrentPosition ( )
overridevirtual

Returns the current position at the current simulation time.

Implements inet::IMobility.

Reimplemented in inet::MoBANLocal.

Referenced by inet::MoBANLocal::getCurrentPosition(), and inet::MoBANLocal::updateVisualRepresentation().

101 {
102  moveAndUpdate();
103  return lastPosition;
104 }
void moveAndUpdate()
Moves and notifies listeners.
Definition: MovingMobilityBase.cc:59
Coord lastPosition
The last position that was reported.
Definition: MobilityBase.h:78
Coord inet::MovingMobilityBase::getCurrentSpeed ( )
overridevirtual

Returns the current speed at the current simulation time.

Implements inet::IMobility.

Reimplemented in inet::MoBANLocal.

Referenced by inet::MoBANLocal::getCurrentSpeed().

107 {
108  moveAndUpdate();
109  return lastSpeed;
110 }
void moveAndUpdate()
Moves and notifies listeners.
Definition: MovingMobilityBase.cc:59
Coord lastSpeed
The last speed that was reported at lastUpdate.
Definition: MovingMobilityBase.h:52
void inet::MovingMobilityBase::handleSelfMessage ( cMessage *  msg)
overrideprotectedvirtual

Called upon arrival of a self messages, subclasses must override.

Implements inet::MobilityBase.

77 {
78  moveAndUpdate();
80 }
void moveAndUpdate()
Moves and notifies listeners.
Definition: MovingMobilityBase.cc:59
void scheduleUpdate()
Schedules the move timer that will update the mobility state.
Definition: MovingMobilityBase.cc:82
void inet::MovingMobilityBase::initialize ( int  stage)
overrideprotectedvirtual

Initializes mobility model parameters.

Reimplemented from inet::MobilityBase.

Reimplemented in inet::MoBANCoordinator, inet::MoBANLocal, inet::Ns2MotionMobility, inet::MassMobility, inet::TurtleMobility, inet::CircleMobility, inet::RectangleMobility, inet::VehicleMobility, inet::BonnMotionMobility, inet::GaussMarkovMobility, inet::TractorMobility, inet::ANSimMobility, inet::ConstSpeedMobility, inet::LinearMobility, inet::ChiangMobility, and inet::RandomWPMobility.

Referenced by inet::ChiangMobility::initialize(), inet::RandomWPMobility::initialize(), inet::LinearMobility::initialize(), inet::ConstSpeedMobility::initialize(), inet::ANSimMobility::initialize(), inet::BonnMotionMobility::initialize(), inet::GaussMarkovMobility::initialize(), inet::TractorMobility::initialize(), inet::VehicleMobility::initialize(), inet::RectangleMobility::initialize(), inet::CircleMobility::initialize(), inet::MassMobility::initialize(), inet::TurtleMobility::initialize(), inet::Ns2MotionMobility::initialize(), inet::MoBANLocal::initialize(), and inet::MoBANCoordinator::initialize().

43 {
45  EV_TRACE << "initializing MovingMobilityBase stage " << stage << endl;
46  if (stage == INITSTAGE_LOCAL) {
47  moveTimer = new cMessage("move");
48  updateInterval = par("updateInterval");
49  }
50 }
virtual void initialize(int stage) override
Initializes mobility model parameters.
Definition: MobilityBase.cc:63
cMessage * moveTimer
The message used for mobility state changes.
Definition: MovingMobilityBase.h:39
Local initializations.
Definition: InitStages.h:35
simtime_t updateInterval
The simulation time interval used to regularly signal mobility state changes.
Definition: MovingMobilityBase.h:44
void inet::MovingMobilityBase::initializePosition ( )
overrideprotectedvirtual

Initializes mobility position.

Reimplemented from inet::MobilityBase.

Reimplemented in inet::LineSegmentsMobilityBase.

53 {
55  lastUpdate = simTime();
57 }
virtual void initializePosition()
Initializes mobility position.
Definition: MobilityBase.cc:91
simtime_t lastUpdate
The simulation time when the mobility state was last updated.
Definition: MovingMobilityBase.h:55
void scheduleUpdate()
Schedules the move timer that will update the mobility state.
Definition: MovingMobilityBase.cc:82
virtual void inet::MovingMobilityBase::move ( )
protectedpure virtual

Moves according to the mobility model to the current simulation time.

Subclasses must override and update lastPosition, lastSpeed, lastUpdate, nextChange and other state according to the mobility model.

Implemented in inet::Ns2MotionMobility, inet::TurtleMobility, inet::CircleMobility, inet::MassMobility, inet::BonnMotionMobility, inet::RectangleMobility, inet::ANSimMobility, inet::ChiangMobility, inet::GaussMarkovMobility, inet::RandomWPMobility, inet::VehicleMobility, inet::LinearMobility, and inet::LineSegmentsMobilityBase.

Referenced by moveAndUpdate().

void inet::MovingMobilityBase::moveAndUpdate ( )
protected

Moves and notifies listeners.

Referenced by getCurrentAngularPosition(), getCurrentPosition(), getCurrentSpeed(), and handleSelfMessage().

60 {
61  simtime_t now = simTime();
62  if (nextChange == now || lastUpdate != now) {
63  move();
64  // determine orientation based on direction
65  Coord direction = lastSpeed;
66  direction.normalize();
67  lastOrientation.alpha = atan2(-direction.y, direction.x);
68  lastOrientation.beta = asin(direction.z);
69  lastOrientation.gamma = 0.0;
70  lastUpdate = simTime();
73  }
74 }
double gamma
Definition: EulerAngles.h:19
double beta
Definition: EulerAngles.h:18
virtual void emitMobilityStateChangedSignal()
Emits a signal with the updated mobility state.
Definition: MobilityBase.cc:176
simtime_t lastUpdate
The simulation time when the mobility state was last updated.
Definition: MovingMobilityBase.h:55
virtual void updateVisualRepresentation()
Moves the visual representation module&#39;s icon to the new position on the screen.
Definition: MobilityBase.cc:157
simtime_t nextChange
The next simulation time when the mobility module needs to update its internal state.
Definition: MovingMobilityBase.h:60
virtual void move()=0
Moves according to the mobility model to the current simulation time.
EulerAngles lastOrientation
The last position that was reported.
Definition: MobilityBase.h:81
double alpha
Definition: EulerAngles.h:17
void normalize()
Updates the length of this position vector to be 1.
Definition: Coord.h:234
Coord lastSpeed
The last speed that was reported at lastUpdate.
Definition: MovingMobilityBase.h:52
void inet::MovingMobilityBase::scheduleUpdate ( )
protected

Schedules the move timer that will update the mobility state.

Referenced by handleSelfMessage(), inet::LineSegmentsMobilityBase::initializePosition(), initializePosition(), and inet::MoBANLocal::setMoBANParameters().

83 {
84  cancelEvent(moveTimer);
85  if (!stationary && updateInterval != 0) {
86  // periodic update is needed
87  simtime_t nextUpdate = simTime() + updateInterval;
88  if (nextChange != -1 && nextChange < nextUpdate)
89  // next change happens earlier than next update
90  scheduleAt(nextChange, moveTimer);
91  else
92  // next update happens earlier than next change or there is no change at all
93  scheduleAt(nextUpdate, moveTimer);
94  }
95  else if (nextChange != -1)
96  // no periodic update is needed
97  scheduleAt(nextChange, moveTimer);
98 }
cMessage * moveTimer
The message used for mobility state changes.
Definition: MovingMobilityBase.h:39
simtime_t nextChange
The next simulation time when the mobility module needs to update its internal state.
Definition: MovingMobilityBase.h:60
simtime_t updateInterval
The simulation time interval used to regularly signal mobility state changes.
Definition: MovingMobilityBase.h:44
bool stationary
A mobility model may decide to become stationary at any time.
Definition: MovingMobilityBase.h:49

Member Data Documentation

cMessage* inet::MovingMobilityBase::moveTimer
protected

The message used for mobility state changes.

Referenced by initialize(), scheduleUpdate(), and ~MovingMobilityBase().

simtime_t inet::MovingMobilityBase::updateInterval
protected

The simulation time interval used to regularly signal mobility state changes.

The 0 value turns off the signal.

Referenced by initialize(), scheduleUpdate(), and inet::GaussMarkovMobility::setTargetPosition().


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