20 #include "ns3/simulator.h"
24 #include "ns3/string.h"
25 #include "ns3/pointer.h"
26 #include "random-direction-2d-mobility-model.h"
32 const double RandomDirection2dMobilityModel::PI = 3.14159265358979323846;
34 NS_OBJECT_ENSURE_REGISTERED (RandomDirection2dMobilityModel);
38 RandomDirection2dMobilityModel::GetTypeId (
void)
40 static TypeId tid = TypeId (
"ns3::RandomDirection2dMobilityModel")
41 .SetParent<MobilityModel> ()
42 .SetGroupName (
"Mobility")
43 .AddConstructor<RandomDirection2dMobilityModel> ()
44 .AddAttribute (
"Bounds",
"The 2d bounding area",
45 RectangleValue (Rectangle (-100, 100, -100, 100)),
46 MakeRectangleAccessor (&RandomDirection2dMobilityModel::m_bounds),
47 MakeRectangleChecker ())
48 .AddAttribute (
"Speed",
"A random variable to control the speed (m/s).",
49 StringValue (
"ns3::UniformRandomVariable[Min=1.0|Max=2.0]"),
50 MakePointerAccessor (&RandomDirection2dMobilityModel::m_speed),
51 MakePointerChecker<RandomVariableStream> ())
52 .AddAttribute (
"Pause",
"A random variable to control the pause (s).",
53 StringValue (
"ns3::ConstantRandomVariable[Constant=2.0]"),
54 MakePointerAccessor (&RandomDirection2dMobilityModel::m_pause),
55 MakePointerChecker<RandomVariableStream> ())
60 RandomDirection2dMobilityModel::RandomDirection2dMobilityModel ()
62 m_direction = CreateObject <UniformRandomVariable> ();
74 DoInitializePrivate ();
79 RandomDirection2dMobilityModel::DoInitializePrivate (
void)
81 double direction = m_direction->
GetValue (0, 2 * PI);
82 SetDirectionAndSpeed (direction);
86 RandomDirection2dMobilityModel::BeginPause (
void)
92 m_event =
Simulator::Schedule (pause, &RandomDirection2dMobilityModel::ResetDirectionAndSpeed,
this);
97 RandomDirection2dMobilityModel::SetDirectionAndSpeed (
double direction)
100 m_helper.UpdateWithBounds (m_bounds);
101 Vector position = m_helper.GetCurrentPosition ();
102 double speed = m_speed->
GetValue ();
103 const Vector vector (std::cos (direction) * speed,
104 std::sin (direction) * speed,
106 m_helper.SetVelocity (vector);
112 &RandomDirection2dMobilityModel::BeginPause,
this);
116 RandomDirection2dMobilityModel::ResetDirectionAndSpeed (
void)
118 double direction = m_direction->
GetValue (0, PI);
120 m_helper.UpdateWithBounds (m_bounds);
121 Vector position = m_helper.GetCurrentPosition ();
124 case Rectangle::RIGHT:
127 case Rectangle::LEFT:
128 direction += -PI / 2;
133 case Rectangle::BOTTOM:
137 SetDirectionAndSpeed (direction);
142 m_helper.UpdateWithBounds (m_bounds);
143 return m_helper.GetCurrentPosition ();
148 m_helper.SetPosition (position);
156 return m_helper.GetVelocity ();
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
Vector CalculateIntersection(const Vector ¤t, const Vector &speed) const
virtual Vector DoGetVelocity(void) const
#define NS_LOG_COMPONENT_DEFINE(name)
virtual void DoInitialize(void)
virtual void DoDispose(void)
#define NS_LOG_FUNCTION_NOARGS()
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
virtual double GetValue(void)=0
Returns a random double from the underlying distribution.
double CalculateDistance(const Vector3D &a, const Vector3D &b)
void NotifyCourseChange(void) const
virtual void DoSetPosition(const Vector &position)
virtual void DoDispose(void)
virtual int64_t DoAssignStreams(int64_t)
static void Remove(const EventId &id)
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Side GetClosestSide(const Vector &position) const
virtual Vector DoGetPosition(void) const
virtual void DoInitialize(void)