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
virtual void DoInitialize(void)
Initialize() implementation.
Simulation virtual time values and global simulation resolution.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Hold variables of type string.
Vector GetCurrentPosition(void) const
Get current position vector.
Ptr< RandomVariableStream > m_speed
a random variable to control speed
void ResetDirectionAndSpeed(void)
Set a new direction and speed.
#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.
void DoInitializePrivate(void)
Sets a new random direction and calls SetDirectionAndSpeed.
virtual double GetValue(void)=0
Get the next random value as a double drawn from the 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...
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
void Update(void) const
Update position, if not paused, from last position and time of last update.
Vector CalculateIntersection(const Vector ¤t, const Vector &speed) const
double CalculateDistance(const Vector3D &a, const Vector3D &b)
virtual Vector DoGetPosition(void) const
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.
virtual Vector DoGetVelocity(void) const
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 UpdateWithBounds(const Rectangle &rectangle) const
Update position, if not paused, from last position and time of last update.
Side GetClosestSide(const Vector &position) const
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.
void NotifyCourseChange(void) const
Must be invoked by subclasses when the course of the position changes to notify course change listene...
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
Vector GetVelocity(void) const
Get velocity; if paused, will return a zero vector.
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.
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)
Set the parent TypeId.