A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
waypoint-mobility-model.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2009 Phillip Sitbon
3
*
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
* Author: Phillip Sitbon <phillip@sitbon.net>
18
*/
19
#ifndef WAYPOINT_MOBILITY_MODEL_H
20
#define WAYPOINT_MOBILITY_MODEL_H
21
22
#include "
mobility-model.h
"
23
#include "
waypoint.h
"
24
25
#include "ns3/vector.h"
26
27
#include <deque>
28
#include <stdint.h>
29
30
class
WaypointMobilityModelNotifyTest
;
31
32
namespace
ns3
33
{
34
35
/**
36
* \ingroup mobility
37
* \brief Waypoint-based mobility model.
38
*
39
* Each object determines its velocity and position at a given time
40
* from a set of ns3::Waypoint objects. Past waypoints are discarded
41
* after the current simulation time greater than their time value.
42
*
43
* By default, the initial position of each object corresponds to the
44
* position of the first waypoint, and the initial velocity of each
45
* object is zero. Upon reaching the last waypoint, object position
46
* becomes static and velocity is zero.
47
*
48
* When a node is in between waypoint times, it moves with a constant
49
* velocity between the position at the previous waypoint and the position
50
* at the current waypoint. To make a node hold a certain position for a
51
* time interval, two waypoints with the same position (but different times)
52
* should be inserted sequentially.
53
*
54
* Waypoints can be added at any time, and setting the current position
55
* of an object will set its velocity to zero until the next waypoint time
56
* (at which time the object jumps to the next waypoint), unless there are
57
* no more waypoints in which case it will not change without user
58
* intervention.
59
*
60
* The model has two attributes with methods that allow clients to get
61
* the next waypoint value (NextWaypoint) and the number of waypoints left
62
* (WaypointsLeft) beyond (but not including) the next waypoint.
63
*
64
* In addition, there are two attributes that govern model behavior. The
65
* first, LazyNotify, governs how the model calls the CourseChange trace.
66
* By default, LazyNotify is false, which means that each time that a
67
* waypoint time is hit, an Update() is forced and the CourseChange
68
* callback will be called. When LazyNotify is true, Update() is suppressed
69
* at waypoint times, and CourseChange callbacks will only occur when
70
* there later are actual calls to Update () (typically when calling
71
* GetPosition ()). This option may be enabled for execution run-time
72
* performance improvements, but when enabled, users should note that
73
* course change listeners will in general not be notified at waypoint
74
* times but instead at the next Update() following a waypoint time,
75
* and some waypoints may not be notified to course change listeners.
76
*
77
* The second, InitialPositionIsWaypoint, is false by default. Recall
78
* that the first waypoint will set the initial position and set velocity
79
* equal to 0 until the first waypoint time. In such a case, the
80
* call to SetPosition(), such as from a PositionAllocator, will be
81
* ignored. However, if InitialPositionIsWaypoint is set to true
82
* and SetPosition() is called before any waypoints have been added,
83
* the SetPosition() call is treated as an initial waypoint at time zero.
84
* In such a case, when SetPosition() is treated as an initial waypoint,
85
* it should be noted that attempts to add a waypoint at the same time
86
* will cause the program to fail.
87
*/
88
class
WaypointMobilityModel
:
public
MobilityModel
89
{
90
public
:
91
/**
92
* Register this type with the TypeId system.
93
* \return the object TypeId
94
*/
95
static
TypeId
GetTypeId
();
96
97
/**
98
* Create a path with no waypoints at location (0,0,0).
99
*/
100
WaypointMobilityModel
();
101
~WaypointMobilityModel
()
override
;
102
103
/**
104
* \param waypoint waypoint to append to the object path.
105
*
106
* Add a waypoint to the path of the object. The time must
107
* be greater than the previous waypoint added, otherwise
108
* a fatal error occurs. The first waypoint is set as the
109
* current position with a velocity of zero.
110
*
111
*/
112
void
AddWaypoint
(
const
Waypoint
& waypoint);
113
114
/**
115
* Get the waypoint that this object is traveling towards.
116
* \returns The waypoint
117
*/
118
Waypoint
GetNextWaypoint
()
const
;
119
120
/**
121
* Get the number of waypoints left for this object, excluding
122
* the next one.
123
* \returns The number of waypoints left
124
*/
125
uint32_t
WaypointsLeft
()
const
;
126
127
/**
128
* Clear any existing waypoints and set the current waypoint
129
* time to infinity. Calling this is only an optimization and
130
* not required. After calling this function, adding waypoints
131
* behaves as it would for a new object.
132
*/
133
void
EndMobility
();
134
135
private
:
136
friend
class ::WaypointMobilityModelNotifyTest;
// To allow Update() calls and access to
137
// m_current
138
139
/**
140
* Update the underlying state corresponding to the stored waypoints
141
*/
142
virtual
void
Update
()
const
;
143
/**
144
* \brief The dispose method.
145
*
146
* Subclasses must override this method.
147
*/
148
void
DoDispose
()
override
;
149
/**
150
* \brief Get current position.
151
* \return A vector with the current position of the node.
152
*/
153
Vector
DoGetPosition
()
const override
;
154
/**
155
* \brief Sets a new position for the node
156
* \param position A vector to be added as the new position
157
*/
158
void
DoSetPosition
(
const
Vector& position)
override
;
159
/**
160
* \brief Returns the current velocity of a node
161
* \return The velocity vector of a node.
162
*/
163
Vector
DoGetVelocity
()
const override
;
164
165
protected
:
166
/**
167
* \brief This variable is set to true if there are no waypoints in the std::deque
168
*/
169
bool
m_first
;
170
/**
171
* \brief If true, course change updates are only notified when position
172
* is calculated.
173
*/
174
bool
m_lazyNotify
;
175
/**
176
* \brief If true, calling SetPosition with no waypoints creates a waypoint
177
*/
178
bool
m_initialPositionIsWaypoint
;
179
/**
180
* \brief The double ended queue containing the ns3::Waypoint objects
181
*/
182
mutable
std::deque<Waypoint>
m_waypoints
;
183
/**
184
* \brief The ns3::Waypoint currently being used
185
*/
186
mutable
Waypoint
m_current
;
187
/**
188
* \brief The next ns3::Waypoint in the deque
189
*/
190
mutable
Waypoint
m_next
;
191
/**
192
* \brief The current velocity vector
193
*/
194
mutable
Vector
m_velocity
;
195
};
196
197
}
// namespace ns3
198
199
#endif
/* WAYPOINT_MOBILITY_MODEL_H */
WaypointMobilityModelNotifyTest
Waypoint Mobility Model Notify Test.
Definition:
waypoint-mobility-model-test.cc:34
ns3::MobilityModel
Keep track of the current position and velocity of an object.
Definition:
mobility-model.h:40
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:59
ns3::Waypoint
a (time, location) pair.
Definition:
waypoint.h:36
ns3::WaypointMobilityModel
Waypoint-based mobility model.
Definition:
waypoint-mobility-model.h:89
ns3::WaypointMobilityModel::m_velocity
Vector m_velocity
The current velocity vector.
Definition:
waypoint-mobility-model.h:194
ns3::WaypointMobilityModel::DoDispose
void DoDispose() override
The dispose method.
Definition:
waypoint-mobility-model.cc:83
ns3::WaypointMobilityModel::GetNextWaypoint
Waypoint GetNextWaypoint() const
Get the waypoint that this object is traveling towards.
Definition:
waypoint-mobility-model.cc:110
ns3::WaypointMobilityModel::m_initialPositionIsWaypoint
bool m_initialPositionIsWaypoint
If true, calling SetPosition with no waypoints creates a waypoint.
Definition:
waypoint-mobility-model.h:178
ns3::WaypointMobilityModel::Update
virtual void Update() const
Update the underlying state corresponding to the stored waypoints.
Definition:
waypoint-mobility-model.cc:124
ns3::WaypointMobilityModel::DoGetVelocity
Vector DoGetVelocity() const override
Returns the current velocity of a node.
Definition:
waypoint-mobility-model.cc:226
ns3::WaypointMobilityModel::WaypointMobilityModel
WaypointMobilityModel()
Create a path with no waypoints at location (0,0,0).
Definition:
waypoint-mobility-model.cc:71
ns3::WaypointMobilityModel::WaypointsLeft
uint32_t WaypointsLeft() const
Get the number of waypoints left for this object, excluding the next one.
Definition:
waypoint-mobility-model.cc:117
ns3::WaypointMobilityModel::m_current
Waypoint m_current
The ns3::Waypoint currently being used.
Definition:
waypoint-mobility-model.h:186
ns3::WaypointMobilityModel::m_first
bool m_first
This variable is set to true if there are no waypoints in the std::deque.
Definition:
waypoint-mobility-model.h:169
ns3::WaypointMobilityModel::m_waypoints
std::deque< Waypoint > m_waypoints
The double ended queue containing the ns3::Waypoint objects.
Definition:
waypoint-mobility-model.h:182
ns3::WaypointMobilityModel::m_lazyNotify
bool m_lazyNotify
If true, course change updates are only notified when position is calculated.
Definition:
waypoint-mobility-model.h:174
ns3::WaypointMobilityModel::EndMobility
void EndMobility()
Clear any existing waypoints and set the current waypoint time to infinity.
Definition:
waypoint-mobility-model.cc:217
ns3::WaypointMobilityModel::DoSetPosition
void DoSetPosition(const Vector &position) override
Sets a new position for the node.
Definition:
waypoint-mobility-model.cc:194
ns3::WaypointMobilityModel::DoGetPosition
Vector DoGetPosition() const override
Get current position.
Definition:
waypoint-mobility-model.cc:187
ns3::WaypointMobilityModel::m_next
Waypoint m_next
The next ns3::Waypoint in the deque.
Definition:
waypoint-mobility-model.h:190
ns3::WaypointMobilityModel::GetTypeId
static TypeId GetTypeId()
Register this type with the TypeId system.
Definition:
waypoint-mobility-model.cc:39
ns3::WaypointMobilityModel::AddWaypoint
void AddWaypoint(const Waypoint &waypoint)
Definition:
waypoint-mobility-model.cc:89
ns3::WaypointMobilityModel::~WaypointMobilityModel
~WaypointMobilityModel() override
Definition:
waypoint-mobility-model.cc:78
uint32_t
mobility-model.h
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
waypoint.h
src
mobility
model
waypoint-mobility-model.h
Generated on Tue May 28 2024 23:38:19 for ns-3 by
1.9.6