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::GaussMarkovMobility inet::MassMobility inet::MoBanCoordinator inet::MoBanLocal inet::Ns2MotionMobility inet::RandomWaypointMobility inet::TractorMobility inet::TurtleMobility

Public Member Functions

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 double getMaxSpeed () const override
 Returns the maximum possible speed at any future time. More...
 
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

 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...
 
virtual void orient ()
 
- Protected Member Functions inherited from inet::MobilityBase
 MobilityBase ()
 
virtual int getId () const override
 
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 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

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

Base class for moving mobility modules.

Periodically emits a signal with the current mobility state.

Constructor & Destructor Documentation

◆ MovingMobilityBase()

inet::MovingMobilityBase::MovingMobilityBase ( )
protected
10  :
11  moveTimer(nullptr),
12  updateInterval(0),
13  stationary(false),
15  lastUpdate(0),
16  nextChange(-1),
17  faceForward(false)
18 {
19 }

◆ ~MovingMobilityBase()

inet::MovingMobilityBase::~MovingMobilityBase ( )
protectedvirtual
22 {
23  cancelAndDelete(moveTimer);
24 }

Member Function Documentation

◆ getCurrentAcceleration()

virtual const Coord& inet::MovingMobilityBase::getCurrentAcceleration ( )
inlineoverridevirtual

Returns the acceleration at the current simulation time.

Implements inet::IMobility.

79 { throw cRuntimeError("Invalid operation"); }

◆ getCurrentAngularAcceleration()

virtual const Quaternion& inet::MovingMobilityBase::getCurrentAngularAcceleration ( )
inlineoverridevirtual

Returns the angular acceleration at the current simulation time.

Implements inet::IMobility.

Reimplemented in inet::CircleMobility.

83 { throw cRuntimeError("Invalid operation"); }

◆ getCurrentAngularPosition()

const Quaternion & inet::MovingMobilityBase::getCurrentAngularPosition ( )
overridevirtual

Returns the angular position at the current simulation time.

Implements inet::IMobility.

107 {
108  moveAndUpdate();
109  return lastOrientation;
110 }

◆ getCurrentAngularVelocity()

const Quaternion & inet::MovingMobilityBase::getCurrentAngularVelocity ( )
overridevirtual

Returns the angular velocity at the current simulation time.

Implements inet::IMobility.

Reimplemented in inet::CircleMobility.

113 {
114  moveAndUpdate();
115  return lastAngularVelocity;
116 }

◆ getCurrentPosition()

const Coord & inet::MovingMobilityBase::getCurrentPosition ( )
overridevirtual

Returns the position at the current simulation time.

Implements inet::IMobility.

Reimplemented in inet::MoBanLocal.

95 {
96  moveAndUpdate();
97  return lastPosition;
98 }

Referenced by inet::MoBanLocal::getCurrentPosition(), and inet::MoBanLocal::refreshDisplay().

◆ getCurrentVelocity()

const Coord & inet::MovingMobilityBase::getCurrentVelocity ( )
overridevirtual

Returns the velocity at the current simulation time.

Implements inet::IMobility.

Reimplemented in inet::MoBanLocal.

101 {
102  moveAndUpdate();
103  return lastVelocity;
104 }

Referenced by inet::MoBanLocal::getCurrentVelocity().

◆ handleSelfMessage()

void inet::MovingMobilityBase::handleSelfMessage ( cMessage *  msg)
overrideprotectedvirtual

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

Implements inet::MobilityBase.

71 {
72  moveAndUpdate();
74 }

◆ initialize()

◆ initializePosition()

void inet::MovingMobilityBase::initializePosition ( )
overrideprotectedvirtual

Initializes mobility position.

Reimplemented from inet::MobilityBase.

Reimplemented in inet::LineSegmentsMobilityBase.

38 {
40  lastUpdate = simTime();
42 }

◆ move()

virtual void inet::MovingMobilityBase::move ( )
protectedpure virtual

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

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

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

Referenced by moveAndUpdate().

◆ moveAndUpdate()

void inet::MovingMobilityBase::moveAndUpdate ( )
protected

Moves and notifies listeners.

45 {
46  simtime_t now = simTime();
47  if (nextChange == now || lastUpdate != now) {
48  move();
49  orient();
50  lastUpdate = simTime();
52  }
53 }

Referenced by getCurrentAngularPosition(), getCurrentAngularVelocity(), getCurrentPosition(), getCurrentVelocity(), and handleSelfMessage().

◆ orient()

void inet::MovingMobilityBase::orient ( )
protectedvirtual

Reimplemented in inet::MassMobility, and inet::VehicleMobility.

56 {
57  if (faceForward) {
58  // determine orientation based on direction
59  if (lastVelocity != Coord::ZERO) {
60  Coord direction = lastVelocity;
61  direction.normalize();
62  auto alpha = rad(atan2(direction.y, direction.x));
63  auto beta = rad(-asin(direction.z));
64  auto gamma = rad(0.0);
65  lastOrientation = Quaternion(EulerAngles(alpha, beta, gamma));
66  }
67  }
68 }

Referenced by moveAndUpdate(), inet::VehicleMobility::orient(), and inet::CircleMobility::setInitialPosition().

◆ scheduleUpdate()

void inet::MovingMobilityBase::scheduleUpdate ( )
protected

Schedules the move timer that will update the mobility state.

77 {
78  cancelEvent(moveTimer);
79  if (!stationary && updateInterval != 0) {
80  // periodic update is needed
81  simtime_t nextUpdate = simTime() + updateInterval;
82  if (nextChange != -1 && nextChange < nextUpdate)
83  // next change happens earlier than next update
84  scheduleAt(nextChange, moveTimer);
85  else
86  // next update happens earlier than next change or there is no change at all
87  scheduleAt(nextUpdate, moveTimer);
88  }
89  else if (nextChange != -1)
90  // no periodic update is needed
91  scheduleAt(nextChange, moveTimer);
92 }

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

Member Data Documentation

◆ faceForward

bool inet::MovingMobilityBase::faceForward
protected

◆ lastAngularVelocity

Quaternion inet::MovingMobilityBase::lastAngularVelocity
protected

The last angular velocity that was reported at lastUpdate.

Referenced by getCurrentAngularVelocity(), and inet::CircleMobility::initialize().

◆ lastUpdate

simtime_t inet::MovingMobilityBase::lastUpdate
protected

◆ lastVelocity

◆ moveTimer

cMessage* inet::MovingMobilityBase::moveTimer
protected

The message used for mobility state changes.

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

◆ nextChange

◆ stationary

◆ updateInterval

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:
inet::MovingMobilityBase::moveTimer
cMessage * moveTimer
The message used for mobility state changes.
Definition: MovingMobilityBase.h:22
inet::MobilityBase::emitMobilityStateChangedSignal
virtual void emitMobilityStateChangedSignal()
Emits a signal with the updated mobility state.
Definition: MobilityBase.cc:246
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::Coord::ZERO
static const Coord ZERO
Definition: Coord.h:27
inet::MobilityBase::lastOrientation
Quaternion lastOrientation
The last orientation that was reported.
Definition: MobilityBase.h:76
inet::MovingMobilityBase::stationary
bool stationary
A mobility model may decide to become stationary at any time.
Definition: MovingMobilityBase.h:32
inet::MovingMobilityBase::faceForward
bool faceForward
Definition: MovingMobilityBase.h:48
inet::MovingMobilityBase::scheduleUpdate
void scheduleUpdate()
Schedules the move timer that will update the mobility state.
Definition: MovingMobilityBase.cc:76
inet::MovingMobilityBase::lastAngularVelocity
Quaternion lastAngularVelocity
The last angular velocity that was reported at lastUpdate.
Definition: MovingMobilityBase.h:38
inet::MovingMobilityBase::orient
virtual void orient()
Definition: MovingMobilityBase.cc:55
inet::MovingMobilityBase::nextChange
simtime_t nextChange
The next simulation time when the mobility module needs to update its internal state.
Definition: MovingMobilityBase.h:46
inet::MovingMobilityBase::moveAndUpdate
void moveAndUpdate()
Moves and notifies listeners.
Definition: MovingMobilityBase.cc:44
inet::MovingMobilityBase::updateInterval
simtime_t updateInterval
The simulation time interval used to regularly signal mobility state changes.
Definition: MovingMobilityBase.h:27
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::MobilityBase::initialize
virtual void initialize(int stage) override
Initializes mobility model parameters.
Definition: MobilityBase.cc:87
inet::MobilityBase::initializePosition
virtual void initializePosition()
Initializes mobility position.
Definition: MobilityBase.cc:115
inet::MovingMobilityBase::lastVelocity
Coord lastVelocity
The last velocity that was reported at lastUpdate.
Definition: MovingMobilityBase.h:35
inet::units::constants::alpha
const value< double, units::unit > alpha(7.2973525376e-3)
inet::Coord::normalize
Coord normalize()
Updates the length of this position vector to be 1.
Definition: Coord.h:280
inet::units::values::rad
value< double, units::rad > rad
Definition: Units.h:1245
inet::MovingMobilityBase::move
virtual void move()=0
Moves according to the mobility model to the current simulation time.