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
constant-velocity-helper.cc
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
#include "
constant-velocity-helper.h
"
9
10
#include "
box.h
"
11
#include "
rectangle.h
"
12
13
#include "ns3/log.h"
14
#include "ns3/simulator.h"
15
16
namespace
ns3
17
{
18
19
NS_LOG_COMPONENT_DEFINE
(
"ConstantVelocityHelper"
);
20
21
ConstantVelocityHelper::ConstantVelocityHelper
()
22
: m_paused(
true
)
23
{
24
NS_LOG_FUNCTION
(
this
);
25
}
26
27
ConstantVelocityHelper::ConstantVelocityHelper
(
const
Vector& position)
28
: m_position(position),
29
m_paused(
true
)
30
{
31
NS_LOG_FUNCTION
(
this
<< position);
32
}
33
34
ConstantVelocityHelper::ConstantVelocityHelper
(
const
Vector& position,
const
Vector& vel)
35
: m_position(position),
36
m_velocity(vel),
37
m_paused(
true
)
38
{
39
NS_LOG_FUNCTION
(
this
<< position << vel);
40
}
41
42
void
43
ConstantVelocityHelper::SetPosition
(
const
Vector& position)
44
{
45
NS_LOG_FUNCTION
(
this
<< position);
46
m_position
= position;
47
m_velocity
= Vector(0.0, 0.0, 0.0);
48
m_lastUpdate
=
Simulator::Now
();
49
}
50
51
Vector
52
ConstantVelocityHelper::GetCurrentPosition
()
const
53
{
54
NS_LOG_FUNCTION
(
this
);
55
return
m_position
;
56
}
57
58
Vector
59
ConstantVelocityHelper::GetVelocity
()
const
60
{
61
NS_LOG_FUNCTION
(
this
);
62
return
m_paused
? Vector(0.0, 0.0, 0.0) :
m_velocity
;
63
}
64
65
void
66
ConstantVelocityHelper::SetVelocity
(
const
Vector& vel)
67
{
68
NS_LOG_FUNCTION
(
this
<< vel);
69
m_velocity
= vel;
70
m_lastUpdate
=
Simulator::Now
();
71
}
72
73
void
74
ConstantVelocityHelper::Update
()
const
75
{
76
NS_LOG_FUNCTION
(
this
);
77
Time
now =
Simulator::Now
();
78
NS_ASSERT
(
m_lastUpdate
<= now);
79
Time
deltaTime
= now -
m_lastUpdate
;
80
m_lastUpdate
= now;
81
if
(
m_paused
)
82
{
83
return
;
84
}
85
double
deltaS
=
deltaTime
.
GetSeconds
();
86
m_position
.x +=
m_velocity
.x *
deltaS
;
87
m_position
.y +=
m_velocity
.y *
deltaS
;
88
m_position
.z +=
m_velocity
.z *
deltaS
;
89
}
90
91
void
92
ConstantVelocityHelper::UpdateWithBounds
(
const
Rectangle
&
bounds
)
const
93
{
94
NS_LOG_FUNCTION
(
this
<<
bounds
);
95
Update
();
96
m_position
.x = std::min(
bounds
.xMax,
m_position
.x);
97
m_position
.x = std::max(
bounds
.xMin,
m_position
.x);
98
m_position
.y = std::min(
bounds
.yMax,
m_position
.y);
99
m_position
.y = std::max(
bounds
.yMin,
m_position
.y);
100
}
101
102
void
103
ConstantVelocityHelper::UpdateWithBounds
(
const
Box
&
bounds
)
const
104
{
105
NS_LOG_FUNCTION
(
this
<<
bounds
);
106
Update
();
107
m_position
.x = std::min(
bounds
.xMax,
m_position
.x);
108
m_position
.x = std::max(
bounds
.xMin,
m_position
.x);
109
m_position
.y = std::min(
bounds
.yMax,
m_position
.y);
110
m_position
.y = std::max(
bounds
.yMin,
m_position
.y);
111
m_position
.z = std::min(
bounds
.zMax,
m_position
.z);
112
m_position
.z = std::max(
bounds
.zMin,
m_position
.z);
113
}
114
115
void
116
ConstantVelocityHelper::Pause
()
117
{
118
NS_LOG_FUNCTION
(
this
);
119
m_paused
=
true
;
120
}
121
122
void
123
ConstantVelocityHelper::Unpause
()
124
{
125
NS_LOG_FUNCTION
(
this
);
126
m_paused
=
false
;
127
}
128
129
}
// namespace ns3
box.h
ns3::Box
a 3d box
Definition
box.h:24
ns3::ConstantVelocityHelper::ConstantVelocityHelper
ConstantVelocityHelper()
Definition
constant-velocity-helper.cc:21
ns3::ConstantVelocityHelper::m_lastUpdate
Time m_lastUpdate
time of last update
Definition
constant-velocity-helper.h:88
ns3::ConstantVelocityHelper::GetCurrentPosition
Vector GetCurrentPosition() const
Get current position vector.
Definition
constant-velocity-helper.cc:52
ns3::ConstantVelocityHelper::m_position
Vector m_position
state variable for current position
Definition
constant-velocity-helper.h:89
ns3::ConstantVelocityHelper::GetVelocity
Vector GetVelocity() const
Get velocity; if paused, will return a zero vector.
Definition
constant-velocity-helper.cc:59
ns3::ConstantVelocityHelper::Update
void Update() const
Update position, if not paused, from last position and time of last update.
Definition
constant-velocity-helper.cc:74
ns3::ConstantVelocityHelper::UpdateWithBounds
void UpdateWithBounds(const Rectangle &rectangle) const
Update position, if not paused, from last position and time of last update.
Definition
constant-velocity-helper.cc:92
ns3::ConstantVelocityHelper::Unpause
void Unpause()
Resume mobility from current position at current velocity.
Definition
constant-velocity-helper.cc:123
ns3::ConstantVelocityHelper::SetPosition
void SetPosition(const Vector &position)
Set position vector.
Definition
constant-velocity-helper.cc:43
ns3::ConstantVelocityHelper::SetVelocity
void SetVelocity(const Vector &vel)
Set new velocity vector.
Definition
constant-velocity-helper.cc:66
ns3::ConstantVelocityHelper::Pause
void Pause()
Pause mobility at current position.
Definition
constant-velocity-helper.cc:116
ns3::ConstantVelocityHelper::m_velocity
Vector m_velocity
state variable for velocity
Definition
constant-velocity-helper.h:90
ns3::ConstantVelocityHelper::m_paused
bool m_paused
state variable for paused
Definition
constant-velocity-helper.h:91
ns3::Rectangle
a 2d rectangle
Definition
rectangle.h:24
ns3::Simulator::Now
static Time Now()
Return the current simulation virtual time.
Definition
simulator.cc:197
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition
nstime.h:94
ns3::Time::GetSeconds
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition
nstime.h:392
constant-velocity-helper.h
NS_ASSERT
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition
assert.h:55
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition
log-macros-enabled.h:229
ns3::Create
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition
ptr.h:436
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
rectangle.h
src
mobility
model
constant-velocity-helper.cc
Generated on Mon Dec 15 2025 15:22:00 for ns-3 by
1.9.8