Waypoint-based mobility model. More...
#include "waypoint-mobility-model.h"
Public Member Functions | |
WaypointMobilityModel () | |
Create a path with no waypoints at location (0,0,0). | |
~WaypointMobilityModel () override | |
void | AddWaypoint (const Waypoint &waypoint) |
void | EndMobility () |
Clear any existing waypoints and set the current waypoint time to infinity. | |
Waypoint | GetNextWaypoint () const |
Get the waypoint that this object is traveling towards. | |
uint32_t | WaypointsLeft () const |
Get the number of waypoints left for this object, excluding the next one. | |
Public Member Functions inherited from ns3::MobilityModel | |
MobilityModel () | |
~MobilityModel () override=0 | |
int64_t | AssignStreams (int64_t stream) |
Assign a fixed random variable stream number to the random variables used by this model. | |
double | GetDistanceFrom (Ptr< const MobilityModel > position) const |
Vector | GetPosition () const |
Vector | GetPositionWithReference (const Vector &referencePosition) const |
This method may be used if the position returned may depend on some reference position provided. | |
double | GetRelativeSpeed (Ptr< const MobilityModel > other) const |
Vector | GetVelocity () const |
void | SetPosition (const Vector &position) |
Public Member Functions inherited from ns3::Object | |
Object () | |
Constructor. | |
~Object () override | |
Destructor. | |
void | AggregateObject (Ptr< Object > other) |
Aggregate two Objects together. | |
void | Dispose () |
Dispose of this Object. | |
AggregateIterator | GetAggregateIterator () const |
Get an iterator to the Objects aggregated to this one. | |
TypeId | GetInstanceTypeId () const override |
Get the most derived TypeId for this Object. | |
template<typename T > | |
Ptr< T > | GetObject () const |
Get a pointer to the requested aggregated Object. | |
template<> | |
Ptr< Object > | GetObject () const |
Specialization of () for objects of type ns3::Object. | |
template<typename T > | |
Ptr< T > | GetObject (TypeId tid) const |
Get a pointer to the requested aggregated Object by TypeId. | |
template<> | |
Ptr< Object > | GetObject (TypeId tid) const |
Specialization of (TypeId tid) for objects of type ns3::Object. | |
void | Initialize () |
Invoke DoInitialize on all Objects aggregated to this one. | |
bool | IsInitialized () const |
Check if the object has been initialized. | |
void | UnidirectionalAggregateObject (Ptr< Object > other) |
Aggregate an Object to another Object. | |
Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter > | |
SimpleRefCount () | |
Default constructor. | |
SimpleRefCount (const SimpleRefCount &o) | |
Copy constructor. | |
uint32_t | GetReferenceCount () const |
Get the reference count of the object. | |
SimpleRefCount & | operator= (const SimpleRefCount &o) |
Assignment operator. | |
void | Ref () const |
Increment the reference count. | |
void | Unref () const |
Decrement the reference count. | |
Public Member Functions inherited from ns3::ObjectBase | |
virtual | ~ObjectBase () |
Virtual destructor. | |
void | GetAttribute (std::string name, AttributeValue &value, bool permissive=false) const |
Get the value of an attribute, raising fatal errors if unsuccessful. | |
bool | GetAttributeFailSafe (std::string name, AttributeValue &value) const |
Get the value of an attribute without raising errors. | |
void | SetAttribute (std::string name, const AttributeValue &value) |
Set a single attribute, raising fatal errors if unsuccessful. | |
bool | SetAttributeFailSafe (std::string name, const AttributeValue &value) |
Set a single attribute without raising errors. | |
bool | TraceConnect (std::string name, std::string context, const CallbackBase &cb) |
Connect a TraceSource to a Callback with a context. | |
bool | TraceConnectWithoutContext (std::string name, const CallbackBase &cb) |
Connect a TraceSource to a Callback without a context. | |
bool | TraceDisconnect (std::string name, std::string context, const CallbackBase &cb) |
Disconnect from a TraceSource a Callback previously connected with a context. | |
bool | TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb) |
Disconnect from a TraceSource a Callback previously connected without a context. | |
Static Public Member Functions | |
static TypeId | GetTypeId () |
Register this type with the TypeId system. | |
Static Public Member Functions inherited from ns3::MobilityModel | |
static TypeId | GetTypeId () |
Register this type with the TypeId system. | |
Static Public Member Functions inherited from ns3::Object | |
static TypeId | GetTypeId () |
Register this type. | |
Static Public Member Functions inherited from ns3::ObjectBase | |
static TypeId | GetTypeId () |
Get the type ID. | |
Protected Attributes | |
Waypoint | m_current |
The ns3::Waypoint currently being used. | |
EventId | m_event |
Update event. | |
bool | m_first |
This variable is set to true if there are no waypoints in the std::deque. | |
bool | m_initialPositionIsWaypoint |
If true, calling SetPosition with no waypoints creates a waypoint. | |
bool | m_lazyNotify |
If true, course change updates are only notified when position is calculated. | |
Waypoint | m_next |
The next ns3::Waypoint in the deque. | |
Vector | m_velocity |
The current velocity vector. | |
std::deque< Waypoint > | m_waypoints |
The double ended queue containing the ns3::Waypoint objects. | |
Private Member Functions | |
void | DoDispose () override |
The dispose method. | |
Vector | DoGetPosition () const override |
Get current position. | |
Vector | DoGetVelocity () const override |
Returns the current velocity of a node. | |
void | DoSetPosition (const Vector &position) override |
Sets a new position for the node. | |
virtual void | Update () const |
Update the underlying state corresponding to the stored waypoints. | |
Friends | |
class | ::WaypointMobilityModelNotifyTest |
Additional Inherited Members | |
Public Types inherited from ns3::MobilityModel | |
typedef void(* | TracedCallback) (Ptr< const MobilityModel > model) |
TracedCallback signature. | |
Protected Member Functions inherited from ns3::MobilityModel | |
void | NotifyCourseChange () const |
Must be invoked by subclasses when the course of the position changes to notify course change listeners. | |
Protected Member Functions inherited from ns3::Object | |
Object (const Object &o) | |
Copy an Object. | |
virtual void | DoInitialize () |
Initialize() implementation. | |
virtual void | NotifyNewAggregate () |
Notify all Objects aggregated to this one of a new Object being aggregated. | |
Protected Member Functions inherited from ns3::ObjectBase | |
void | ConstructSelf (const AttributeConstructionList &attributes) |
Complete construction of ObjectBase; invoked by derived classes. | |
virtual void | NotifyConstructionCompleted () |
Notifier called once the ObjectBase is fully constructed. | |
Related Symbols inherited from ns3::ObjectBase | |
static TypeId | GetObjectIid () |
Ensure the TypeId for ObjectBase gets fully configured to anchor the inheritance tree properly. | |
Waypoint-based mobility model.
Each object determines its velocity and position at a given time from a set of ns3::Waypoint objects. Past waypoints are discarded after the current simulation time greater than their time value.
By default, the initial position of each object corresponds to the position of the first waypoint, and the initial velocity of each object is zero. Upon reaching the last waypoint, object position becomes static and velocity is zero.
When a node is in between waypoint times, it moves with a constant velocity between the position at the previous waypoint and the position at the current waypoint. To make a node hold a certain position for a time interval, two waypoints with the same position (but different times) should be inserted sequentially.
Waypoints can be added at any time, and setting the current position of an object will set its velocity to zero until the next waypoint time (at which time the object jumps to the next waypoint), unless there are no more waypoints in which case it will not change without user intervention.
The model has two attributes with methods that allow clients to get the next waypoint value (NextWaypoint) and the number of waypoints left (WaypointsLeft) beyond (but not including) the next waypoint.
In addition, there are two attributes that govern model behavior. The first, LazyNotify, governs how the model calls the CourseChange trace. By default, LazyNotify is false, which means that each time that a waypoint time is hit, an Update() is forced and the CourseChange callback will be called. When LazyNotify is true, Update() is suppressed at waypoint times, and CourseChange callbacks will only occur when there later are actual calls to Update () (typically when calling GetPosition ()). This option may be enabled for execution run-time performance improvements, but when enabled, users should note that course change listeners will in general not be notified at waypoint times but instead at the next Update() following a waypoint time, and some waypoints may not be notified to course change listeners.
The second, InitialPositionIsWaypoint, is false by default. Recall that the first waypoint will set the initial position and set velocity equal to 0 until the first waypoint time. In such a case, the call to SetPosition(), such as from a PositionAllocator, will be ignored. However, if InitialPositionIsWaypoint is set to true and SetPosition() is called before any waypoints have been added, the SetPosition() call is treated as an initial waypoint at time zero. In such a case, when SetPosition() is treated as an initial waypoint, it should be noted that attempts to add a waypoint at the same time will cause the program to fail.
Definition at line 77 of file waypoint-mobility-model.h.
ns3::WaypointMobilityModel::WaypointMobilityModel | ( | ) |
Create a path with no waypoints at location (0,0,0).
Definition at line 60 of file waypoint-mobility-model.cc.
|
override |
Definition at line 67 of file waypoint-mobility-model.cc.
References ns3::EventId::Cancel(), and m_event.
void ns3::WaypointMobilityModel::AddWaypoint | ( | const Waypoint & | waypoint | ) |
waypoint | waypoint to append to the object path. |
Add a waypoint to the path of the object. The time must be greater than the previous waypoint added, otherwise a fatal error occurs. The first waypoint is set as the current position with a velocity of zero.
Definition at line 79 of file waypoint-mobility-model.cc.
References m_current, m_event, m_first, m_lazyNotify, m_next, m_waypoints, ns3::Simulator::Now(), NS_ABORT_MSG_IF, ns3::Simulator::Schedule(), ns3::Waypoint::time, and Update().
Referenced by DoSetPosition().
|
overrideprivatevirtual |
The dispose method.
Subclasses must override this method.
Reimplemented from ns3::Object.
Definition at line 73 of file waypoint-mobility-model.cc.
References ns3::Object::DoDispose().
|
overrideprivatevirtual |
Get current position.
Implements ns3::MobilityModel.
Definition at line 179 of file waypoint-mobility-model.cc.
References m_current, ns3::Waypoint::position, and Update().
|
overrideprivatevirtual |
Returns the current velocity of a node.
Implements ns3::MobilityModel.
Definition at line 218 of file waypoint-mobility-model.cc.
References m_velocity.
|
overrideprivatevirtual |
Sets a new position for the node.
position | A vector to be added as the new position |
Implements ns3::MobilityModel.
Definition at line 186 of file waypoint-mobility-model.cc.
References AddWaypoint(), m_current, m_first, m_initialPositionIsWaypoint, m_next, m_velocity, ns3::MobilityModel::NotifyCourseChange(), ns3::Simulator::Now(), ns3::Waypoint::position, ns3::Waypoint::time, and Update().
void ns3::WaypointMobilityModel::EndMobility | ( | ) |
Clear any existing waypoints and set the current waypoint time to infinity.
Calling this is only an optimization and not required. After calling this function, adding waypoints behaves as it would for a new object.
Definition at line 209 of file waypoint-mobility-model.cc.
References m_current, m_first, m_next, m_waypoints, and ns3::Waypoint::time.
Waypoint ns3::WaypointMobilityModel::GetNextWaypoint | ( | ) | const |
Get the waypoint that this object is traveling towards.
Definition at line 102 of file waypoint-mobility-model.cc.
References m_next, and Update().
Referenced by GetTypeId().
|
static |
Register this type with the TypeId system.
Definition at line 28 of file waypoint-mobility-model.cc.
References ns3::TypeId::ATTR_GET, GetNextWaypoint(), m_initialPositionIsWaypoint, m_lazyNotify, ns3::MakeBooleanAccessor(), ns3::MakeBooleanChecker(), ns3::MakeUintegerAccessor(), ns3::MakeUintegerChecker(), ns3::MakeWaypointAccessor(), ns3::MakeWaypointChecker(), ns3::TypeId::SetParent(), and WaypointsLeft().
|
privatevirtual |
Update the underlying state corresponding to the stored waypoints.
Definition at line 116 of file waypoint-mobility-model.cc.
References m_current, m_next, m_velocity, m_waypoints, ns3::MobilityModel::NotifyCourseChange(), ns3::Simulator::Now(), NS_ASSERT, ns3::Waypoint::position, ns3::Seconds(), and ns3::Waypoint::time.
Referenced by AddWaypoint(), DoGetPosition(), DoSetPosition(), GetNextWaypoint(), and WaypointsLeft().
uint32_t ns3::WaypointMobilityModel::WaypointsLeft | ( | ) | const |
Get the number of waypoints left for this object, excluding the next one.
Definition at line 109 of file waypoint-mobility-model.cc.
References m_waypoints, and Update().
Referenced by GetTypeId().
|
friend |
Definition at line 125 of file waypoint-mobility-model.h.
|
mutableprotected |
The ns3::Waypoint currently being used.
Definition at line 175 of file waypoint-mobility-model.h.
Referenced by AddWaypoint(), DoGetPosition(), DoSetPosition(), EndMobility(), and Update().
|
protected |
Update event.
Definition at line 187 of file waypoint-mobility-model.h.
Referenced by ~WaypointMobilityModel(), and AddWaypoint().
|
protected |
This variable is set to true if there are no waypoints in the std::deque.
Definition at line 158 of file waypoint-mobility-model.h.
Referenced by AddWaypoint(), DoSetPosition(), and EndMobility().
|
protected |
If true, calling SetPosition with no waypoints creates a waypoint.
Definition at line 167 of file waypoint-mobility-model.h.
Referenced by DoSetPosition(), and GetTypeId().
|
protected |
If true, course change updates are only notified when position is calculated.
Definition at line 163 of file waypoint-mobility-model.h.
Referenced by AddWaypoint(), and GetTypeId().
|
mutableprotected |
The next ns3::Waypoint in the deque.
Definition at line 179 of file waypoint-mobility-model.h.
Referenced by AddWaypoint(), DoSetPosition(), EndMobility(), GetNextWaypoint(), and Update().
|
mutableprotected |
The current velocity vector.
Definition at line 183 of file waypoint-mobility-model.h.
Referenced by DoGetVelocity(), DoSetPosition(), and Update().
|
mutableprotected |
The double ended queue containing the ns3::Waypoint objects.
Definition at line 171 of file waypoint-mobility-model.h.
Referenced by AddWaypoint(), EndMobility(), Update(), and WaypointsLeft().