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;
Ptr< UniformRandomVariable > m_direction
rv to control direction
Simulation virtual time values and global simulation resolution.
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
Vector CalculateIntersection(const Vector ¤t, const Vector &speed) const
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Hold variables of type string.
virtual Vector DoGetVelocity(void) const
Ptr< RandomVariableStream > m_speed
a random variable to control speed
void ResetDirectionAndSpeed(void)
Set a new direction and speed.
Vector GetCurrentPosition(void) const
Get current position vector.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
ConstantVelocityHelper m_helper
helper for velocity computations
virtual void DoInitialize(void)
Initialize() implementation.
virtual void DoDispose(void)
Destructor implementation.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
void DoInitializePrivate(void)
Sets a new random direction and calls SetDirectionAndSpeed.
virtual double GetValue(void)=0
Returns a random double from the underlying distribution.
AttributeValue implementation for Rectangle.
Keep track of the current position and velocity of an object.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
double CalculateDistance(const Vector3D &a, const Vector3D &b)
void NotifyCourseChange(void) const
Must be invoked by subclasses when the course of the position changes to notify course change listene...
void Update(void) const
Update position, if not paused, from last position and time of last update.
virtual void DoSetPosition(const Vector &position)
virtual void DoDispose(void)
Destructor implementation.
virtual int64_t DoAssignStreams(int64_t)
The default implementation does nothing but return the passed-in parameter.
static void Remove(const EventId &id)
Remove an event from the event list.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetVelocity(const Vector &vel)
Set new velocity vector.
RandomDirection2dMobilityModel()
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
Schedule an event to expire Now.
EventId m_event
event ID of next scheduled event
static TypeId GetTypeId(void)
Register this type with the TypeId system.
Vector GetVelocity(void) const
Get velocity; if paused, will return a zero vector.
Side GetClosestSide(const Vector &position) const
void UpdateWithBounds(const Rectangle &rectangle) const
Update position, if not paused, from last position and time of last update.
Time Seconds(double value)
Construct a Time in the indicated unit.
void SetDirectionAndSpeed(double direction)
Set new velocity and direction, and schedule next pause event.
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Rectangle m_bounds
the 2D bounding area
void Unpause(void)
Resume mobility from current position at current velocity.
Ptr< RandomVariableStream > m_pause
a random variable to control pause
Ptr< const AttributeChecker > MakeRectangleChecker(void)
void BeginPause(void)
Pause, cancel currently scheduled event, schedule end of pause event.
void SetPosition(const Vector &position)
Set position vector.
Random direction mobility model.
virtual Vector DoGetPosition(void) const
Ptr< const AttributeAccessor > MakeRectangleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
a unique identifier for an interface.
void Pause(void)
Pause mobility at current position.
TypeId SetParent(TypeId tid)
virtual void DoInitialize(void)
Initialize() implementation.