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-acceleration-mobility-model.cc
Go to the documentation of this file.
1
/*
2
* SPDX-License-Identifier: GPL-2.0-only
3
*
4
* Author: Gustavo Carneiro <gjc@inescporto.pt>
5
*/
6
#include "
constant-acceleration-mobility-model.h
"
7
8
#include "ns3/simulator.h"
9
10
namespace
ns3
11
{
12
13
NS_OBJECT_ENSURE_REGISTERED
(ConstantAccelerationMobilityModel);
14
15
TypeId
16
ConstantAccelerationMobilityModel::GetTypeId
()
17
{
18
static
TypeId
tid =
TypeId
(
"ns3::ConstantAccelerationMobilityModel"
)
19
.
SetParent
<
MobilityModel
>()
20
.SetGroupName(
"Mobility"
)
21
.AddConstructor<
ConstantAccelerationMobilityModel
>();
22
return
tid;
23
}
24
25
ConstantAccelerationMobilityModel::ConstantAccelerationMobilityModel
()
26
{
27
}
28
29
ConstantAccelerationMobilityModel::~ConstantAccelerationMobilityModel
()
30
{
31
}
32
33
inline
Vector
34
ConstantAccelerationMobilityModel::DoGetVelocity
()
const
35
{
36
double
t = (
Simulator::Now
() -
m_baseTime
).GetSeconds();
37
return
Vector(
m_baseVelocity
.x +
m_acceleration
.x * t,
38
m_baseVelocity
.y +
m_acceleration
.y * t,
39
m_baseVelocity
.z +
m_acceleration
.z * t);
40
}
41
42
inline
Vector
43
ConstantAccelerationMobilityModel::DoGetPosition
()
const
44
{
45
double
t = (
Simulator::Now
() -
m_baseTime
).GetSeconds();
46
double
half_t_square = t * t * 0.5;
47
return
Vector(
m_basePosition
.x +
m_baseVelocity
.x * t +
m_acceleration
.x * half_t_square,
48
m_basePosition
.y +
m_baseVelocity
.y * t +
m_acceleration
.y * half_t_square,
49
m_basePosition
.z +
m_baseVelocity
.z * t +
m_acceleration
.z * half_t_square);
50
}
51
52
void
53
ConstantAccelerationMobilityModel::DoSetPosition
(
const
Vector& position)
54
{
55
m_baseVelocity
=
DoGetVelocity
();
56
m_baseTime
=
Simulator::Now
();
57
m_basePosition
= position;
58
NotifyCourseChange
();
59
}
60
61
void
62
ConstantAccelerationMobilityModel::SetVelocityAndAcceleration
(
const
Vector& velocity,
63
const
Vector& acceleration)
64
{
65
m_basePosition
=
DoGetPosition
();
66
m_baseTime
=
Simulator::Now
();
67
m_baseVelocity
= velocity;
68
m_acceleration
= acceleration;
69
NotifyCourseChange
();
70
}
71
72
}
// 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:23
ns3::ConstantAccelerationMobilityModel::SetVelocityAndAcceleration
void SetVelocityAndAcceleration(const Vector &velocity, const Vector &acceleration)
Set the model's velocity and acceleration.
Definition
constant-acceleration-mobility-model.cc:62
ns3::ConstantAccelerationMobilityModel::GetTypeId
static TypeId GetTypeId()
Register this type with the TypeId system.
Definition
constant-acceleration-mobility-model.cc:16
ns3::ConstantAccelerationMobilityModel::m_basePosition
Vector m_basePosition
the base position
Definition
constant-acceleration-mobility-model.h:49
ns3::ConstantAccelerationMobilityModel::DoSetPosition
void DoSetPosition(const Vector &position) override
Definition
constant-acceleration-mobility-model.cc:53
ns3::ConstantAccelerationMobilityModel::~ConstantAccelerationMobilityModel
~ConstantAccelerationMobilityModel() override
Definition
constant-acceleration-mobility-model.cc:29
ns3::ConstantAccelerationMobilityModel::ConstantAccelerationMobilityModel
ConstantAccelerationMobilityModel()
Create position located at coordinates (0,0,0) with speed (0,0,0).
Definition
constant-acceleration-mobility-model.cc:25
ns3::ConstantAccelerationMobilityModel::m_acceleration
Vector m_acceleration
the acceleration
Definition
constant-acceleration-mobility-model.h:51
ns3::ConstantAccelerationMobilityModel::DoGetPosition
Vector DoGetPosition() const override
Definition
constant-acceleration-mobility-model.cc:43
ns3::ConstantAccelerationMobilityModel::m_baseTime
Time m_baseTime
the base time
Definition
constant-acceleration-mobility-model.h:48
ns3::ConstantAccelerationMobilityModel::DoGetVelocity
Vector DoGetVelocity() const override
Definition
constant-acceleration-mobility-model.cc:34
ns3::ConstantAccelerationMobilityModel::m_baseVelocity
Vector m_baseVelocity
the base velocity
Definition
constant-acceleration-mobility-model.h:50
ns3::MobilityModel
Keep track of the current position and velocity of an object.
Definition
mobility-model.h:29
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:101
ns3::Simulator::Now
static Time Now()
Return the current simulation virtual time.
Definition
simulator.cc:197
ns3::TypeId
a unique identifier for an interface.
Definition
type-id.h:48
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition
type-id.cc:1001
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:35
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
mobility
model
constant-acceleration-mobility-model.cc
Generated on Fri Nov 8 2024 13:59:04 for ns-3 by
1.11.0