11#include "ns3/pointer.h"
12#include "ns3/simulator.h"
13#include "ns3/string.h"
29 TypeId(
"ns3::RandomDirection2dMobilityModel")
31 .SetGroupName(
"Mobility")
33 .AddAttribute(
"Bounds",
34 "The 2d bounding area",
38 .AddAttribute(
"Speed",
39 "A random variable to control the speed (m/s).",
40 StringValue(
"ns3::UniformRandomVariable[Min=1.0|Max=2.0]"),
43 .AddAttribute(
"Pause",
44 "A random variable to control the pause (s).",
45 StringValue(
"ns3::ConstantRandomVariable[Constant=2.0]"),
78 double direction =
m_direction->GetValue(0, 2 * M_PI);
99 Vector position =
m_helper.GetCurrentPosition();
100 double speed =
m_speed->GetValue();
101 const Vector
vector(std::cos(direction) * speed, std::sin(direction) * speed, 0.0);
114 double direction = 0;
117 Vector position =
m_helper.GetCurrentPosition();
118 switch (
m_bounds.GetClosestSideOrCorner(position))
121 direction =
m_direction->GetValue(M_PI_2, M_PI + M_PI_2);
124 direction =
m_direction->GetValue(-M_PI_2, M_PI - M_PI_2);
133 direction =
m_direction->GetValue(M_PI, M_PI + M_PI_2);
136 direction =
m_direction->GetValue(M_PI + M_PI_2, 2 * M_PI);
140 direction += M_PI / 2;
153 return m_helper.GetCurrentPosition();
174 m_speed->SetStream(stream + 1);
175 m_pause->SetStream(stream + 2);
void NotifyCourseChange() const
Must be invoked by subclasses when the course of the position changes to notify course change listene...
virtual void DoInitialize()
Initialize() implementation.
virtual void DoDispose()
Destructor implementation.
Random direction mobility model.
Vector DoGetPosition() const override
~RandomDirection2dMobilityModel() override
void DoSetPosition(const Vector &position) override
void SetDirectionAndSpeed(double direction)
Set new velocity and direction, and schedule next pause event.
EventId m_event
event ID of next scheduled event
int64_t DoAssignStreams(int64_t) override
The default implementation does nothing but return the passed-in parameter.
ConstantVelocityHelper m_helper
helper for velocity computations
void BeginPause()
Pause, cancel currently scheduled event, schedule end of pause event.
void DoInitializePrivate()
Sets a new random direction and calls SetDirectionAndSpeed.
void DoInitialize() override
Initialize() implementation.
static TypeId GetTypeId()
Register this type with the TypeId system.
void DoDispose() override
Destructor implementation.
Vector DoGetVelocity() const override
Ptr< RandomVariableStream > m_speed
a random variable to control speed
void ResetDirectionAndSpeed()
Set a new direction and speed.
Rectangle m_bounds
the 2D bounding area
RandomDirection2dMobilityModel()
Ptr< UniformRandomVariable > m_direction
rv to control direction
Ptr< RandomVariableStream > m_pause
a random variable to control pause
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Hold variables of type string.
Simulation virtual time values and global simulation resolution.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< AttributeChecker > MakePointerChecker()
Create a PointerChecker for a type.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeRectangleChecker()
Ptr< const AttributeAccessor > MakeRectangleAccessor(T1 a1)
double CalculateDistance(const Vector3D &a, const Vector3D &b)