A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
mobility-model.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006,2007 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19
20#include "mobility-model.h"
21
22#include "ns3/trace-source-accessor.h"
23
24#include <cmath>
25
26namespace ns3
27{
28
29NS_OBJECT_ENSURE_REGISTERED(MobilityModel);
30
31TypeId
33{
34 static TypeId tid =
35 TypeId("ns3::MobilityModel")
37 .SetGroupName("Mobility")
38 .AddAttribute(
39 "Position",
40 "The current position of the mobility model.",
42 VectorValue(Vector(0.0, 0.0, 0.0)),
45 .AddAttribute("Velocity",
46 "The current velocity of the mobility model.",
48 VectorValue(Vector(0.0, 0.0, 0.0)), // ignored initial value.
51 .AddTraceSource("CourseChange",
52 "The value of the position and/or velocity vector changed",
54 "ns3::MobilityModel::TracedCallback");
55 return tid;
56}
57
59{
60}
61
63{
64}
65
66Vector
68{
69 return DoGetPosition();
70}
71
72Vector
73MobilityModel::GetPositionWithReference(const Vector& referencePosition) const
74{
75 return DoGetPositionWithReference(referencePosition);
76}
77
78// Default implementation ignores referencePosition
79Vector
80MobilityModel::DoGetPositionWithReference(const Vector& referencePosition) const
81{
82 return DoGetPosition();
83}
84
85Vector
87{
88 return DoGetVelocity();
89}
90
91void
92MobilityModel::SetPosition(const Vector& position)
93{
94 DoSetPosition(position);
95}
96
97double
99{
100 Vector oPosition = other->DoGetPosition();
101 Vector position = DoGetPosition();
102 return CalculateDistance(position, oPosition);
103}
104
105double
107{
108 return (GetVelocity() - other->GetVelocity()).GetLength();
109}
110
111void
113{
115}
116
117int64_t
119{
120 return DoAssignStreams(start);
121}
122
123// Default implementation does nothing
124int64_t
126{
127 return 0;
128}
129
130} // namespace ns3
ns3::TracedCallback< Ptr< const MobilityModel > > m_courseChangeTrace
Used to alert subscribers that a change in direction, velocity, or position has occurred.
Vector GetPositionWithReference(const Vector &referencePosition) const
This method may be used if the position returned may depend on some reference position provided.
static TypeId GetTypeId()
Register this type with the TypeId system.
double GetDistanceFrom(Ptr< const MobilityModel > position) const
~MobilityModel() override=0
double GetRelativeSpeed(Ptr< const MobilityModel > other) const
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
virtual Vector DoGetPosition() const =0
virtual Vector DoGetPositionWithReference(const Vector &referencePosition) const
Vector GetVelocity() const
virtual void DoSetPosition(const Vector &position)=0
virtual int64_t DoAssignStreams(int64_t start)
The default implementation does nothing but return the passed-in parameter.
Vector GetPosition() const
void SetPosition(const Vector &position)
void NotifyCourseChange() const
Must be invoked by subclasses when the course of the position changes to notify course change listene...
virtual Vector DoGetVelocity() const =0
A base class which provides memory management and object aggregation.
Definition: object.h:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
a unique identifier for an interface.
Definition: type-id.h:59
@ ATTR_GET
The attribute can be read.
Definition: type-id.h:64
@ ATTR_SET
The attribute can be written.
Definition: type-id.h:65
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
Ptr< const AttributeAccessor > MakeVectorAccessor(T1 a1)
Definition: vector.h:341
Ptr< const AttributeChecker > MakeVectorChecker()
Definition: vector.cc:44
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double CalculateDistance(const Vector3D &a, const Vector3D &b)
Definition: vector.cc:109