21 #include "ns3/abort.h"
22 #include "ns3/simulator.h"
23 #include "ns3/uinteger.h"
25 #include "ns3/boolean.h"
26 #include "waypoint-mobility-model.h"
27 #include "ns3/config.h"
34 NS_OBJECT_ENSURE_REGISTERED (WaypointMobilityModel);
38 WaypointMobilityModel::GetTypeId (
void)
40 static TypeId tid = TypeId (
"ns3::WaypointMobilityModel")
41 .SetParent<MobilityModel> ()
42 .SetGroupName (
"Mobility")
44 .AddAttribute (
"NextWaypoint",
"The next waypoint used to determine position.",
48 MakeWaypointChecker ())
49 .AddAttribute (
"WaypointsLeft",
"The number of waypoints remaining.",
53 MakeUintegerChecker<uint32_t> ())
54 .AddAttribute (
"LazyNotify",
"Only call NotifyCourseChange when position is calculated.",
56 MakeBooleanAccessor (&WaypointMobilityModel::m_lazyNotify),
57 MakeBooleanChecker ())
58 .AddAttribute (
"InitialPositionIsWaypoint",
"Calling SetPosition with no waypoints creates a waypoint.",
60 MakeBooleanAccessor (&WaypointMobilityModel::m_initialPositionIsWaypoint),
61 MakeBooleanChecker ())
70 m_initialPositionIsWaypoint (false)
73 WaypointMobilityModel::~WaypointMobilityModel ()
87 m_current = m_next = waypoint;
91 NS_ABORT_MSG_IF ( !m_waypoints.empty () && (m_waypoints.back ().time >= waypoint.time),
92 "Waypoints must be added in ascending time order");
93 m_waypoints.push_back (waypoint);
111 return m_waypoints.size ();
114 WaypointMobilityModel::Update (
void)
const
117 bool newWaypoint =
false;
119 if ( now < m_current.time )
124 while ( now >= m_next.time )
126 if ( m_waypoints.empty () )
128 if ( m_current.time <= m_next.time )
135 m_current.position = m_next.position;
136 m_current.time = now;
137 m_velocity = Vector (0,0,0);
142 m_current.time = now;
149 m_next = m_waypoints.front ();
150 m_waypoints.pop_front ();
153 const double t_span = (m_next.time - m_current.time).GetSeconds ();
155 m_velocity.
x = (m_next.position.
x - m_current.position.
x) / t_span;
156 m_velocity.
y = (m_next.position.
y - m_current.position.
y) / t_span;
157 m_velocity.
z = (m_next.position.
z - m_current.position.
z) / t_span;
160 if ( now > m_current.time )
162 const double t_diff = (now - m_current.time).GetSeconds ();
163 m_current.position.
x += m_velocity.
x * t_diff;
164 m_current.position.
y += m_velocity.
y * t_diff;
165 m_current.position.
z += m_velocity.
z * t_diff;
166 m_current.time = now;
178 return m_current.position;
185 if ( m_first && m_initialPositionIsWaypoint )
192 m_current.time = std::max (now, m_next.time);
193 m_current.position = position;
194 m_velocity =
Vector (0,0,0);
196 if ( !m_first && (now >= m_current.time) )
205 m_waypoints.clear ();
206 m_current.time =
Time(std::numeric_limits<uint64_t>::infinity());
207 m_next.time = m_current.time;
virtual void DoDispose(void)
virtual Vector DoGetVelocity(void) const
void AddWaypoint(const Waypoint &waypoint)
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
virtual Vector DoGetPosition(void) const
virtual void DoDispose(void)
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
virtual void DoSetPosition(const Vector &position)
void NotifyCourseChange(void) const
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if cond is true.
Waypoint GetNextWaypoint(void) const
uint32_t WaypointsLeft(void) const