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/mobility-export.h"
12#include "ns3/object.h"
13#include "ns3/traced-callback.h"
14#include "ns3/vector.h"
15
16namespace ns3
17{
18
19/**
20 * @ingroup mobility
21 * @brief Keep track of the current position and velocity of an object.
22 *
23 * All space coordinates in this class and its subclasses are
24 * understood to be meters or meters/s. i.e., they are all
25 * metric international units.
26 *
27 * This is a base class for all specific mobility models.
28 */
29class MOBILITY_EXPORT MobilityModel : public Object
30{
31 public:
32 /**
33 * Register this type with the TypeId system.
34 * @return the object TypeId
35 */
36 static TypeId GetTypeId();
38 ~MobilityModel() override = 0;
39
40 /**
41 * Copy function allows one to copy the underlying MobilityModel
42 * from a MobilityModel pointer, by calling each children Copy implementation.
43 * This is primarily used by wraparound models for the spectrum channel.
44 *
45 * @return a copy of the current mobility model
46 */
47 virtual Ptr<MobilityModel> Copy() const = 0;
48
49 /**
50 * @return the current position
51 */
52 Vector GetPosition() const;
53 /**
54 * This method may be used if the position returned may depend on some
55 * reference position provided. For example, in a hierarchical mobility
56 * model that is buildings-aware, the child mobility model may not be able
57 * to determine if it is inside or outside of a building unless it knows
58 * the parent position.
59 *
60 * @param referencePosition reference position to consider
61 * @return the current position based on the provided referencePosition
62 * \sa ns3::MobilityModel::DoGetPositionWithReference
63 */
64 Vector GetPositionWithReference(const Vector& referencePosition) const;
65 /**
66 * @param position the position to set.
67 */
68 void SetPosition(const Vector& position);
69 /**
70 * @return the current velocity.
71 */
72 Vector GetVelocity() const;
73 /**
74 * @param position a reference to another mobility model
75 * @return the distance between the two objects. Unit is meters.
76 */
77 double GetDistanceFrom(Ptr<const MobilityModel> position) const;
78 /**
79 * @param other reference to another object's mobility model
80 * @return the relative speed between the two objects. Unit is meters/s.
81 */
83 /**
84 * Assign a fixed random variable stream number to the random variables
85 * used by this model. Return the number of streams (possibly zero) that
86 * have been assigned.
87 *
88 * @param stream first stream index to use
89 * @return the number of stream indices assigned by this model
90 */
91 int64_t AssignStreams(int64_t stream);
92
93 /**
94 * TracedCallback signature.
95 *
96 * @param [in] model Value of the MobilityModel.
97 */
99
100 protected:
101 /**
102 * Must be invoked by subclasses when the course of the
103 * position changes to notify course change listeners.
104 */
105 void NotifyCourseChange() const;
106
107 private:
108 /**
109 * @return the current position.
110 *
111 * Concrete subclasses of this base class must
112 * implement this method.
113 */
114 virtual Vector DoGetPosition() const = 0;
115 /**
116 * @param referencePosition the reference position to consider
117 * @return the current position.
118 *
119 * Unless subclasses override, this method will disregard the reference
120 * position and return "DoGetPosition ()".
121 */
122 virtual Vector DoGetPositionWithReference(const Vector& referencePosition) const;
123 /**
124 * @param position the position to set.
125 *
126 * Concrete subclasses of this base class must
127 * implement this method.
128 */
129 virtual void DoSetPosition(const Vector& position) = 0;
130 /**
131 * @return the current velocity.
132 *
133 * Concrete subclasses of this base class must
134 * implement this method.
135 */
136 virtual Vector DoGetVelocity() const = 0;
137 /**
138 * The default implementation does nothing but return the passed-in
139 * parameter. Subclasses using random variables are expected to
140 * override this.
141 * @param start starting stream index
142 * @return the number of streams used
143 */
144 virtual int64_t DoAssignStreams(int64_t start);
145
146 /**
147 * Used to alert subscribers that a change in direction, velocity,
148 * or position has occurred.
149 */
151};
152
153} // namespace ns3
154
155#endif /* MOBILITY_MODEL_H */
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
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 Ptr< MobilityModel > Copy() const =0
Copy function allows one to copy the underlying MobilityModel from a MobilityModel pointer,...
void(* TracedCallback)(Ptr< const MobilityModel > model)
TracedCallback signature.
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
Object()
Constructor.
Definition object.cc:96
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:67
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition type-id.h:49
Every class exported by the ns3 library is enclosed in the ns3 namespace.