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

#include <VehicleMobility.h>

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

Classes

struct  Waypoint
 

Public Member Functions

virtual double getMaxSpeed () const override
 Returns the maximum possible speed at any future time. More...
 
- 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 void initialize (int stage) override
 Initializes mobility model parameters. More...
 
virtual void setInitialPosition () override
 Initializes the position from the display string or from module parameters. More...
 
virtual void move () override
 Moves according to the mobility model to the current simulation time. More...
 
virtual void orient () override
 
virtual void readWaypointsFromFile (const char *fileName)
 
- 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...
 
- 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 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

std::vector< Waypointwaypoints
 
physicalenvironment::IGroundground = nullptr
 
double speed
 
double heading
 
double waypointProximity
 
double angularSpeed
 
int targetPointIndex
 
- 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...
 

Member Function Documentation

◆ getMaxSpeed()

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

Returns the maximum possible speed at any future time.

Reimplemented from inet::MobilityBase.

49 { return speed; }

◆ initialize()

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

Initializes mobility model parameters.

Reimplemented from inet::MovingMobilityBase.

23 {
25  EV_TRACE << "initializing VehicleMobility stage " << stage << endl;
26  if (stage == INITSTAGE_LOCAL) {
27  speed = par("speed");
28  waypointProximity = par("waypointProximity");
29  targetPointIndex = 0;
30  heading = 0;
31  angularSpeed = 0;
32  readWaypointsFromFile(par("waypointFile"));
33  ground = findModuleFromPar<IGround>(par("groundModule"), this);
34  }
35 }

◆ move()

void inet::VehicleMobility::move ( )
overrideprotectedvirtual

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.

Implements inet::MovingMobilityBase.

84 {
85  Waypoint target = waypoints[targetPointIndex];
86  double dx = target.x - lastPosition.x;
87  double dy = target.y - lastPosition.y;
88  if (dx * dx + dy * dy < waypointProximity * waypointProximity) // reached so change to next (within the predefined proximity of the waypoint)
90  double targetDirection = atan2(dy, dx) / M_PI * 180;
91  double diff = targetDirection - heading;
92  while (diff < -180)
93  diff += 360;
94  while (diff > 180)
95  diff -= 360;
96  angularSpeed = diff * 5;
97  double timeStep = (simTime() - lastUpdate).dbl();
98  heading += angularSpeed * timeStep;
99 
100  Coord tempSpeed = Coord(cos(M_PI * heading / 180), sin(M_PI * heading / 180)) * speed;
101  Coord tempPosition = lastPosition + tempSpeed * timeStep;
102 
103  if (ground)
104  tempPosition = ground->computeGroundProjection(tempPosition);
105 
106  lastVelocity = tempPosition - lastPosition;
107  lastPosition = tempPosition;
108 }

◆ orient()

void inet::VehicleMobility::orient ( )
overrideprotectedvirtual

Reimplemented from inet::MovingMobilityBase.

111 {
112  if (ground) {
113  Coord groundNormal = ground->computeGroundNormal(lastPosition);
114 
115  // this will make the wheels follow the ground
116  Quaternion quat = Quaternion::rotationFromTo(Coord(0, 0, 1), groundNormal);
117 
118  Coord groundTangent = groundNormal % lastVelocity;
119  groundTangent.normalize();
120  Coord direction = groundTangent % groundNormal;
121  direction.normalize(); // this is lastSpeed, normalized and adjusted to be perpendicular to groundNormal
122 
123  // our model looks in this direction if we only rotate the Z axis to match the ground normal
124  Coord groundX = quat.rotate(Coord(1, 0, 0));
125 
126  double dp = groundX * direction;
127 
128  double angle;
129 
130  if (((groundX % direction) * groundNormal) > 0)
131  angle = std::acos(dp);
132  else
133  // correcting for the case where the angle should be over 90 degrees (or under -90):
134  angle = 2 * M_PI - std::acos(dp);
135 
136  // and finally rotating around the now-ground-orthogonal local Z
137  quat *= Quaternion(Coord(0, 0, 1), angle);
138 
139  lastOrientation = quat;
140  }
141  else
143 }

◆ readWaypointsFromFile()

void inet::VehicleMobility::readWaypointsFromFile ( const char *  fileName)
protectedvirtual
51 {
52  auto coordinateSystem = findModuleFromPar<IGeographicCoordinateSystem>(par("coordinateSystemModule"), this);
53  char line[256];
54  std::ifstream inputFile(fileName);
55  while (true) {
56  inputFile.getline(line, 256);
57  if (!inputFile.fail()) {
58  cStringTokenizer tokenizer(line, ",");
59  double value1 = atof(tokenizer.nextToken());
60  double value2 = atof(tokenizer.nextToken());
61  double value3 = atof(tokenizer.nextToken());
62  double x;
63  double y;
64  double z;
65  if (coordinateSystem == nullptr) {
66  x = value1;
67  y = value2;
68  z = value3;
69  }
70  else {
71  Coord sceneCoordinate = coordinateSystem->computeSceneCoordinate(GeoCoord(deg(value1), deg(value2), m(value3)));
72  x = sceneCoordinate.x;
73  y = sceneCoordinate.y;
74  z = sceneCoordinate.z;
75  }
76  waypoints.push_back(Waypoint(x, y, z));
77  }
78  else
79  break;
80  }
81 }

◆ setInitialPosition()

void inet::VehicleMobility::setInitialPosition ( )
overrideprotectedvirtual

Initializes the position from the display string or from module parameters.

Reimplemented from inet::MobilityBase.

Member Data Documentation

◆ angularSpeed

double inet::VehicleMobility::angularSpeed
protected

◆ ground

physicalenvironment::IGround* inet::VehicleMobility::ground = nullptr
protected

◆ heading

double inet::VehicleMobility::heading
protected

◆ speed

double inet::VehicleMobility::speed
protected

◆ targetPointIndex

int inet::VehicleMobility::targetPointIndex
protected

◆ waypointProximity

double inet::VehicleMobility::waypointProximity
protected

◆ waypoints

std::vector<Waypoint> inet::VehicleMobility::waypoints
protected

The documentation for this class was generated from the following files:
inet::VehicleMobility::ground
physicalenvironment::IGround * ground
Definition: VehicleMobility.h:32
inet::VehicleMobility::heading
double heading
Definition: VehicleMobility.h:35
inet::physicalenvironment::IGround::computeGroundProjection
virtual Coord computeGroundProjection(const Coord &position) const =0
Returns a point on the ground "underneath" (or above) the given position.
inet::VehicleMobility::angularSpeed
double angularSpeed
Definition: VehicleMobility.h:37
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::physicalenvironment::IGround::computeGroundNormal
virtual Coord computeGroundNormal(const Coord &position) const =0
Returns a unit length vector that is locally perpendicular to the ground at "position",...
inet::units::units::deg
fscale< rad, rad2degScale > deg
Definition: Units.h:1158
inet::MobilityBase::lastOrientation
Quaternion lastOrientation
The last orientation that was reported.
Definition: MobilityBase.h:76
inet::VehicleMobility::targetPointIndex
int targetPointIndex
Definition: VehicleMobility.h:38
inet::Coord::x
double x
Definition: Coord.h:36
inet::units::cos
Value cos(const value< Value, Unit > &angle)
Definition: Units.h:1524
inet::Quaternion::rotationFromTo
static Quaternion rotationFromTo(const Coord &from, const Coord &to)
Definition: Quaternion.cc:157
inet::VehicleMobility::waypoints
std::vector< Waypoint > waypoints
Definition: VehicleMobility.h:29
inet::MovingMobilityBase::orient
virtual void orient()
Definition: MovingMobilityBase.cc:55
inet::MovingMobilityBase::initialize
virtual void initialize(int stage) override
Initializes mobility model parameters.
Definition: MovingMobilityBase.cc:26
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::VehicleMobility::readWaypointsFromFile
virtual void readWaypointsFromFile(const char *fileName)
Definition: VehicleMobility.cc:50
inet::MovingMobilityBase::lastVelocity
Coord lastVelocity
The last velocity that was reported at lastUpdate.
Definition: MovingMobilityBase.h:35
inet::VehicleMobility::speed
double speed
Definition: VehicleMobility.h:34
inet::Coord::normalize
Coord normalize()
Updates the length of this position vector to be 1.
Definition: Coord.h:280
inet::units::values::m
value< double, units::m > m
Definition: Units.h:1233
inet::VehicleMobility::waypointProximity
double waypointProximity
Definition: VehicleMobility.h:36
inet::Coord::y
double y
Definition: Coord.h:37
M_PI
#define M_PI
Definition: INETMath.h:52
inet::units::sin
Value sin(const value< Value, Unit > &angle)
Definition: Units.h:1518