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