21 #include "ns3/double.h"
24 #include "ns3/pointer.h"
25 #include "ns3/simulator.h"
26 #include "ns3/string.h"
41 TypeId(
"ns3::RandomWalk2dMobilityModel")
43 .SetGroupName(
"Mobility")
45 .AddAttribute(
"Bounds",
46 "Bounds of the area to cruise.",
47 RectangleValue(
Rectangle(0.0, 100.0, 0.0, 100.0)),
49 MakeRectangleChecker())
51 "Change current direction and speed after moving for this delay.",
55 .AddAttribute(
"Distance",
56 "Change current direction and speed after moving for this distance.",
59 MakeDoubleChecker<double>())
61 "The mode indicates the condition used to "
62 "change the current speed and direction",
64 MakeEnumAccessor<RandomWalk2dMobilityModel::Mode>(
70 .AddAttribute(
"Direction",
71 "A random variable used to pick the direction (radians).",
72 StringValue(
"ns3::UniformRandomVariable[Min=0.0|Max=6.283184]"),
74 MakePointerChecker<RandomVariableStream>())
75 .AddAttribute(
"Speed",
76 "A random variable used to pick the speed (m/s).",
77 StringValue(
"ns3::UniformRandomVariable[Min=2.0|Max=4.0]"),
79 MakePointerChecker<RandomVariableStream>());
108 direction = directionOverride->
GetValue(M_PI_2, M_PI + M_PI_2);
111 direction = directionOverride->
GetValue(-M_PI_2, M_PI - M_PI_2);
114 direction = directionOverride->
GetValue(M_PI, 2 * M_PI);
117 direction = directionOverride->
GetValue(0, M_PI);
120 direction = directionOverride->
GetValue(M_PI, M_PI + M_PI_2);
123 direction = directionOverride->
GetValue(M_PI + M_PI_2, 2 * M_PI);
126 direction = directionOverride->
GetValue(0, M_PI_2);
127 direction += M_PI / 2;
130 direction = directionOverride->
GetValue(M_PI_2, M_PI);
134 Vector vector(std::cos(direction) * speed, std::sin(direction) * speed, 0.0);
155 Vector nextPosition = position;
156 nextPosition.x += speed.x * delayLeft.
GetSeconds();
157 nextPosition.y += speed.y * delayLeft.
GetSeconds();
171 std::min(delaySeconds, std::abs((nextPosition.x - position.x) / speed.x));
173 else if (speed.y != 0)
176 std::min(delaySeconds, std::abs((nextPosition.y - position.y) / speed.y));
180 NS_ABORT_MSG(
"RandomWalk2dMobilityModel::DoWalk: unable to calculate the rebound time "
181 "(the node is stationary).");
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.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Hold variables of type enum.
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.
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.
2D random walk mobility model.
Ptr< RandomVariableStream > m_speed
rv for picking speed
static TypeId GetTypeId()
Register this type with the TypeId system.
void DoInitialize() override
Initialize() implementation.
double m_modeDistance
Change direction and speed after this distance.
void DoInitializePrivate()
Perform initialization of the object before MobilityModel::DoInitialize ()
void DoWalk(Time timeLeft)
Walk according to position and velocity, until distance is reached, time is reached,...
void Rebound(Time timeLeft)
Performs the rebound of the node if it reaches a boundary.
Vector DoGetPosition() const override
ConstantVelocityHelper m_helper
helper for this object
Vector DoGetVelocity() const override
Time m_modeTime
Change current direction and speed after this delay.
Rectangle m_bounds
Bounds of the area to cruise.
void DoSetPosition(const Vector &position) override
void DoDispose() override
Destructor implementation.
Ptr< RandomVariableStream > m_direction
rv for picking direction
int64_t DoAssignStreams(int64_t) override
The default implementation does nothing but return the passed-in parameter.
Mode m_mode
whether in time or distance mode
EventId m_event
stored event ID
Side GetClosestSideOrCorner(const Vector &position) const
bool IsInside(const Vector &position) const
bool IsOnTheBorder(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.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#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 > MakeTimeAccessor(T1 a1)
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Ptr< const AttributeChecker > MakeEnumChecker(T v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)