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);
101 const Vector vector(std::cos(direction) * speed, std::sin(direction) * speed, 0.0);
114 double direction = 0;
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;
Vector GetCurrentPosition() const
Get current position vector.
Vector GetVelocity() const
Get velocity; if paused, will return a zero vector.
void Update() const
Update position, if not paused, from last position and time of last update.
void UpdateWithBounds(const Rectangle &rectangle) const
Update position, if not paused, from last position and time of last update.
void Unpause()
Resume mobility from current position at current velocity.
void SetPosition(const Vector &position)
Set position vector.
void SetVelocity(const Vector &vel)
Set new velocity vector.
void Pause()
Pause mobility at current position.
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Keep track of the current position and velocity of an object.
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
virtual double GetValue()=0
Get the next random value drawn from the distribution.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
Side GetClosestSideOrCorner(const Vector &position) const
Vector CalculateIntersection(const Vector ¤t, const Vector &speed) const
AttributeValue implementation for Rectangle.
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.
Ptr< const AttributeChecker > MakeRectangleChecker()
Ptr< const AttributeAccessor > MakeRectangleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
#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.
double CalculateDistance(const Vector3D &a, const Vector3D &b)