author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Sat, 04 Jul 2009 08:15:48 +0200 | |
changeset 4654 | 2eaebe77d66b |
parent 4226 | a08201e94eb2 |
permissions | -rw-r--r-- |
1575
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
2 |
/* |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
3 |
* Copyright (c) 2007 INRIA |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
4 |
* |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License version 2 as |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation; |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
8 |
* |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
13 |
* |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
17 |
* |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
18 |
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
19 |
*/ |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
20 |
#include "ns3/simulator.h" |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
21 |
#include <algorithm> |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
22 |
#include <cmath> |
1625
0579a50b2c62
random-direction -> random-direction-2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1624
diff
changeset
|
23 |
#include "random-direction-2d-mobility-model.h" |
1656
99949986bb92
Add a bit of function name logging.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1637
diff
changeset
|
24 |
#include "ns3/log.h" |
99949986bb92
Add a bit of function name logging.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1637
diff
changeset
|
25 |
|
99949986bb92
Add a bit of function name logging.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1637
diff
changeset
|
26 |
NS_LOG_COMPONENT_DEFINE ("RandomDirection2dMobilityModel"); |
1575
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
27 |
|
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
28 |
namespace ns3 { |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
29 |
|
1658
52f6bf2a7caa
Improve the precision of the RandomDirection2dMobilityModel::PI constant (value copied from glibc's math.h header file).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1656
diff
changeset
|
30 |
const double RandomDirection2dMobilityModel::PI = 3.14159265358979323846; |
2249
3a1da26d61dc
replace ComponentManager::Create and ClassId with InterfaceId::CreateObjest and InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2232
diff
changeset
|
31 |
|
3a1da26d61dc
replace ComponentManager::Create and ClassId with InterfaceId::CreateObjest and InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2232
diff
changeset
|
32 |
NS_OBJECT_ENSURE_REGISTERED (RandomDirection2dMobilityModel); |
1575
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
33 |
|
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
34 |
|
2250
18f432098389
InterfaceId -> TypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2249
diff
changeset
|
35 |
TypeId |
2251
04963d8cca51
iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2250
diff
changeset
|
36 |
RandomDirection2dMobilityModel::GetTypeId (void) |
2249
3a1da26d61dc
replace ComponentManager::Create and ClassId with InterfaceId::CreateObjest and InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2232
diff
changeset
|
37 |
{ |
2602
d9262bff6df2
add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2553
diff
changeset
|
38 |
static TypeId tid = TypeId ("ns3::RandomDirection2dMobilityModel") |
2249
3a1da26d61dc
replace ComponentManager::Create and ClassId with InterfaceId::CreateObjest and InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2232
diff
changeset
|
39 |
.SetParent<MobilityModel> () |
2399
fd9d94d518d2
convert Mobility subsystem to Value framework
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2336
diff
changeset
|
40 |
.SetGroupName ("Mobility") |
2249
3a1da26d61dc
replace ComponentManager::Create and ClassId with InterfaceId::CreateObjest and InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2232
diff
changeset
|
41 |
.AddConstructor<RandomDirection2dMobilityModel> () |
2543
401bfe8c0176
kill old code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2458
diff
changeset
|
42 |
.AddAttribute ("Bounds", "The 2d bounding area", |
2965
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2834
diff
changeset
|
43 |
RectangleValue (Rectangle (-100, 100, -100, 100)), |
2435
3128175f5866
ParamSpec -> Accessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2427
diff
changeset
|
44 |
MakeRectangleAccessor (&RandomDirection2dMobilityModel::m_bounds), |
2427
9245ec163111
split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2424
diff
changeset
|
45 |
MakeRectangleChecker ()) |
2543
401bfe8c0176
kill old code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2458
diff
changeset
|
46 |
.AddAttribute ("Speed", "A random variable to control the speed (m/s).", |
2965
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2834
diff
changeset
|
47 |
RandomVariableValue (UniformVariable (1.0, 2.0)), |
2435
3128175f5866
ParamSpec -> Accessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2427
diff
changeset
|
48 |
MakeRandomVariableAccessor (&RandomDirection2dMobilityModel::m_speed), |
2427
9245ec163111
split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2424
diff
changeset
|
49 |
MakeRandomVariableChecker ()) |
2543
401bfe8c0176
kill old code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2458
diff
changeset
|
50 |
.AddAttribute ("Pause", "A random variable to control the pause (s).", |
2965
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2834
diff
changeset
|
51 |
RandomVariableValue (ConstantVariable (2.0)), |
2435
3128175f5866
ParamSpec -> Accessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2427
diff
changeset
|
52 |
MakeRandomVariableAccessor (&RandomDirection2dMobilityModel::m_pause), |
2427
9245ec163111
split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2424
diff
changeset
|
53 |
MakeRandomVariableChecker ()) |
9245ec163111
split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2424
diff
changeset
|
54 |
; |
2252
80595448707a
iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2251
diff
changeset
|
55 |
return tid; |
2249
3a1da26d61dc
replace ComponentManager::Create and ClassId with InterfaceId::CreateObjest and InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2232
diff
changeset
|
56 |
} |
3a1da26d61dc
replace ComponentManager::Create and ClassId with InterfaceId::CreateObjest and InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2232
diff
changeset
|
57 |
|
1575
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
58 |
|
1626
feaecfd93b5d
RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1625
diff
changeset
|
59 |
RandomDirection2dMobilityModel::RandomDirection2dMobilityModel () |
1575
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
60 |
{ |
1626
feaecfd93b5d
RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1625
diff
changeset
|
61 |
m_event = Simulator::ScheduleNow (&RandomDirection2dMobilityModel::Start, this); |
1575
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
62 |
} |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
63 |
void |
1626
feaecfd93b5d
RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1625
diff
changeset
|
64 |
RandomDirection2dMobilityModel::DoDispose (void) |
1575
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
65 |
{ |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
66 |
// chain up. |
1579
a4187ed1e45e
Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1575
diff
changeset
|
67 |
MobilityModel::DoDispose (); |
1575
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
68 |
} |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
69 |
void |
1626
feaecfd93b5d
RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1625
diff
changeset
|
70 |
RandomDirection2dMobilityModel::Start (void) |
1575
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
71 |
{ |
4226
a08201e94eb2
Mathieu's patch: update users of GetSingleValue
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
4218
diff
changeset
|
72 |
double direction = m_direction.GetValue (0, 2 * PI); |
1575
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
73 |
SetDirectionAndSpeed (direction); |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
74 |
} |
1661
7583786bd063
Adapt to StaticSpeedHelper change
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1658
diff
changeset
|
75 |
|
7583786bd063
Adapt to StaticSpeedHelper change
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1658
diff
changeset
|
76 |
void |
7583786bd063
Adapt to StaticSpeedHelper change
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1658
diff
changeset
|
77 |
RandomDirection2dMobilityModel::BeginPause (void) |
7583786bd063
Adapt to StaticSpeedHelper change
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1658
diff
changeset
|
78 |
{ |
3782
a2375aed06f3
rework StaticSpeedHelper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2989
diff
changeset
|
79 |
m_helper.Update (); |
a2375aed06f3
rework StaticSpeedHelper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2989
diff
changeset
|
80 |
m_helper.Pause (); |
2399
fd9d94d518d2
convert Mobility subsystem to Value framework
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2336
diff
changeset
|
81 |
Time pause = Seconds (m_pause.GetValue ()); |
1661
7583786bd063
Adapt to StaticSpeedHelper change
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1658
diff
changeset
|
82 |
m_event = Simulator::Schedule (pause, &RandomDirection2dMobilityModel::ResetDirectionAndSpeed, this); |
7583786bd063
Adapt to StaticSpeedHelper change
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1658
diff
changeset
|
83 |
NotifyCourseChange (); |
7583786bd063
Adapt to StaticSpeedHelper change
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1658
diff
changeset
|
84 |
} |
7583786bd063
Adapt to StaticSpeedHelper change
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1658
diff
changeset
|
85 |
|
1575
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
86 |
void |
1626
feaecfd93b5d
RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1625
diff
changeset
|
87 |
RandomDirection2dMobilityModel::SetDirectionAndSpeed (double direction) |
1575
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
88 |
{ |
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2834
diff
changeset
|
89 |
NS_LOG_FUNCTION_NOARGS (); |
3782
a2375aed06f3
rework StaticSpeedHelper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2989
diff
changeset
|
90 |
m_helper.UpdateWithBounds (m_bounds); |
a2375aed06f3
rework StaticSpeedHelper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2989
diff
changeset
|
91 |
Vector position = m_helper.GetCurrentPosition (); |
2399
fd9d94d518d2
convert Mobility subsystem to Value framework
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2336
diff
changeset
|
92 |
double speed = m_speed.GetValue (); |
1817
8b0520433350
replace Position and Speed by Vector
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1816
diff
changeset
|
93 |
const Vector vector (std::cos (direction) * speed, |
8b0520433350
replace Position and Speed by Vector
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1816
diff
changeset
|
94 |
std::sin (direction) * speed, |
8b0520433350
replace Position and Speed by Vector
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1816
diff
changeset
|
95 |
0.0); |
3782
a2375aed06f3
rework StaticSpeedHelper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2989
diff
changeset
|
96 |
m_helper.SetVelocity (vector); |
a2375aed06f3
rework StaticSpeedHelper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2989
diff
changeset
|
97 |
m_helper.Unpause (); |
2399
fd9d94d518d2
convert Mobility subsystem to Value framework
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2336
diff
changeset
|
98 |
Vector next = m_bounds.CalculateIntersection (position, vector); |
1620
69baa7b1c487
remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1591
diff
changeset
|
99 |
Time delay = Seconds (CalculateDistance (position, next) / speed); |
1661
7583786bd063
Adapt to StaticSpeedHelper change
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1658
diff
changeset
|
100 |
m_event = Simulator::Schedule (delay, |
7583786bd063
Adapt to StaticSpeedHelper change
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1658
diff
changeset
|
101 |
&RandomDirection2dMobilityModel::BeginPause, this); |
1620
69baa7b1c487
remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1591
diff
changeset
|
102 |
NotifyCourseChange (); |
1575
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
103 |
} |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
104 |
void |
1626
feaecfd93b5d
RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1625
diff
changeset
|
105 |
RandomDirection2dMobilityModel::ResetDirectionAndSpeed (void) |
1575
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
106 |
{ |
4226
a08201e94eb2
Mathieu's patch: update users of GetSingleValue
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
4218
diff
changeset
|
107 |
double direction = m_direction.GetValue (0, PI); |
1591
4a1f822fe9aa
split useful code out of random direction mobility model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1584
diff
changeset
|
108 |
|
3782
a2375aed06f3
rework StaticSpeedHelper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2989
diff
changeset
|
109 |
m_helper.UpdateWithBounds (m_bounds); |
a2375aed06f3
rework StaticSpeedHelper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2989
diff
changeset
|
110 |
Vector position = m_helper.GetCurrentPosition (); |
2399
fd9d94d518d2
convert Mobility subsystem to Value framework
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2336
diff
changeset
|
111 |
switch (m_bounds.GetClosestSide (position)) |
1575
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
112 |
{ |
1620
69baa7b1c487
remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1591
diff
changeset
|
113 |
case Rectangle::RIGHT: |
1575
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
114 |
direction += PI / 2; |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
115 |
break; |
1620
69baa7b1c487
remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1591
diff
changeset
|
116 |
case Rectangle::LEFT: |
1575
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
117 |
direction += - PI / 2; |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
118 |
break; |
1620
69baa7b1c487
remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1591
diff
changeset
|
119 |
case Rectangle::TOP: |
1575
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
120 |
direction += PI; |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
121 |
break; |
1620
69baa7b1c487
remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1591
diff
changeset
|
122 |
case Rectangle::BOTTOM: |
1575
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
123 |
direction += 0.0; |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
124 |
break; |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
125 |
} |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
126 |
SetDirectionAndSpeed (direction); |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
127 |
} |
1817
8b0520433350
replace Position and Speed by Vector
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1816
diff
changeset
|
128 |
Vector |
1816
d7c9b9da78f4
rename MobilityModel::Get/Set to GetPosition/SetPosition
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1661
diff
changeset
|
129 |
RandomDirection2dMobilityModel::DoGetPosition (void) const |
1575
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
130 |
{ |
3782
a2375aed06f3
rework StaticSpeedHelper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2989
diff
changeset
|
131 |
m_helper.UpdateWithBounds (m_bounds); |
a2375aed06f3
rework StaticSpeedHelper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2989
diff
changeset
|
132 |
return m_helper.GetCurrentPosition (); |
1575
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
133 |
} |
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
134 |
void |
1817
8b0520433350
replace Position and Speed by Vector
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1816
diff
changeset
|
135 |
RandomDirection2dMobilityModel::DoSetPosition (const Vector &position) |
1575
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
136 |
{ |
3782
a2375aed06f3
rework StaticSpeedHelper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2989
diff
changeset
|
137 |
m_helper.SetPosition (position); |
1575
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
138 |
Simulator::Remove (m_event); |
1626
feaecfd93b5d
RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1625
diff
changeset
|
139 |
m_event = Simulator::ScheduleNow (&RandomDirection2dMobilityModel::Start, this); |
1575
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
140 |
} |
1817
8b0520433350
replace Position and Speed by Vector
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1816
diff
changeset
|
141 |
Vector |
1818
fbdc8361dc77
GetSpeed -> GetVelocity
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1817
diff
changeset
|
142 |
RandomDirection2dMobilityModel::DoGetVelocity (void) const |
1624
6e7d48a8c120
add MobilityModel::GetSpeed method and implement it in all mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1620
diff
changeset
|
143 |
{ |
1818
fbdc8361dc77
GetSpeed -> GetVelocity
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1817
diff
changeset
|
144 |
return m_helper.GetVelocity (); |
1624
6e7d48a8c120
add MobilityModel::GetSpeed method and implement it in all mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1620
diff
changeset
|
145 |
} |
1575
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
146 |
|
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
147 |
|
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
148 |
|
cbc37ce4b91d
RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
149 |
} // namespace ns3 |