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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8
9#include "mobility-model.h"
10
11#include "ns3/trace-source-accessor.h"
12
13#include <cmath>
14
15namespace ns3
16{
17
18NS_OBJECT_ENSURE_REGISTERED(MobilityModel);
19
20TypeId
22{
23 static TypeId tid =
24 TypeId("ns3::MobilityModel")
26 .SetGroupName("Mobility")
27 .AddAttribute(
28 "Position",
29 "The current position of the mobility model.",
31 VectorValue(Vector(0.0, 0.0, 0.0)),
34 .AddAttribute("Velocity",
35 "The current velocity of the mobility model.",
37 VectorValue(Vector(0.0, 0.0, 0.0)), // ignored initial value.
40 .AddTraceSource("CourseChange",
41 "The value of the position and/or velocity vector changed",
43 "ns3::MobilityModel::TracedCallback");
44 return tid;
45}
46
50
54
55Vector
57{
58 return DoGetPosition();
59}
60
61Vector
62MobilityModel::GetPositionWithReference(const Vector& referencePosition) const
63{
64 return DoGetPositionWithReference(referencePosition);
65}
66
67// Default implementation ignores referencePosition
68Vector
69MobilityModel::DoGetPositionWithReference(const Vector& referencePosition) const
70{
71 return DoGetPosition();
72}
73
74Vector
76{
77 return DoGetVelocity();
78}
79
80void
81MobilityModel::SetPosition(const Vector& position)
82{
83 DoSetPosition(position);
84}
85
86double
88{
89 Vector oPosition = other->DoGetPosition();
90 Vector position = DoGetPosition();
91 return CalculateDistance(position, oPosition);
92}
93
94double
96{
97 return (GetVelocity() - other->GetVelocity()).GetLength();
98}
99
100void
105
106int64_t
108{
109 return DoAssignStreams(start);
110}
111
112// Default implementation does nothing
113int64_t
115{
116 return 0;
117}
118
119} // 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:78
Smart pointer class similar to boost::intrusive_ptr.
a unique identifier for an interface.
Definition type-id.h:48
@ ATTR_GET
The attribute can be read.
Definition type-id.h:53
@ ATTR_SET
The attribute can be written.
Definition type-id.h:54
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
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:33
double CalculateDistance(const Vector3D &a, const Vector3D &b)
Definition vector.cc:98
Ptr< const AttributeAccessor > MakeVectorAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition vector.h:378