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

Uses the <position_change> elements of the ANSim tool's trace file. More...

#include <AnsimMobility.h>

Inheritance diagram for inet::AnsimMobility:
inet::LineSegmentsMobilityBase inet::MovingMobilityBase inet::MobilityBase inet::IMobility

Public Member Functions

virtual double getMaxSpeed () const override
 Returns the maximum possible speed at any future time. More...
 
 AnsimMobility ()
 
- Public Member Functions inherited from inet::LineSegmentsMobilityBase
 LineSegmentsMobilityBase ()
 
- 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 setTargetPosition () override
 Overridden from LineSegmentsMobilityBase. More...
 
virtual void move () override
 Overridden from LineSegmentsMobilityBase. More...
 
virtual cXMLElement * findNextPositionChange (cXMLElement *positionChange)
 Finds the next <position_change> element. More...
 
virtual void extractDataFrom (cXMLElement *node)
 Utility: extract data from given <position_update> element. More...
 
virtual void computeMaxSpeed ()
 
- Protected Member Functions inherited from inet::LineSegmentsMobilityBase
virtual void initializePosition () override
 Initializes mobility position. More...
 
- Protected Member Functions inherited from inet::MovingMobilityBase
 MovingMobilityBase ()
 
virtual ~MovingMobilityBase ()
 
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

int nodeId
 we'll have to compare this to the <node_id> elements More...
 
cXMLElement * nextPositionChange
 points to the next <position_change> element More...
 
double maxSpeed
 
- Protected Attributes inherited from inet::LineSegmentsMobilityBase
Coord targetPosition
 End position of current linear movement. More...
 
- 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

Uses the <position_change> elements of the ANSim tool's trace file.

See NED file for more info.

Constructor & Destructor Documentation

◆ AnsimMobility()

inet::AnsimMobility::AnsimMobility ( )
68 {
69  maxSpeed = 0;
70  nodeId = -1;
71  nextPositionChange = nullptr;
72 }

Member Function Documentation

◆ computeMaxSpeed()

void inet::AnsimMobility::computeMaxSpeed ( )
protectedvirtual
30 {
31  cXMLElement *rootElem = par("ansimTrace");
32  cXMLElement *curElem = rootElem->getElementByPath("mobility/position_change");
33  if (!curElem)
34  throw cRuntimeError("Element doesn't have <mobility> child or <position_change> grandchild at %s",
35  rootElem->getSourceLocation());
36  cXMLElement *nextElem = findNextPositionChange(curElem);
37  if (!nextElem)
38  throw cRuntimeError("Element doesn't have second <position_change> grandchild at %s",
39  curElem->getSourceLocation());
40  curElem = nextElem;
41  cXMLElement *destElem = firstChildWithTag(curElem, "destination");
42  const char *xStr = firstChildWithTag(destElem, "xpos")->getNodeValue();
43  const char *yStr = firstChildWithTag(destElem, "ypos")->getNodeValue();
44  Coord lastPos(atof(xStr), atof(yStr), 0);
45  // first position is the initial position so we don't take it into account to compute maxSpeed
46  if (curElem)
47  curElem = curElem->getNextSibling();
48  while (curElem) {
49  cXMLElement *destElem = firstChildWithTag(curElem, "destination");
50  const char *xStr = firstChildWithTag(destElem, "xpos")->getNodeValue();
51  const char *yStr = firstChildWithTag(destElem, "ypos")->getNodeValue();
52  const char *startTimeStr = firstChildWithTag(curElem, "start_time")->getNodeValue();
53  const char *endTimeStr = firstChildWithTag(curElem, "end_time")->getNodeValue();
54  double elapsedTime = atof(endTimeStr) - atof(startTimeStr);
55  if (elapsedTime == 0)
56  throw cRuntimeError("Elapsed time is zero: infinite speed");
57  Coord currentPos(atof(xStr), atof(yStr), 0);
58  double distance = currentPos.distance(lastPos);
59  double currentSpeed = distance / elapsedTime;
60  if (currentSpeed > maxSpeed)
61  maxSpeed = currentSpeed;
62  lastPos = currentPos;
63  curElem = findNextPositionChange(curElem->getNextSibling());
64  }
65 }

Referenced by initialize().

◆ extractDataFrom()

void inet::AnsimMobility::extractDataFrom ( cXMLElement *  node)
protectedvirtual

Utility: extract data from given <position_update> element.

136 {
137  // extract data from <position_change> element
138  // FIXME start_time has to be taken into account too! as pause from prev element's end_time
139  const char *startTimeStr = firstChildWithTag(node, "start_time")->getNodeValue();
140  if (!startTimeStr)
141  throw cRuntimeError("No content in <start_time> element at %s", node->getSourceLocation());
142  const char *endTimeStr = firstChildWithTag(node, "end_time")->getNodeValue();
143  if (!endTimeStr)
144  throw cRuntimeError("No content in <end_time> element at %s", node->getSourceLocation());
145  cXMLElement *destElem = firstChildWithTag(node, "destination");
146  const char *xStr = firstChildWithTag(destElem, "xpos")->getNodeValue();
147  const char *yStr = firstChildWithTag(destElem, "ypos")->getNodeValue();
148  if (!xStr || !yStr)
149  throw cRuntimeError("No content in <destination>/<xpos> or <ypos> element at %s", node->getSourceLocation());
150 
151  nextChange = atof(endTimeStr);
152  targetPosition.x = atof(xStr);
153  targetPosition.y = atof(yStr);
154 }

Referenced by setInitialPosition(), and setTargetPosition().

◆ findNextPositionChange()

cXMLElement * inet::AnsimMobility::findNextPositionChange ( cXMLElement *  positionChange)
protectedvirtual

Finds the next <position_change> element.

106 {
107  // find next <position_change> element with matching <node_id> tag (current one also OK)
108  while (positionChange) {
109  const char *nodeIdStr = firstChildWithTag(positionChange, "node_id")->getNodeValue();
110  if (nodeIdStr && atoi(nodeIdStr) == nodeId)
111  break;
112 
113  positionChange = positionChange->getNextSibling();
114  }
115  return positionChange;
116 }

Referenced by computeMaxSpeed(), setInitialPosition(), and setTargetPosition().

◆ getMaxSpeed()

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

Returns the maximum possible speed at any future time.

Reimplemented from inet::MobilityBase.

53 { return maxSpeed; }

◆ initialize()

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

Initializes mobility model parameters.

Reimplemented from inet::MovingMobilityBase.

75 {
77 
78  EV_TRACE << "initializing AnsimMobility stage " << stage << endl;
79  if (stage == INITSTAGE_LOCAL) {
80  nodeId = par("nodeId");
81  if (nodeId == -1)
82  nodeId = getContainingNode(this)->getIndex();
83 
84  // get script: param should point to <simulation> element
85  cXMLElement *rootElem = par("ansimTrace");
86  if (strcmp(rootElem->getTagName(), "simulation") != 0)
87  throw cRuntimeError("<simulation> is expected as root element not <%s> at %s",
88  rootElem->getTagName(), rootElem->getSourceLocation());
89  nextPositionChange = rootElem->getElementByPath("mobility/position_change");
90  if (!nextPositionChange)
91  throw cRuntimeError("Element doesn't have <mobility> child or <position_change> grandchild at %s",
92  rootElem->getSourceLocation());
94  }
95 }

◆ move()

void inet::AnsimMobility::move ( )
overrideprotectedvirtual

Overridden from LineSegmentsMobilityBase.

Reimplemented from inet::LineSegmentsMobilityBase.

157 {
160 }

◆ numInitStages()

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

Returns the required number of initialize stages.

Reimplemented from inet::MobilityBase.

31 { return NUM_INIT_STAGES; }

◆ setInitialPosition()

void inet::AnsimMobility::setInitialPosition ( )
overrideprotectedvirtual

Initializes the position according to the mobility model.

Reimplemented from inet::MobilityBase.

98 {
99  cXMLElement *firstPositionChange = findNextPositionChange(nextPositionChange);
100  if (firstPositionChange)
101  extractDataFrom(firstPositionChange);
103 }

◆ setTargetPosition()

void inet::AnsimMobility::setTargetPosition ( )
overrideprotectedvirtual

Overridden from LineSegmentsMobilityBase.

Implements inet::LineSegmentsMobilityBase.

119 {
121  if (!nextPositionChange) {
122  nextChange = -1;
123  stationary = true;
125  return;
126  }
127 
128  // extract data from it
130 
131  // skip this one
132  nextPositionChange = nextPositionChange->getNextSibling();
133 }

Member Data Documentation

◆ maxSpeed

double inet::AnsimMobility::maxSpeed
protected

Referenced by AnsimMobility(), and computeMaxSpeed().

◆ nextPositionChange

cXMLElement* inet::AnsimMobility::nextPositionChange
protected

points to the next <position_change> element

Referenced by AnsimMobility(), initialize(), setInitialPosition(), and setTargetPosition().

◆ nodeId

int inet::AnsimMobility::nodeId
protected

we'll have to compare this to the <node_id> elements

Referenced by AnsimMobility(), findNextPositionChange(), and initialize().


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::AnsimMobility::extractDataFrom
virtual void extractDataFrom(cXMLElement *node)
Utility: extract data from given <position_update> element.
Definition: AnsimMobility.cc:135
inet::LineSegmentsMobilityBase::targetPosition
Coord targetPosition
End position of current linear movement.
Definition: LineSegmentsMobilityBase.h:28
inet::getContainingNode
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:40
inet::MovingMobilityBase::stationary
bool stationary
A mobility model may decide to become stationary at any time.
Definition: MovingMobilityBase.h:32
inet::Coord::x
double x
Definition: Coord.h:36
inet::LineSegmentsMobilityBase::move
virtual void move() override
Moves according to the mobility model to the current simulation time.
Definition: LineSegmentsMobilityBase.cc:31
inet::MovingMobilityBase::initialize
virtual void initialize(int stage) override
Initializes mobility model parameters.
Definition: MovingMobilityBase.cc:26
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::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::AnsimMobility::maxSpeed
double maxSpeed
Definition: AnsimMobility.h:28
inet::MobilityBase::raiseErrorIfOutside
virtual void raiseErrorIfOutside()
Utility function to raise an error if the node gets outside the constraint area.
Definition: MobilityBase.cc:343
NUM_INIT_STAGES
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
inet::AnsimMobility::findNextPositionChange
virtual cXMLElement * findNextPositionChange(cXMLElement *positionChange)
Finds the next <position_change> element.
Definition: AnsimMobility.cc:105
inet::AnsimMobility::nodeId
int nodeId
we'll have to compare this to the <node_id> elements
Definition: AnsimMobility.h:25
inet::AnsimMobility::nextPositionChange
cXMLElement * nextPositionChange
points to the next <position_change> element
Definition: AnsimMobility.h:27
inet::AnsimMobility::computeMaxSpeed
virtual void computeMaxSpeed()
Definition: AnsimMobility.cc:29
inet::Coord::y
double y
Definition: Coord.h:37