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 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 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

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 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 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 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

std::vector< Waypointwaypoints
 
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 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...
 

Member Function Documentation

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

Returns the maximum possible speed at any future time.

Reimplemented from inet::MobilityBase.

55 { return speed; }
double speed
Definition: VehicleMobility.h:41
void inet::VehicleMobility::initialize ( int  stage)
overrideprotectedvirtual

Initializes mobility model parameters.

Reimplemented from inet::MovingMobilityBase.

28 {
30  EV_TRACE << "initializing VehicleMobility stage " << stage << endl;
31  if (stage == INITSTAGE_LOCAL) {
32  speed = par("speed");
33  waypointProximity = par("waypointProximity");
34  targetPointIndex = 0;
35  heading = 0;
36  angularSpeed = 0;
37  }
38  else if (stage == INITSTAGE_PHYSICAL_ENVIRONMENT)
39  readWaypointsFromFile(par("waypointFile"));
40 }
virtual void initialize(int stage) override
Initializes mobility model parameters.
Definition: MovingMobilityBase.cc:42
double angularSpeed
Definition: VehicleMobility.h:44
int targetPointIndex
Definition: VehicleMobility.h:45
Physical environment initializations (mobility, obstacles, battery, annotations, etc).
Definition: InitStages.h:40
double waypointProximity
Definition: VehicleMobility.h:43
Local initializations.
Definition: InitStages.h:35
virtual void readWaypointsFromFile(const char *fileName)
Definition: VehicleMobility.cc:50
double speed
Definition: VehicleMobility.h:41
double heading
Definition: VehicleMobility.h:42
void inet::VehicleMobility::move ( )
overrideprotectedvirtual

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.

Implements inet::MovingMobilityBase.

85 {
86  Waypoint target = waypoints[targetPointIndex];
87  double dx = target.x - lastPosition.x;
88  double dy = target.y - lastPosition.y;
89  if (dx * dx + dy * dy < waypointProximity * waypointProximity) // reached so change to next (within the predefined proximity of the waypoint)
91  double targetDirection = atan2(dy, dx) / M_PI * 180;
92  double diff = targetDirection - heading;
93  while (diff < -180)
94  diff += 360;
95  while (diff > 180)
96  diff -= 360;
97  angularSpeed = diff * 5;
98  double timeStep = (simTime() - lastUpdate).dbl();
99  heading += angularSpeed * timeStep;
100  double distance = speed * timeStep;
101  lastPosition.x += distance * cos(M_PI * heading / 180);
102  lastPosition.y += distance * sin(M_PI * heading / 180);
103  lastSpeed.x = speed * cos(M_PI * heading / 180);
104  lastSpeed.y = speed * sin(M_PI * heading / 180);
105 }
double angularSpeed
Definition: VehicleMobility.h:44
Value cos(const value< Value, Unit > &angle)
Definition: Units.h:1201
int targetPointIndex
Definition: VehicleMobility.h:45
std::vector< Waypoint > waypoints
Definition: VehicleMobility.h:39
simtime_t lastUpdate
The simulation time when the mobility state was last updated.
Definition: MovingMobilityBase.h:55
Coord lastPosition
The last position that was reported.
Definition: MobilityBase.h:78
double waypointProximity
Definition: VehicleMobility.h:43
#define M_PI
Definition: PlotFigure.cc:27
double speed
Definition: VehicleMobility.h:41
double y
Definition: Coord.h:50
double x
Definition: Coord.h:49
Value sin(const value< Value, Unit > &angle)
Definition: Units.h:1195
Coord lastSpeed
The last speed that was reported at lastUpdate.
Definition: MovingMobilityBase.h:52
double heading
Definition: VehicleMobility.h:42
void inet::VehicleMobility::readWaypointsFromFile ( const char *  fileName)
protectedvirtual

Referenced by initialize().

51 {
52  auto coordinateSystem = getModuleFromPar<IGeographicCoordinateSystem>(par("coordinateSystemModule"), this, false);
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  Coord playgroundCoordinate;
60  double value1 = atof(tokenizer.nextToken());
61  double value2 = atof(tokenizer.nextToken());
62  double value3 = atof(tokenizer.nextToken());
63  double x;
64  double y;
65  double z;
66  if (coordinateSystem == nullptr) {
67  x = value1;
68  y = value2;
69  z = value3;
70  }
71  else {
72  Coord playgroundCoordinate = coordinateSystem->computePlaygroundCoordinate(GeoCoord(value1, value2, value3));
73  x = playgroundCoordinate.x;
74  y = playgroundCoordinate.y;
75  z = playgroundCoordinate.z;
76  }
77  waypoints.push_back(Waypoint(x, y, z));
78  }
79  else
80  break;
81  }
82 }
std::vector< Waypoint > waypoints
Definition: VehicleMobility.h:39
void inet::VehicleMobility::setInitialPosition ( )
overrideprotectedvirtual

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

Reimplemented from inet::MobilityBase.

43 {
46  lastSpeed.x = speed * cos(M_PI * heading / 180);
47  lastSpeed.y = speed * sin(M_PI * heading / 180);
48 }
Value cos(const value< Value, Unit > &angle)
Definition: Units.h:1201
int targetPointIndex
Definition: VehicleMobility.h:45
std::vector< Waypoint > waypoints
Definition: VehicleMobility.h:39
Coord lastPosition
The last position that was reported.
Definition: MobilityBase.h:78
#define M_PI
Definition: PlotFigure.cc:27
double speed
Definition: VehicleMobility.h:41
double y
Definition: Coord.h:50
double x
Definition: Coord.h:49
Value sin(const value< Value, Unit > &angle)
Definition: Units.h:1195
Coord lastSpeed
The last speed that was reported at lastUpdate.
Definition: MovingMobilityBase.h:52
double heading
Definition: VehicleMobility.h:42

Member Data Documentation

double inet::VehicleMobility::angularSpeed
protected

Referenced by initialize(), and move().

double inet::VehicleMobility::heading
protected
double inet::VehicleMobility::speed
protected
int inet::VehicleMobility::targetPointIndex
protected
double inet::VehicleMobility::waypointProximity
protected

Referenced by initialize(), and move().

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

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