|
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
|
2 /* |
|
3 * Copyright (c) 2009 Phillip Sitbon |
|
4 * |
|
5 * This program is free software; you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License version 2 as |
|
7 * published by the Free Software Foundation; |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU General Public License |
|
15 * along with this program; if not, write to the Free Software |
|
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 * |
|
18 * Author: Phillip Sitbon <phillip@sitbon.net> |
|
19 */ |
|
20 #ifndef WAYPOINT_MOBILITY_MODEL_H |
|
21 #define WAYPOINT_MOBILITY_MODEL_H |
|
22 |
|
23 #include <stdint.h> |
|
24 #include <deque> |
|
25 #include "mobility-model.h" |
|
26 #include "ns3/vector.h" |
|
27 #include "waypoint.h" |
|
28 |
|
29 namespace ns3 { |
|
30 |
|
31 /** |
|
32 * \brief a waypoint-based mobility model |
|
33 * |
|
34 * Each object determines its velocity and position at a given time |
|
35 * from a set of ns3::Waypoint objects. The position of each object |
|
36 * is not updated unless queried, and past waypoints are discarded |
|
37 * after the current simulation time greater than their time value. |
|
38 * |
|
39 * The initial position of each object corresponds to the position of |
|
40 * the first waypoint, and the initial velocity of each object is zero. |
|
41 * Upon reaching the last waypoint, object positions becomes static and |
|
42 * velocity is zero. |
|
43 * |
|
44 * When a node is in between waypoints (in time), it moves with a constant |
|
45 * velocity between the position at the previous waypoint and the position |
|
46 * at the current waypoint. To make a node hold a certain position for a |
|
47 * time interval, two waypoints with the same position (but different times) |
|
48 * should be inserted sequentially. |
|
49 * |
|
50 * Waypoints can be added at any time, and setting the current position |
|
51 * of an object will set its velocity to zero until the next waypoint time |
|
52 * (at which time the object jumps to the next waypoint), unless there are |
|
53 * no more waypoints in which case it will not change without user |
|
54 * intervention. |
|
55 * |
|
56 */ |
|
57 class WaypointMobilityModel : public MobilityModel |
|
58 { |
|
59 public: |
|
60 static TypeId GetTypeId (void); |
|
61 |
|
62 /** |
|
63 * Create a path with no waypoints at location (0,0,0). |
|
64 */ |
|
65 WaypointMobilityModel (); |
|
66 virtual ~WaypointMobilityModel (); |
|
67 |
|
68 /** |
|
69 * \param waypoint waypoint to append to the object path. |
|
70 * |
|
71 * Add a waypoint to the path of the object. The time must |
|
72 * be greater than the previous waypoint added, otherwise |
|
73 * a fatal error occurs. The first waypoint is set as the |
|
74 * current position with a velocity of zero. |
|
75 * |
|
76 */ |
|
77 void AddWaypoint (const Waypoint &waypoint); |
|
78 |
|
79 /** |
|
80 * Get the waypoint that this object is traveling towards. |
|
81 */ |
|
82 Waypoint GetNextWaypoint (void) const; |
|
83 |
|
84 /** |
|
85 * Get the number of waypoints left for this object, excluding |
|
86 * the next one. |
|
87 */ |
|
88 uint32_t WaypointsLeft (void) const; |
|
89 |
|
90 /** |
|
91 * Clear any existing waypoints and set the current waypoint |
|
92 * time to infinity. Calling this is only an optimization and |
|
93 * not required. After calling this function, adding waypoints |
|
94 * behaves as it would for a new object. |
|
95 */ |
|
96 void EndMobility (void); |
|
97 |
|
98 private: |
|
99 void Update (void) const; |
|
100 virtual void DoDispose (void); |
|
101 virtual Vector DoGetPosition (void) const; |
|
102 virtual void DoSetPosition (const Vector &position); |
|
103 virtual Vector DoGetVelocity (void) const; |
|
104 |
|
105 bool m_first; |
|
106 mutable std::deque<Waypoint> m_waypoints; |
|
107 mutable Waypoint m_current; |
|
108 mutable Waypoint m_next; |
|
109 mutable Vector m_velocity; |
|
110 }; |
|
111 |
|
112 } // namespace ns3 |
|
113 |
|
114 #endif /* WAYPOINT_MOBILITY_MODEL_H */ |
|
115 |