A Discrete-Event Network Simulator
API
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 
26 namespace ns3
27 {
28 
29 NS_OBJECT_ENSURE_REGISTERED(MobilityModel);
30 
31 TypeId
33 {
34  static TypeId tid =
35  TypeId("ns3::MobilityModel")
36  .SetParent<Object>()
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 
66 Vector
68 {
69  return DoGetPosition();
70 }
71 
72 Vector
73 MobilityModel::GetPositionWithReference(const Vector& referencePosition) const
74 {
75  return DoGetPositionWithReference(referencePosition);
76 }
77 
78 // Default implementation ignores referencePosition
79 Vector
80 MobilityModel::DoGetPositionWithReference(const Vector& referencePosition) const
81 {
82  return DoGetPosition();
83 }
84 
85 Vector
87 {
88  return DoGetVelocity();
89 }
90 
91 void
92 MobilityModel::SetPosition(const Vector& position)
93 {
94  DoSetPosition(position);
95 }
96 
97 double
99 {
100  Vector oPosition = other->DoGetPosition();
101  Vector position = DoGetPosition();
102  return CalculateDistance(position, oPosition);
103 }
104 
105 double
107 {
108  return (GetVelocity() - other->GetVelocity()).GetLength();
109 }
110 
111 void
113 {
114  m_courseChangeTrace(this);
115 }
116 
117 int64_t
119 {
120  return DoAssignStreams(start);
121 }
122 
123 // Default implementation does nothing
124 int64_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:931
#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.
Ptr< const AttributeChecker > MakeVectorChecker()
Definition: vector.cc:44
Ptr< const AttributeAccessor > MakeVectorAccessor(T1 a1)
Definition: vector.h:353
double CalculateDistance(const Vector3D &a, const Vector3D &b)
Definition: vector.cc:109