22 #include "ns3/pointer.h"
23 #include "ns3/simulator.h"
24 #include "ns3/string.h"
40 TypeId(
"ns3::RandomDirection2dMobilityModel")
42 .SetGroupName(
"Mobility")
44 .AddAttribute(
"Bounds",
45 "The 2d bounding area",
46 RectangleValue(
Rectangle(-100, 100, -100, 100)),
48 MakeRectangleChecker())
49 .AddAttribute(
"Speed",
50 "A random variable to control the speed (m/s).",
51 StringValue(
"ns3::UniformRandomVariable[Min=1.0|Max=2.0]"),
53 MakePointerChecker<RandomVariableStream>())
54 .AddAttribute(
"Pause",
55 "A random variable to control the pause (s).",
56 StringValue(
"ns3::ConstantRandomVariable[Constant=2.0]"),
58 MakePointerChecker<RandomVariableStream>());
64 m_direction = CreateObject<UniformRandomVariable>();
107 const Vector vector(std::cos(direction) * speed, std::sin(direction) * speed, 0.0);
120 double direction = 0;
146 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
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
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.
#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.
#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 AttributeAccessor > MakePointerAccessor(T1 a1)
double CalculateDistance(const Vector3D &a, const Vector3D &b)