A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
constant-acceleration-mobility-model.cc
Go to the documentation of this file.
1
/*
2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License version 2 as
4
* published by the Free Software Foundation;
5
*
6
* This program is distributed in the hope that it will be useful,
7
* but WITHOUT ANY WARRANTY; without even the implied warranty of
8
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
* GNU General Public License for more details.
10
*
11
* You should have received a copy of the GNU General Public License
12
* along with this program; if not, write to the Free Software
13
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14
*
15
* Author: Gustavo Carneiro <gjc@inescporto.pt>
16
*/
17
#include "
constant-acceleration-mobility-model.h
"
18
19
#include "ns3/simulator.h"
20
21
namespace
ns3
22
{
23
24
NS_OBJECT_ENSURE_REGISTERED
(ConstantAccelerationMobilityModel);
25
26
TypeId
27
ConstantAccelerationMobilityModel::GetTypeId
()
28
{
29
static
TypeId
tid =
TypeId
(
"ns3::ConstantAccelerationMobilityModel"
)
30
.
SetParent
<
MobilityModel
>()
31
.SetGroupName(
"Mobility"
)
32
.AddConstructor<
ConstantAccelerationMobilityModel
>();
33
return
tid;
34
}
35
36
ConstantAccelerationMobilityModel::ConstantAccelerationMobilityModel
()
37
{
38
}
39
40
ConstantAccelerationMobilityModel::~ConstantAccelerationMobilityModel
()
41
{
42
}
43
44
inline
Vector
45
ConstantAccelerationMobilityModel::DoGetVelocity
()
const
46
{
47
double
t = (
Simulator::Now
() -
m_baseTime
).GetSeconds();
48
return
Vector(
m_baseVelocity
.x +
m_acceleration
.x * t,
49
m_baseVelocity
.y +
m_acceleration
.y * t,
50
m_baseVelocity
.z +
m_acceleration
.z * t);
51
}
52
53
inline
Vector
54
ConstantAccelerationMobilityModel::DoGetPosition
()
const
55
{
56
double
t = (
Simulator::Now
() -
m_baseTime
).GetSeconds();
57
double
half_t_square = t * t * 0.5;
58
return
Vector(
m_basePosition
.x +
m_baseVelocity
.x * t +
m_acceleration
.x * half_t_square,
59
m_basePosition
.y +
m_baseVelocity
.y * t +
m_acceleration
.y * half_t_square,
60
m_basePosition
.z +
m_baseVelocity
.z * t +
m_acceleration
.z * half_t_square);
61
}
62
63
void
64
ConstantAccelerationMobilityModel::DoSetPosition
(
const
Vector& position)
65
{
66
m_baseVelocity
=
DoGetVelocity
();
67
m_baseTime
=
Simulator::Now
();
68
m_basePosition
= position;
69
NotifyCourseChange
();
70
}
71
72
void
73
ConstantAccelerationMobilityModel::SetVelocityAndAcceleration
(
const
Vector& velocity,
74
const
Vector& acceleration)
75
{
76
m_basePosition
=
DoGetPosition
();
77
m_baseTime
=
Simulator::Now
();
78
m_baseVelocity
= velocity;
79
m_acceleration
= acceleration;
80
NotifyCourseChange
();
81
}
82
83
}
// namespace ns3
ns3::ConstantAccelerationMobilityModel
Mobility model for which the current acceleration does not change once it has been set and until it i...
Definition:
constant-acceleration-mobility-model.h:34
ns3::ConstantAccelerationMobilityModel::SetVelocityAndAcceleration
void SetVelocityAndAcceleration(const Vector &velocity, const Vector &acceleration)
Set the model's velocity and acceleration.
Definition:
constant-acceleration-mobility-model.cc:73
ns3::ConstantAccelerationMobilityModel::GetTypeId
static TypeId GetTypeId()
Register this type with the TypeId system.
Definition:
constant-acceleration-mobility-model.cc:27
ns3::ConstantAccelerationMobilityModel::m_basePosition
Vector m_basePosition
the base position
Definition:
constant-acceleration-mobility-model.h:60
ns3::ConstantAccelerationMobilityModel::DoSetPosition
void DoSetPosition(const Vector &position) override
Definition:
constant-acceleration-mobility-model.cc:64
ns3::ConstantAccelerationMobilityModel::~ConstantAccelerationMobilityModel
~ConstantAccelerationMobilityModel() override
Definition:
constant-acceleration-mobility-model.cc:40
ns3::ConstantAccelerationMobilityModel::ConstantAccelerationMobilityModel
ConstantAccelerationMobilityModel()
Create position located at coordinates (0,0,0) with speed (0,0,0).
Definition:
constant-acceleration-mobility-model.cc:36
ns3::ConstantAccelerationMobilityModel::m_acceleration
Vector m_acceleration
the acceleration
Definition:
constant-acceleration-mobility-model.h:62
ns3::ConstantAccelerationMobilityModel::DoGetPosition
Vector DoGetPosition() const override
Definition:
constant-acceleration-mobility-model.cc:54
ns3::ConstantAccelerationMobilityModel::m_baseTime
Time m_baseTime
the base time
Definition:
constant-acceleration-mobility-model.h:59
ns3::ConstantAccelerationMobilityModel::DoGetVelocity
Vector DoGetVelocity() const override
Definition:
constant-acceleration-mobility-model.cc:45
ns3::ConstantAccelerationMobilityModel::m_baseVelocity
Vector m_baseVelocity
the base velocity
Definition:
constant-acceleration-mobility-model.h:61
ns3::MobilityModel
Keep track of the current position and velocity of an object.
Definition:
mobility-model.h:40
ns3::MobilityModel::NotifyCourseChange
void NotifyCourseChange() const
Must be invoked by subclasses when the course of the position changes to notify course change listene...
Definition:
mobility-model.cc:112
ns3::Simulator::Now
static Time Now()
Return the current simulation virtual time.
Definition:
simulator.cc:208
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:59
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition:
type-id.cc:931
constant-acceleration-mobility-model.h
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition:
object-base.h:46
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
mobility
model
constant-acceleration-mobility-model.cc
Generated on Sun Mar 3 2024 17:11:05 for ns-3 by
1.9.1