View | Details | Raw Unified | Return to bug 482
Collapse All | Expand All

(-)9bddd87225a9 (+79 lines)
Added Link Here 
1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 *
16
 * Author: Gustavo Carneiro  <gjc@inescporto.pt>
17
 */
18
#include "constant-acceleration-mobility-model.h"
19
#include "ns3/simulator.h"
20
21
namespace ns3 {
22
23
NS_OBJECT_ENSURE_REGISTERED (ConstantAccelerationMobilityModel);
24
25
TypeId ConstantAccelerationMobilityModel::GetTypeId (void)
26
{
27
  static TypeId tid = TypeId ("ns3::ConstantAccelerationMobilityModel")
28
    .SetParent<MobilityModel> ()
29
    .AddConstructor<ConstantAccelerationMobilityModel> ();
30
  return tid;
31
}
32
33
ConstantAccelerationMobilityModel::ConstantAccelerationMobilityModel ()
34
{}
35
36
ConstantAccelerationMobilityModel::~ConstantAccelerationMobilityModel ()
37
{}
38
39
inline Vector
40
ConstantAccelerationMobilityModel::DoGetVelocity (void) const
41
{
42
  double t = (Simulator::Now () - m_baseTime).GetSeconds ();
43
  return Vector (m_baseVelocity.x + m_acceleration.x*t,
44
                 m_baseVelocity.y + m_acceleration.y*t,
45
                 m_baseVelocity.z + m_acceleration.z*t);
46
}
47
48
inline Vector
49
ConstantAccelerationMobilityModel::DoGetPosition (void) const
50
{
51
  double t = (Simulator::Now () - m_baseTime).GetSeconds ();
52
  double half_t_square = t*t*0.5;
53
  return Vector (m_basePosition.x + m_baseVelocity.x*t + m_acceleration.x*half_t_square,
54
                 m_basePosition.y + m_baseVelocity.y*t + m_acceleration.y*half_t_square,
55
                 m_basePosition.z + m_baseVelocity.z*t + m_acceleration.z*half_t_square);
56
}
57
58
void 
59
ConstantAccelerationMobilityModel::DoSetPosition (const Vector &position)
60
{
61
  m_baseVelocity = DoGetVelocity ();
62
  m_baseTime = Simulator::Now ();
63
  m_basePosition = position;
64
  NotifyCourseChange ();
65
}
66
67
void 
68
ConstantAccelerationMobilityModel::SetVelocityAndAcceleration (const Vector &velocity,
69
                                                               const Vector &acceleration)
70
{
71
  m_basePosition = DoGetPosition ();
72
  m_baseTime = Simulator::Now ();
73
  m_baseVelocity = velocity;
74
  m_acceleration = acceleration;
75
  NotifyCourseChange ();
76
}
77
78
79
}; // namespace ns3
(-)9bddd87225a9 (+56 lines)
Added Link Here 
1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 *
16
 * Author: Gustavo Carneiro  <gjc@inescporto.pt>
17
 */
18
#ifndef CONSTANT_ACCELERATION_MOBILITY_MODEL_H
19
#define CONSTANT_ACCELERATION_MOBILITY_MODEL_H
20
21
#include "mobility-model.h"
22
#include "ns3/nstime.h"
23
24
namespace ns3 {
25
26
/**
27
 * \brief a position model for which the current acceleration does not
28
 *        change once it has been set and until it is set again 
29
 *        explicitely to a new value.
30
 */
31
class ConstantAccelerationMobilityModel : public MobilityModel 
32
{
33
public:
34
  static TypeId GetTypeId (void);
35
  /**
36
   * Create position located at coordinates (0,0,0) with
37
   * speed (0,0,0).
38
   */
39
  ConstantAccelerationMobilityModel ();
40
  virtual ~ConstantAccelerationMobilityModel ();
41
  void SetVelocityAndAcceleration (const Vector &velocity, const Vector &acceleration);
42
43
private:
44
  virtual Vector DoGetPosition (void) const;
45
  virtual void DoSetPosition (const Vector &position);
46
  virtual Vector DoGetVelocity (void) const;
47
48
  Time m_baseTime;
49
  Vector m_basePosition;
50
  Vector m_baseVelocity;
51
  Vector m_acceleration;
52
};
53
54
}; // namespace ns3
55
56
#endif /* CONSTANT_ACCELERATION_MOBILITY_MODEL_H */
(-)a/src/mobility/wscript (+2 lines)
 Lines 14-19    Link Here 
14
        'random-waypoint-mobility-model.cc',
14
        'random-waypoint-mobility-model.cc',
15
        'random-walk-2d-mobility-model.cc',
15
        'random-walk-2d-mobility-model.cc',
16
        'random-direction-2d-mobility-model.cc',
16
        'random-direction-2d-mobility-model.cc',
17
        'constant-acceleration-mobility-model.cc',
17
        ]
18
        ]
18
19
19
    headers = bld.new_task_gen('ns3header')
20
    headers = bld.new_task_gen('ns3header')
 Lines 30-33    Link Here 
30
        'random-waypoint-mobility-model.h',
31
        'random-waypoint-mobility-model.h',
31
        'random-walk-2d-mobility-model.h',
32
        'random-walk-2d-mobility-model.h',
32
        'random-direction-2d-mobility-model.h',
33
        'random-direction-2d-mobility-model.h',
34
        'constant-acceleration-mobility-model.h',
33
        ]
35
        ]

Return to bug 482