A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
mobility-model.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006,2007 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8#ifndef MOBILITY_MODEL_H
9#define MOBILITY_MODEL_H
10
11#include "ns3/object.h"
12#include "ns3/traced-callback.h"
13#include "ns3/vector.h"
14
15namespace ns3
16{
17
18/**
19 * \ingroup mobility
20 * \brief Keep track of the current position and velocity of an object.
21 *
22 * All space coordinates in this class and its subclasses are
23 * understood to be meters or meters/s. i.e., they are all
24 * metric international units.
25 *
26 * This is a base class for all specific mobility models.
27 */
28class MobilityModel : public Object
29{
30 public:
31 /**
32 * Register this type with the TypeId system.
33 * \return the object TypeId
34 */
35 static TypeId GetTypeId();
37 ~MobilityModel() override = 0;
38
39 /**
40 * \return the current position
41 */
42 Vector GetPosition() const;
43 /**
44 * This method may be used if the position returned may depend on some
45 * reference position provided. For example, in a hierarchical mobility
46 * model that is buildings-aware, the child mobility model may not be able
47 * to determine if it is inside or outside of a building unless it knows
48 * the parent position.
49 *
50 * \param referencePosition reference position to consider
51 * \return the current position based on the provided referencePosition
52 * \sa ns3::MobilityModel::DoGetPositionWithReference
53 */
54 Vector GetPositionWithReference(const Vector& referencePosition) const;
55 /**
56 * \param position the position to set.
57 */
58 void SetPosition(const Vector& position);
59 /**
60 * \return the current velocity.
61 */
62 Vector GetVelocity() const;
63 /**
64 * \param position a reference to another mobility model
65 * \return the distance between the two objects. Unit is meters.
66 */
67 double GetDistanceFrom(Ptr<const MobilityModel> position) const;
68 /**
69 * \param other reference to another object's mobility model
70 * \return the relative speed between the two objects. Unit is meters/s.
71 */
73 /**
74 * Assign a fixed random variable stream number to the random variables
75 * used by this model. Return the number of streams (possibly zero) that
76 * have been assigned.
77 *
78 * \param stream first stream index to use
79 * \return the number of stream indices assigned by this model
80 */
81 int64_t AssignStreams(int64_t stream);
82
83 /**
84 * TracedCallback signature.
85 *
86 * \param [in] model Value of the MobilityModel.
87 */
89
90 protected:
91 /**
92 * Must be invoked by subclasses when the course of the
93 * position changes to notify course change listeners.
94 */
95 void NotifyCourseChange() const;
96
97 private:
98 /**
99 * \return the current position.
100 *
101 * Concrete subclasses of this base class must
102 * implement this method.
103 */
104 virtual Vector DoGetPosition() const = 0;
105 /**
106 * \param referencePosition the reference position to consider
107 * \return the current position.
108 *
109 * Unless subclasses override, this method will disregard the reference
110 * position and return "DoGetPosition ()".
111 */
112 virtual Vector DoGetPositionWithReference(const Vector& referencePosition) const;
113 /**
114 * \param position the position to set.
115 *
116 * Concrete subclasses of this base class must
117 * implement this method.
118 */
119 virtual void DoSetPosition(const Vector& position) = 0;
120 /**
121 * \return the current velocity.
122 *
123 * Concrete subclasses of this base class must
124 * implement this method.
125 */
126 virtual Vector DoGetVelocity() const = 0;
127 /**
128 * The default implementation does nothing but return the passed-in
129 * parameter. Subclasses using random variables are expected to
130 * override this.
131 * \param start starting stream index
132 * \return the number of streams used
133 */
134 virtual int64_t DoAssignStreams(int64_t start);
135
136 /**
137 * Used to alert subscribers that a change in direction, velocity,
138 * or position has occurred.
139 */
141};
142
143} // namespace ns3
144
145#endif /* MOBILITY_MODEL_H */
Keep track of the current position and velocity of an object.
ns3::TracedCallback< Ptr< const MobilityModel > > m_courseChangeTrace
Used to alert subscribers that a change in direction, velocity, or position has occurred.
Vector GetPositionWithReference(const Vector &referencePosition) const
This method may be used if the position returned may depend on some reference position provided.
static TypeId GetTypeId()
Register this type with the TypeId system.
double GetDistanceFrom(Ptr< const MobilityModel > position) const
~MobilityModel() override=0
double GetRelativeSpeed(Ptr< const MobilityModel > other) const
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
virtual Vector DoGetPosition() const =0
virtual Vector DoGetPositionWithReference(const Vector &referencePosition) const
Vector GetVelocity() const
virtual void DoSetPosition(const Vector &position)=0
virtual int64_t DoAssignStreams(int64_t start)
The default implementation does nothing but return the passed-in parameter.
Vector GetPosition() const
void SetPosition(const Vector &position)
void NotifyCourseChange() const
Must be invoked by subclasses when the course of the position changes to notify course change listene...
virtual Vector DoGetVelocity() const =0
A base class which provides memory management and object aggregation.
Definition object.h:78
Smart pointer class similar to boost::intrusive_ptr.
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition type-id.h:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.