src/mobility/constant-velocity-helper.cc
author Dan Broyles <muxman@sbcglobal.net>
Wed, 03 Mar 2010 10:58:27 -0500
changeset 6100 38066d5d262b
parent 4258 8b6b5fbc1976
permissions -rw-r--r--
Merge Gauss Markov Mobility Model
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1460
0c9be520ba9f fix copyright statements
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 968
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
0c9be520ba9f fix copyright statements
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 968
diff changeset
     2
/*
0c9be520ba9f fix copyright statements
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 968
diff changeset
     3
 * Copyright (c) 2006,2007 INRIA
0c9be520ba9f fix copyright statements
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 968
diff changeset
     4
 *
0c9be520ba9f fix copyright statements
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 968
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
0c9be520ba9f fix copyright statements
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 968
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
0c9be520ba9f fix copyright statements
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 968
diff changeset
     7
 * published by the Free Software Foundation;
0c9be520ba9f fix copyright statements
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 968
diff changeset
     8
 *
0c9be520ba9f fix copyright statements
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 968
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
0c9be520ba9f fix copyright statements
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 968
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0c9be520ba9f fix copyright statements
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 968
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0c9be520ba9f fix copyright statements
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 968
diff changeset
    12
 * GNU General Public License for more details.
0c9be520ba9f fix copyright statements
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 968
diff changeset
    13
 *
0c9be520ba9f fix copyright statements
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 968
diff changeset
    14
 * You should have received a copy of the GNU General Public License
0c9be520ba9f fix copyright statements
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 968
diff changeset
    15
 * along with this program; if not, write to the Free Software
0c9be520ba9f fix copyright statements
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 968
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
0c9be520ba9f fix copyright statements
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 968
diff changeset
    17
 *
0c9be520ba9f fix copyright statements
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 968
diff changeset
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
0c9be520ba9f fix copyright statements
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 968
diff changeset
    19
 */
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
#include "ns3/simulator.h"
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
#include "ns3/rectangle.h"
6100
38066d5d262b Merge Gauss Markov Mobility Model
Dan Broyles <muxman@sbcglobal.net>
parents: 4258
diff changeset
    22
#include "ns3/box.h"
4258
8b6b5fbc1976 StaticSpeedHelper -> ConstantVelocityHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3926
diff changeset
    23
#include "constant-velocity-helper.h"
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    24
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    25
namespace ns3 {
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
4258
8b6b5fbc1976 StaticSpeedHelper -> ConstantVelocityHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3926
diff changeset
    27
ConstantVelocityHelper::ConstantVelocityHelper ()
3926
29bb5689faa4 bug 420: avoid valgrind warning
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3782
diff changeset
    28
  : m_paused (true)
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
{}
4258
8b6b5fbc1976 StaticSpeedHelper -> ConstantVelocityHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3926
diff changeset
    30
ConstantVelocityHelper::ConstantVelocityHelper (const Vector &position)
3926
29bb5689faa4 bug 420: avoid valgrind warning
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3782
diff changeset
    31
  : m_position (position),
29bb5689faa4 bug 420: avoid valgrind warning
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3782
diff changeset
    32
    m_paused (true)
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
{}
4258
8b6b5fbc1976 StaticSpeedHelper -> ConstantVelocityHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3926
diff changeset
    34
ConstantVelocityHelper::ConstantVelocityHelper (const Vector &position,
3782
a2375aed06f3 rework StaticSpeedHelper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1818
diff changeset
    35
				      const Vector &vel)
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    36
  : m_position (position),
3782
a2375aed06f3 rework StaticSpeedHelper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1818
diff changeset
    37
    m_velocity (vel),
1659
4df279b828d3 Refactor handling of pauses in StaticSpeedHelper to fix bug (must return null speed when paused)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1642
diff changeset
    38
    m_paused (true)
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    39
{}
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    40
void 
4258
8b6b5fbc1976 StaticSpeedHelper -> ConstantVelocityHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3926
diff changeset
    41
ConstantVelocityHelper::SetPosition (const Vector &position)
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    42
{
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    43
  m_position = position;
3782
a2375aed06f3 rework StaticSpeedHelper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1818
diff changeset
    44
  m_velocity = Vector (0.0, 0.0, 0.0);
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    45
  m_lastUpdate = Simulator::Now ();
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    46
}
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    47
1817
8b0520433350 replace Position and Speed by Vector
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1659
diff changeset
    48
Vector
4258
8b6b5fbc1976 StaticSpeedHelper -> ConstantVelocityHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3926
diff changeset
    49
ConstantVelocityHelper::GetCurrentPosition (void) const
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    50
{
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    51
  return m_position;
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    52
}
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    53
1817
8b0520433350 replace Position and Speed by Vector
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1659
diff changeset
    54
Vector 
4258
8b6b5fbc1976 StaticSpeedHelper -> ConstantVelocityHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3926
diff changeset
    55
ConstantVelocityHelper::GetVelocity (void) const
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    56
{
3782
a2375aed06f3 rework StaticSpeedHelper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1818
diff changeset
    57
  return m_paused? Vector (0.0, 0.0, 0.0) : m_velocity;
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    58
}
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    59
void 
4258
8b6b5fbc1976 StaticSpeedHelper -> ConstantVelocityHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3926
diff changeset
    60
ConstantVelocityHelper::SetVelocity (const Vector &vel)
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    61
{
3782
a2375aed06f3 rework StaticSpeedHelper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1818
diff changeset
    62
  m_velocity = vel;
a2375aed06f3 rework StaticSpeedHelper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1818
diff changeset
    63
  m_lastUpdate = Simulator::Now ();
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    64
}
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    65
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    66
void
4258
8b6b5fbc1976 StaticSpeedHelper -> ConstantVelocityHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3926
diff changeset
    67
ConstantVelocityHelper::Update (void) const
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    68
{
1659
4df279b828d3 Refactor handling of pauses in StaticSpeedHelper to fix bug (must return null speed when paused)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1642
diff changeset
    69
  Time now = Simulator::Now ();
4df279b828d3 Refactor handling of pauses in StaticSpeedHelper to fix bug (must return null speed when paused)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1642
diff changeset
    70
  NS_ASSERT (m_lastUpdate <= now);
4df279b828d3 Refactor handling of pauses in StaticSpeedHelper to fix bug (must return null speed when paused)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1642
diff changeset
    71
  Time deltaTime = now - m_lastUpdate;
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    72
  m_lastUpdate = now;
3782
a2375aed06f3 rework StaticSpeedHelper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1818
diff changeset
    73
  if (m_paused)
a2375aed06f3 rework StaticSpeedHelper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1818
diff changeset
    74
    {
a2375aed06f3 rework StaticSpeedHelper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1818
diff changeset
    75
      return;
a2375aed06f3 rework StaticSpeedHelper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1818
diff changeset
    76
    }
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    77
  double deltaS = deltaTime.GetSeconds ();
3782
a2375aed06f3 rework StaticSpeedHelper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1818
diff changeset
    78
  m_position.x += m_velocity.x * deltaS;
a2375aed06f3 rework StaticSpeedHelper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1818
diff changeset
    79
  m_position.y += m_velocity.y * deltaS;
a2375aed06f3 rework StaticSpeedHelper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1818
diff changeset
    80
  m_position.z += m_velocity.z * deltaS;
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    81
}
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    82
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    83
void
4258
8b6b5fbc1976 StaticSpeedHelper -> ConstantVelocityHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3926
diff changeset
    84
ConstantVelocityHelper::UpdateWithBounds (const Rectangle &bounds) const
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    85
{
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    86
  Update ();
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    87
  m_position.x = std::min (bounds.xMax, m_position.x);
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    88
  m_position.x = std::max (bounds.xMin, m_position.x);
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    89
  m_position.y = std::min (bounds.yMax, m_position.y);
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    90
  m_position.y = std::max (bounds.yMin, m_position.y);
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    91
}
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    92
6100
38066d5d262b Merge Gauss Markov Mobility Model
Dan Broyles <muxman@sbcglobal.net>
parents: 4258
diff changeset
    93
void
38066d5d262b Merge Gauss Markov Mobility Model
Dan Broyles <muxman@sbcglobal.net>
parents: 4258
diff changeset
    94
ConstantVelocityHelper::UpdateWithBounds (const Box &bounds) const
38066d5d262b Merge Gauss Markov Mobility Model
Dan Broyles <muxman@sbcglobal.net>
parents: 4258
diff changeset
    95
{
38066d5d262b Merge Gauss Markov Mobility Model
Dan Broyles <muxman@sbcglobal.net>
parents: 4258
diff changeset
    96
  Update ();
38066d5d262b Merge Gauss Markov Mobility Model
Dan Broyles <muxman@sbcglobal.net>
parents: 4258
diff changeset
    97
  m_position.x = std::min (bounds.xMax, m_position.x);
38066d5d262b Merge Gauss Markov Mobility Model
Dan Broyles <muxman@sbcglobal.net>
parents: 4258
diff changeset
    98
  m_position.x = std::max (bounds.xMin, m_position.x);
38066d5d262b Merge Gauss Markov Mobility Model
Dan Broyles <muxman@sbcglobal.net>
parents: 4258
diff changeset
    99
  m_position.y = std::min (bounds.yMax, m_position.y);
38066d5d262b Merge Gauss Markov Mobility Model
Dan Broyles <muxman@sbcglobal.net>
parents: 4258
diff changeset
   100
  m_position.y = std::max (bounds.yMin, m_position.y);
38066d5d262b Merge Gauss Markov Mobility Model
Dan Broyles <muxman@sbcglobal.net>
parents: 4258
diff changeset
   101
  m_position.z = std::min (bounds.zMax, m_position.z);
38066d5d262b Merge Gauss Markov Mobility Model
Dan Broyles <muxman@sbcglobal.net>
parents: 4258
diff changeset
   102
  m_position.z = std::max (bounds.zMin, m_position.z);
38066d5d262b Merge Gauss Markov Mobility Model
Dan Broyles <muxman@sbcglobal.net>
parents: 4258
diff changeset
   103
}
38066d5d262b Merge Gauss Markov Mobility Model
Dan Broyles <muxman@sbcglobal.net>
parents: 4258
diff changeset
   104
1659
4df279b828d3 Refactor handling of pauses in StaticSpeedHelper to fix bug (must return null speed when paused)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1642
diff changeset
   105
void 
4258
8b6b5fbc1976 StaticSpeedHelper -> ConstantVelocityHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3926
diff changeset
   106
ConstantVelocityHelper::Pause (void)
1659
4df279b828d3 Refactor handling of pauses in StaticSpeedHelper to fix bug (must return null speed when paused)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1642
diff changeset
   107
{
4df279b828d3 Refactor handling of pauses in StaticSpeedHelper to fix bug (must return null speed when paused)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1642
diff changeset
   108
  m_paused = true;
4df279b828d3 Refactor handling of pauses in StaticSpeedHelper to fix bug (must return null speed when paused)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1642
diff changeset
   109
}
4df279b828d3 Refactor handling of pauses in StaticSpeedHelper to fix bug (must return null speed when paused)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1642
diff changeset
   110
4df279b828d3 Refactor handling of pauses in StaticSpeedHelper to fix bug (must return null speed when paused)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1642
diff changeset
   111
void 
4258
8b6b5fbc1976 StaticSpeedHelper -> ConstantVelocityHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3926
diff changeset
   112
ConstantVelocityHelper::Unpause (void)
1659
4df279b828d3 Refactor handling of pauses in StaticSpeedHelper to fix bug (must return null speed when paused)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1642
diff changeset
   113
{
3782
a2375aed06f3 rework StaticSpeedHelper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1818
diff changeset
   114
  m_paused = false;
1659
4df279b828d3 Refactor handling of pauses in StaticSpeedHelper to fix bug (must return null speed when paused)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1642
diff changeset
   115
}
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   116
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   117
} // namespace ns3