20 #include "ns3/simulator.h"
24 #include "ns3/string.h"
25 #include "ns3/pointer.h"
38 static TypeId tid =
TypeId (
"ns3::RandomDirection2dMobilityModel")
40 .SetGroupName (
"Mobility")
42 .AddAttribute (
"Bounds",
"The 2d bounding area",
46 .AddAttribute (
"Speed",
"A random variable to control the speed (m/s).",
47 StringValue (
"ns3::UniformRandomVariable[Min=1.0|Max=2.0]"),
49 MakePointerChecker<RandomVariableStream> ())
50 .AddAttribute (
"Pause",
"A random variable to control the pause (s).",
51 StringValue (
"ns3::ConstantRandomVariable[Constant=2.0]"),
53 MakePointerChecker<RandomVariableStream> ())
60 m_direction = CreateObject <UniformRandomVariable> ();
101 const Vector vector (std::cos (direction) * speed,
102 std::sin (direction) * speed,
123 direction += M_PI / 2;
126 direction += -M_PI / 2;
void Unpause(void)
Resume mobility from current position at current velocity.
Vector GetVelocity(void) const
Get velocity; if paused, will return a zero vector.
void UpdateWithBounds(const Rectangle &rectangle) const
Update position, if not paused, from last position and time of last update.
void SetPosition(const Vector &position)
Set position vector.
void Pause(void)
Pause mobility at current position.
void SetVelocity(const Vector &vel)
Set new velocity vector.
void Update(void) const
Update position, if not paused, from last position and time of last update.
Vector GetCurrentPosition(void) const
Get current position vector.
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Keep track of the current position and velocity of an object.
void NotifyCourseChange(void) const
Must be invoked by subclasses when the course of the position changes to notify course change listene...
virtual void DoDispose(void)
Destructor implementation.
virtual void DoInitialize(void)
Initialize() implementation.
Random direction mobility model.
static TypeId GetTypeId(void)
Register this type with the TypeId system.
virtual int64_t DoAssignStreams(int64_t)
The default implementation does nothing but return the passed-in parameter.
void SetDirectionAndSpeed(double direction)
Set new velocity and direction, and schedule next pause event
EventId m_event
event ID of next scheduled event
virtual void DoDispose(void)
Destructor implementation.
virtual Vector DoGetVelocity(void) const
ConstantVelocityHelper m_helper
helper for velocity computations
void DoInitializePrivate(void)
Sets a new random direction and calls SetDirectionAndSpeed.
void BeginPause(void)
Pause, cancel currently scheduled event, schedule end of pause event.
Ptr< RandomVariableStream > m_speed
a random variable to control speed
virtual Vector DoGetPosition(void) const
Rectangle m_bounds
the 2D bounding area
void ResetDirectionAndSpeed(void)
Set a new direction and speed.
virtual void DoInitialize(void)
Initialize() implementation.
RandomDirection2dMobilityModel()
Ptr< UniformRandomVariable > m_direction
rv to control direction
virtual void DoSetPosition(const Vector &position)
Ptr< RandomVariableStream > m_pause
a random variable to control pause
virtual double GetValue(void)=0
Get the next random value as a double drawn from the distribution.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
Side GetClosestSide(const Vector &position) const
Vector CalculateIntersection(const Vector ¤t, const Vector &speed) const
AttributeValue implementation for Rectangle.
static EventId Schedule(Time const &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< const AttributeAccessor > MakeRectangleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeChecker > MakeRectangleChecker(void)
#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.
double CalculateDistance(const Vector3D &a, const Vector3D &b)