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

(-)a/src/auv/doc/auv.h (+27 lines)
Line 0    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
 */
17
18
#ifndef AUV_H
19
#define AUV_H
20
21
/**
22
 * \defgroup auv Autonomous Underwater Vehicle
23
 *
24
 * This section documents the API of the ns-3 AUV module. For a generic functional description, please refer to the ns-3 manual.
25
 */
26
27
#endif /* AUV_H */
(-)a/src/auv/doc/auv.rst (+10 lines)
Line 0    Link Here 
1
An autonomous underwater vehicle (AUV) is a robot which travels underwater
2
without requiring input from an operator.
3
4
The NS-3 AUV module simulates the below AUVs:
5
6
Seaglider
7
REMUS 100
8
SAUV II
9
10
(-)a/src/auv/examples/auv-energy-model.cc (+111 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2010 Andrea Sacco
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: Andrea Sacco <andrea.sacco85@gmail.com>
19
 */
20
21
#include "ns3/glider-energy-model.h"
22
23
using namespace ns3;
24
25
/**
26
 * In this example we show the basic usage of an AUV energy model.
27
 * Specifically, we show how to create a generic node, adding to it a
28
 * basic energy source and consuming energy from the energy source.
29
 *
30
 * The Seaglider AUV power consumption depends on buoyancy and vertical
31
 * speed values, so we simulate a 20 seconds movement at 0.3 m/s of vertical
32
 * speed and 138g of buoyancy. Then a 20 seconds movement at 0.2 m/s
33
 * of vertical speed and 138g of buoyancy and then a stop of 5 seconds.
34
 *
35
 * The required energy will be drained by the model basing on the
36
 * given buoyancy/speed values, from the energy source installed onto
37
 * the node.
38
 *
39
 * We register a callback to the TotalEnergyConsumption traced value.
40
 */
41
42
void
43
DoubleTrace (double oldValue, double newValue)
44
{
45
  std::cout << "Energy changed from " << oldValue << "J to " << newValue << "J" << std::endl;
46
}
47
48
int
49
main (int argc, char **argv)
50
{
51
  // uncomment to see energy consumption details
52
  // LogComponentEnable ("GliderEnergyModel", LOG_LEVEL_ALL);
53
54
  // create node
55
  Ptr<Node> node = CreateObject<Node> ();
56
57
  // create energy source
58
  ObjectFactory m_energySource;
59
  m_energySource.SetTypeId ("ns3::BasicEnergySource");
60
  m_energySource.Set ("BasicEnergySourceInitialEnergyJ",
61
                      DoubleValue (10000000));
62
  Ptr<EnergySource> source = m_energySource.Create<EnergySource> ();
63
  source->SetNode (node);
64
  Ptr<EnergySourceContainer> sourceCont = CreateObject<EnergySourceContainer> ();
65
  sourceCont->Add (source);
66
  // aggregate energy source to node
67
  node->AggregateObject (sourceCont);
68
69
  // create device energy model
70
  Ptr<GliderEnergyModel> model = CreateObject<GliderEnergyModel> ();
71
  // set energy source pointer
72
  model->SetEnergySource (source);
73
  model->SetNode (node);
74
  // add device energy model to model list in energy source
75
  source->AppendDeviceEnergyModel (model);
76
  // register a callback to the total consumption value
77
  model->TraceConnectWithoutContext ("TotalEnergyConsumption", MakeCallback (&DoubleTrace));
78
79
  // retrieve device energy model from energy source
80
  DeviceEnergyModelContainer modelCont =
81
    source->FindDeviceEnergyModels ("ns3::GliderEnergyModel");
82
  NS_ASSERT (modelCont.GetN () != 0);
83
  // get pointer
84
  Ptr<GliderEnergyModel> devModel = DynamicCast<GliderEnergyModel> (modelCont.Get (0));
85
86
  // simulate 20 seconds of movement with 138g buoyancy and 0.3 m/s of W
87
  devModel->ChangeEnergyConsumption (138, 0.3);
88
89
  // simulate 20 seconds of movement with 138g buoyancy and 0.2 m/s of W
90
  Simulator::Schedule (Seconds (20),
91
                       &GliderEnergyModel::ChangeEnergyConsumption,
92
                       devModel,
93
                       138,
94
                       0.2);
95
96
  // simulate a stop of the vehicle for the remaining 5 seconds
97
  Simulator::Schedule (Seconds (40),
98
                       &GliderEnergyModel::ChangeEnergyConsumption,
99
                       devModel,
100
                       0,
101
                       0);
102
103
  // run simulation
104
  Simulator::Stop (Seconds (45));
105
  Simulator::Run ();
106
  Simulator::Destroy ();
107
108
  std::cout << "Remaining energy: " << source->GetRemainingEnergy () << std::endl;
109
110
  return 0;
111
}
(-)a/src/auv/examples/auv-mobility.cc (+172 lines)
Line 0    Link Here 
1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2010 Andrea Sacco
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: Andrea Sacco <andrea.sacco85@gmail.com>
19
 */
20
21
#include "ns3/glider-mobility-model.h"
22
#include "ns3/gnuplot.h"
23
#include "ns3/auv-mobility-helper.h"
24
25
#include <fstream>
26
27
using namespace ns3;
28
29
/**
30
 * We show how to use the AuvMobilityHelper to install an auv mobility model
31
 * into a (set of) node.
32
 *
33
 * Then we make the AUV to submerge to a depth of 1000 meters.
34
 * We also set a callback function called on reaching of the target depth.
35
 *
36
 * The callback then makes the AUV to emerge to water surface (0 meters).
37
 * We set a callback function called on reaching of the target depth.
38
 * The emerge callback then, stops the AUV.
39
 *
40
 * During the whole navigation process, the AUV's position is tracked by the
41
 * TracePos function and plotted into a Gnuplot graph.
42
 */
43
44
void Emerge (Ptr<GliderMobilityModel> mob);
45
46
static void
47
SubmergeCb (Ptr<MobilityModel> mob)
48
{
49
  // reached the target, makes the vehicle emerge
50
  Emerge (mob->GetObject<GliderMobilityModel> ());
51
}
52
53
static void
54
EmergeCb (Ptr<MobilityModel> mob)
55
{
56
  // stop the vehicle
57
  mob->GetObject<GliderMobilityModel> ()->Stop ();
58
}
59
60
void
61
Submerge (Ptr<GliderMobilityModel> mob)
62
{
63
  // set the submerge callback
64
  mob->SetSubmergeCallback (MakeCallback (&SubmergeCb));
65
66
  // makes the vehicle submerge to 1000m
67
  mob->Submerge (-1000);
68
}
69
70
void
71
Emerge (Ptr<GliderMobilityModel> mob)
72
{
73
  // set the emerge callback
74
  mob->SetEmergeCallback (MakeCallback (&EmergeCb));
75
76
  // makes the vehicle emerge to water surface
77
  mob->Emerge (0);
78
}
79
80
static void
81
TracePos (Gnuplot3dDataset* ds, Ptr<const GliderMobilityModel> mob)
82
{
83
  Vector curPos = mob->GetPosition ();
84
  ds->Add (curPos.x, curPos.y, curPos.z);
85
86
  Simulator::Schedule (Seconds (10),
87
                       &TracePos,
88
                       ds,
89
                       mob);
90
}
91
92
void
93
GeneratePlot (const GnuplotDataset& ds)
94
{
95
  Gnuplot gp;
96
  gp.SetTitle ("3D view");
97
  gp.SetExtra ("set multiplot");
98
  gp.AppendExtra ("set size 0.5,0.5");
99
  gp.AppendExtra ("set origin 0.0,0.0");
100
  gp.AppendExtra ("set view 60,30");
101
  gp.AddDataset (ds);
102
103
  Gnuplot gp1;
104
  gp1.SetTitle ("X-Y view");
105
  gp1.SetExtra ("set view 0,0");
106
  gp1.AppendExtra ("set origin 0.0,0.5");
107
  gp1.AddDataset (ds);
108
109
  Gnuplot gp2;
110
  gp2.SetTitle ("X-Z view");
111
  gp2.SetExtra ("set view 90,0");
112
  gp2.AppendExtra ("set origin 0.5,0.0");
113
  gp2.AddDataset (ds);
114
115
  Gnuplot gp3;
116
  gp3.SetTitle ("Y-Z view");
117
  gp3.SetExtra ("set view 0,90");
118
  gp3.AppendExtra ("set origin 0.5,0.5");
119
  gp3.AddDataset (ds);
120
121
  GnuplotCollection gpc ("seaglider-navigation-trace.eps");
122
  gpc.AddPlot (gp);
123
  gpc.AddPlot (gp1);
124
  gpc.AddPlot (gp2);
125
  gpc.AddPlot (gp3);
126
  gpc.SetTerminal ("postscript eps enhanced color \"Helvetica\" 10");
127
128
  std::ofstream of ("seaglider-navigation-trace.gpl");
129
  if (!of.is_open ())
130
    {
131
      NS_FATAL_ERROR ("Can not open GNU Plot outfile: seaglider-navigation-trace.gpl");
132
    }
133
  gpc.GenerateOutput (of);
134
  of.close ();
135
136
  std::cout << "Seaglider navigation trace successfully created!" << std::endl;
137
}
138
139
int
140
main (int argc, char **argv)
141
{
142
  NodeContainer node;
143
  node.Create (1);
144
145
  // install the glider mobility model
146
  AuvMobilityHelper rmh;
147
  rmh.SetType ("ns3::GliderMobilityModel");
148
  rmh.Install (node);
149
150
  Ptr<GliderMobilityModel> glider = DynamicCast<GliderMobilityModel> (node.Get (0)->GetObject<AuvMobilityModel> ());
151
  NS_ASSERT (glider != NULL);
152
153
  // set the initial position of the AUV
154
  glider->SetPosition (Vector (0.,0.,0.));
155
156
  // trace the position
157
  Gnuplot3dDataset ds ("Navigation Trace");
158
  TracePos (&ds, glider);
159
160
  // submerge
161
  Submerge (glider);
162
163
  // run simulation
164
  Simulator::Stop (Seconds (4001));
165
  Simulator::Run ();
166
  Simulator::Destroy ();
167
168
  // generate the navigation trace
169
  GeneratePlot (ds);
170
171
  return 0;
172
}
(-)a/src/auv/examples/auv-waypoint-mobility.cc (+106 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2010 Andrea Sacco
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: Andrea Sacco <andrea.sacco85@gmail.com>
19
 */
20
21
#include "ns3/remus-mobility-model.h"
22
#include "ns3/auv-waypoint-mobility-model.h"
23
#include "ns3/glider-mobility-model.h"
24
25
using namespace ns3;
26
27
/**
28
 * We show how to use the AuvWaypointMobilityModel with a non-standard
29
 * ConstantVelocityMobilityModel.
30
 *
31
 * We first create a waypoint model with an underlying RemusMobilityModel
32
 * setting the mobility trace with two waypoints.
33
 *
34
 * We then create a waypoint model with an underlying GliderMobilityModel
35
 * setting the waypoints separately with the AddWaypoint method.
36
 *
37
 * We start the simulation.
38
 *
39
 * The AUV's position is printed out every seconds.
40
 */
41
42
static void
43
TracePos (Ptr<const AuvWaypointMobilityModel> mob)
44
{
45
  Vector curPos = mob->GetPosition ();
46
47
  std::cout << "At " << Simulator::Now ().GetSeconds () << ": " <<
48
    curPos.x << " " << curPos.y << " " << curPos.z << std::endl;
49
50
  Simulator::Schedule (Seconds (1),
51
                       &TracePos,
52
                       mob);
53
}
54
55
56
int
57
main (int argc, char **argv)
58
{
59
  Ptr<Node> node1 = CreateObject<Node> ();
60
61
  // create the waypoint model
62
  Ptr<AuvWaypointMobilityModel> mm = CreateObject<AuvWaypointMobilityModel> ();
63
  Ptr<RemusMobilityModel> remus = CreateObject<RemusMobilityModel> ();
64
  remus->SetNode (node1);
65
  // set the RemusMobilityModel as the underlying model
66
  mm->SetValidatorMobilityModel (remus);
67
  node1->AggregateObject (mm);
68
69
  // set some waypoints
70
  mm->AddWaypoint (Waypoint (Seconds (0), Vector (0, 0, 0)));
71
  mm->AddWaypoint (Waypoint (Seconds (10), Vector (20, 0, 0)));
72
73
  std::cout << "Remus simulation" << std::endl;
74
75
  // trace the position
76
  TracePos (mm);
77
78
  // run the simulation
79
  Simulator::Stop (Seconds (15));
80
  Simulator::Run ();
81
  Simulator::Destroy ();
82
83
  // create another waypoint model with an underlying GliderMobilityModel
84
  Ptr<Node> node2 = CreateObject<Node> ();
85
  Ptr<GliderMobilityModel> gmm = CreateObject<GliderMobilityModel> ();
86
  gmm->SetNode (node2);
87
  Ptr<AuvWaypointMobilityModel> wpmm = CreateObject<AuvWaypointMobilityModel> ();
88
  wpmm->SetValidatorMobilityModel (gmm);
89
  node2->AggregateObject (wpmm);
90
91
  // set some waypoints
92
  wpmm->AddWaypoint (Waypoint (Seconds (0), Vector (0,0,0)));
93
  wpmm->AddWaypoint (Waypoint (Seconds (60), Vector (10,0,-20)));
94
95
  std::cout << std::endl << "Seaglider simulation" << std::endl;
96
97
  // trace the position
98
  TracePos (wpmm);
99
100
  // run the simulation
101
  Simulator::Stop (Seconds (62));
102
  Simulator::Run ();
103
  Simulator::Destroy ();
104
105
  return 0;
106
}
(-)a/src/auv/examples/uan-energy-auv.cc (+185 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2010 Andrea Sacco
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: Andrea Sacco <andrea.sacco85@gmail.com>
19
 */
20
#include "ns3/core-module.h"
21
#include "uan-energy-auv.h"
22
#include "ns3/auv-glider-helper.h"
23
#include "ns3/auv-waypoint-mobility-model.h"
24
#include "ns3/basic-energy-source-helper.h"
25
#include "ns3/constant-position-mobility-model.h"
26
#include "ns3/uan-channel.h"
27
#include "ns3/uan-noise-model-default.h"
28
#include "ns3/uan-prop-model-ideal.h"
29
#include "ns3/acoustic-modem-energy-model-helper.h"
30
#include "ns3/energy-model-helper.h"
31
32
using namespace ns3;
33
34
UanEnergyAuv::UanEnergyAuv ()
35
  : m_bytesRx (0),
36
  m_sentPackets (0)
37
{
38
}
39
40
UanEnergyAuv::~UanEnergyAuv ()
41
{
42
  m_auv = NULL;
43
  m_gateway = NULL;
44
}
45
46
void
47
UanEnergyAuv::SendOnePacket (Ptr<Node> node)
48
{
49
  // create an empty 17 bytes packet
50
  Ptr<Packet> pkt = Create<Packet> (17);
51
  // send the packet in broadcast
52
  Ptr<UanNetDevice> dev = node->GetDevice (0)->GetObject<UanNetDevice> ();
53
  dev->Send (pkt, dev->GetBroadcast (), 0);
54
  // increase the sent packets number
55
  ++m_sentPackets;
56
57
  Simulator::Schedule (Seconds (10),
58
                       &UanEnergyAuv::SendOnePacket,
59
                       this,
60
                       node);
61
}
62
63
bool
64
UanEnergyAuv::RxPacket (Ptr<NetDevice> dev, Ptr<const Packet> pkt, uint16_t mode, const Address &sender)
65
{
66
  // increase the total bytes received
67
  m_bytesRx += pkt->GetSize ();
68
69
  return true;
70
}
71
72
void
73
UanEnergyAuv::PrintStats ()
74
{
75
  Ptr<EnergySource> source;
76
77
  std::cout << "AUV: sent " << m_sentPackets << " packets" << std::endl;
78
  std::cout << "Gateway: received " << m_bytesRx << " bytes" << std::endl;
79
80
  source = m_gateway->GetObject<EnergySourceContainer> ()->Get (0);
81
  std::cout << "Gateway energy consumption: " << 100 - (source->GetEnergyFraction () * 100) << " %" << std::endl;
82
83
  source = m_auv->GetObject<EnergySourceContainer> ()->Get (0);
84
  std::cout << "AUV energy consumption (nav): " << 100 - (source->GetEnergyFraction () * 100) << " %" << std::endl;
85
86
  source = m_auv->GetObject<EnergySourceContainer> ()->Get (1);
87
  std::cout << "AUV energy consumption (comms): " << 100 - (source->GetEnergyFraction () * 100) << " %" << std::endl;
88
}
89
90
bool
91
UanEnergyAuv::Run ()
92
{
93
  UanHelper uan;
94
  AcousticModemEnergyModelHelper umem;
95
96
  // create a generic node
97
  m_auv = CreateObject<Node> ();
98
99
  // create a gateway node
100
  m_gateway = CreateObject<Node> ();
101
102
  // install the glider components
103
  AuvGliderHelper gh;
104
  gh.Install (m_auv);
105
106
  // move the vehicle somewhere
107
  Ptr<AuvWaypointMobilityModel> mob = m_auv->GetObject<AuvWaypointMobilityModel> ();
108
  mob->AddWaypoint (Waypoint (Seconds (0), Vector (500,0,0)));
109
  mob->AddWaypoint (Waypoint (Seconds (3000), Vector (0, 500,-1000)));
110
  mob->AddWaypoint (Waypoint (Seconds (6000), Vector (-500, 0, 0)));
111
  mob->AddWaypoint (Waypoint (Seconds (9000), Vector (0, 500,-1000)));
112
  mob->AddWaypoint (Waypoint (Seconds (12000), Vector (500, 0, 0)));
113
114
  // set the gateway mobility model
115
  Ptr<ConstantPositionMobilityModel> mobility = CreateObject<ConstantPositionMobilityModel> ();
116
  mobility->SetPosition (Vector (0, 0, 0));
117
  m_gateway->AggregateObject (mobility);
118
119
120
  // create a default underwater channel
121
  Ptr<UanChannel> channel = CreateObject<UanChannel> ();
122
  Ptr<UanNoiseModelDefault> noise = CreateObject<UanNoiseModelDefault> ();
123
  channel->SetPropagationModel (CreateObject<UanPropModelIdeal> ());
124
  channel->SetNoiseModel (noise);
125
126
  // install the underwater communication stack on AUV and gateway
127
  uan.Install (m_auv, channel);
128
  uan.Install (m_gateway, channel);
129
130
  // setup the energy sources for AUV and gateway
131
  BasicEnergySourceHelper eh;
132
  eh.Set ("BasicEnergySourceInitialEnergyJ", DoubleValue (3888000.0));
133
  eh.Install (m_gateway);
134
135
  // Check nodes setup
136
  Ptr<EnergySource> gatewayEnergySource = m_gateway->GetObject<EnergySourceContainer> ()->Get (0);
137
  NS_ASSERT (gatewayEnergySource != NULL);
138
139
  Ptr<EnergySource> auvEnergySource = m_auv->GetObject<EnergySourceContainer> ()->Get (1);
140
  NS_ASSERT (auvEnergySource != NULL);
141
142
  Ptr<NetDevice> gatewayDevice = m_gateway->GetDevice (0);
143
  NS_ASSERT (gatewayDevice != NULL);
144
145
  Ptr<NetDevice> auvDevice = m_auv->GetDevice (0);
146
  NS_ASSERT (auvDevice != NULL);
147
148
  // micro modem energy model
149
  umem.Install (gatewayDevice, gatewayEnergySource);
150
  umem.Install (auvDevice, auvEnergySource);
151
152
  // Animate with a packet every 10 seconds
153
  Simulator::ScheduleNow (&UanEnergyAuv::SendOnePacket,
154
                          this,
155
                          m_auv);
156
157
  // set the receive callback
158
  gatewayDevice->SetReceiveCallback (MakeCallback (&UanEnergyAuv::RxPacket,
159
                                                   this));
160
  // run the simulation
161
  Simulator::Stop (Hours (3));
162
  Simulator::Run ();
163
  // print the simulation's statistics
164
  PrintStats ();
165
  Simulator::Destroy ();
166
  return false;
167
}
168
169
int
170
main (int argc, char **argv)
171
{
172
  CommandLine cmd;
173
  UanEnergyAuv uan;
174
175
  cmd.Parse (argc, argv);
176
177
  // uncomment to see models log
178
  // LogComponentEnable("GliderEnergyModel", LOG_LEVEL_ALL);
179
  // LogComponentEnable("BasicEnergySource", LOG_LEVEL_ALL);
180
  // LogComponentEnable("AcousticModemEnergyModel", LOG_LEVEL_ALL);
181
182
  uan.Run ();
183
184
  return 0;
185
}
(-)a/src/auv/examples/uan-energy-auv.h (+70 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2010 Andrea Sacco
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: Andrea Sacco <andrea.sacco85@gmail.com>
19
 */
20
21
#ifndef UAN_ENERGY_AUV_H
22
#define UAN_ENERGY_AUV_H
23
24
25
26
/**
27
 * This is a comprehensive example where all the project's components are used.
28
 * We setup two nodes, one fixed surface gateway and a moving Seaglider AUV,
29
 * both equipped with an acoustic modem.
30
 *
31
 * Using the waypoint mobility model with an underlying GliderMobilityModel,
32
 * we make the glider descend to -1000 meters and then emerge to the water surface.
33
 *
34
 * The AUV sends a generic 17-bytes packet every 10 seconds during the navigation
35
 * process.
36
 * The gateway receives the packets and stores the total bytes amount.
37
 *
38
 * During the simulation the AUV consumes energy for navigation and packets sending.
39
 * The energy drained is subtracted from the main energy source.
40
 * The surface gateway instead consumes energy only receiving packets.
41
 *
42
 * At the end of the simulation are printed out the energy consumptions of the two
43
 * nodes and the networking stats.
44
 */
45
46
#include "ns3/packet.h"
47
#include "ns3/uan-helper.h"
48
49
using namespace ns3;
50
51
class UanEnergyAuv
52
{
53
public:
54
  UanEnergyAuv ();
55
  ~UanEnergyAuv ();
56
57
  bool RxPacket (Ptr<NetDevice> dev, Ptr<const Packet> pkt, uint16_t mode, const Address &sender);
58
  void SendOnePacket (Ptr<Node> node);
59
60
  void PrintStats ();
61
62
  bool Run (void);
63
64
  uint32_t m_bytesRx;
65
  uint32_t m_sentPackets;
66
  Ptr<Node> m_auv;
67
  Ptr<Node> m_gateway;
68
};
69
70
#endif /* UAN_ENERGY_AUV_H */
(-)a/src/auv/examples/wscript (+15 lines)
Line 0    Link Here 
1
# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
3
def build(bld):
4
    obj = bld.create_ns3_program('uan-energy-auv', ['internet', 'uan', 'mobility', 'auv', 'energy'])
5
    obj.source = 'uan-energy-auv.cc'
6
7
    obj = bld.create_ns3_program('auv-energy-model', ['internet', 'mobility', 'auv', 'energy'])
8
    obj.source = 'auv-energy-model.cc'
9
10
    obj = bld.create_ns3_program('auv-waypoint-mobility', ['internet', 'mobility', 'auv'])
11
    obj.source = 'auv-waypoint-mobility.cc'
12
13
    obj = bld.create_ns3_program('auv-mobility', ['internet', 'mobility', 'auv'])
14
    obj.source = 'auv-mobility.cc'
15
(-)a/src/auv/helper/auv-glider-helper.cc (+139 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2010 Andrea Sacco
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: Andrea Sacco <andrea.sacco85@gmail.com>
19
 */
20
21
#include "auv-glider-helper.h"
22
#include "ns3/net-device-container.h"
23
#include "ns3/auv-mobility-helper.h"
24
#include "ns3/li-ion-energy-source.h"
25
#include "ns3/glider-energy-model.h"
26
#include "ns3/glider-mobility-model.h"
27
#include "ns3/auv-waypoint-mobility-model.h"
28
#include "ns3/energy-source-container.h"
29
#include "ns3/acoustic-modem-energy-model-helper.h"
30
#include "ns3/uan-channel.h"
31
#include "ns3/uan-net-device.h"
32
#include "ns3/uan-helper.h"
33
34
namespace ns3 {
35
36
AuvGliderHelper::AuvGliderHelper ()
37
{
38
}
39
40
void
41
AuvGliderHelper::Install (NodeContainer c) const
42
{
43
  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
44
    {
45
      Install (*i);
46
    }
47
}
48
49
void
50
AuvGliderHelper::Install (std::string nodeName) const
51
{
52
  Ptr<Node> node = Names::Find<Node> (nodeName);
53
  Install (node);
54
}
55
56
void
57
AuvGliderHelper::Install (Ptr<Node> node) const
58
{
59
  // waypoint mobility model with underlying glider mobility model
60
  Ptr<GliderMobilityModel> gmm = CreateObject<GliderMobilityModel> ();
61
  gmm->SetNode (node);
62
  Ptr<AuvWaypointMobilityModel> wpmm = CreateObject<AuvWaypointMobilityModel> ();
63
  wpmm->SetValidatorMobilityModel (gmm);
64
  node->AggregateObject (wpmm);
65
66
  // Motor battery pack. 7 in-series string x 6 strings = 42 cells
67
  // Capacity 18.1 MJ @ 24 V
68
  //
69
  //     +--C-C-C-C-C-C-C--+
70
  //     +--C-C-C-C-C-C-C--+
71
  //  ---+--C-C-C-C-C-C-C--+---
72
  //     +--C-C-C-C-C-C-C--+
73
  //     +--C-C-C-C-C-C-C--+
74
  //     +--C-C-C-C-C-C-C--+
75
  //
76
  Ptr<EnergySourceContainer> esContainer = CreateObject<EnergySourceContainer> ();
77
  Ptr<EnergySourceContainer> cont = node->GetObject<EnergySourceContainer> ();
78
  NS_ASSERT_MSG (cont == 0, "Energy source already installed!");
79
  ObjectFactory fact;
80
  fact.SetTypeId (LiIonEnergySource::GetTypeId ());
81
  fact.Set ("LiIonEnergySourceInitialEnergyJ", DoubleValue (13608000.0));
82
  fact.Set ("InitialCellVoltage", DoubleValue (3.45 * 7));
83
  fact.Set ("NominalCellVoltage", DoubleValue (3.3 * 7));
84
  fact.Set ("ExpCellVoltage", DoubleValue (3.55 * 7));
85
  fact.Set ("RatedCapacity", DoubleValue (30.0 * 6));
86
  fact.Set ("NomCapacity", DoubleValue (27.0 * 6));
87
  fact.Set ("ExpCapacity", DoubleValue (15.0 * 6));
88
  // 0.145 ohm per cell, 7 in series and 6 string in parallel
89
  // Gstring = 1 / (0.145 * 7)
90
  // Rint = 1 / (Gstring * 6)
91
  fact.Set ("InternalResistance", DoubleValue (0.16917));
92
  fact.Set ("TypCurrent", DoubleValue (1.0 * 6));
93
  fact.Set ("ThresholdVoltage", DoubleValue (3.0 * 6));
94
  Ptr<LiIonEnergySource> devSource = fact.Create ()->GetObject<LiIonEnergySource> ();
95
  devSource->SetNode (node);
96
  esContainer->Add (devSource);
97
98
  // Analogic/digital power battery pack. 3 in-series string x 4 strings = 12 cells
99
  // Capacity 18.1 MJ @ 10 V
100
  //
101
  //     +--C-C-C--+
102
  //     +--C-C-C--+
103
  //  ---+--C-C-C--+---
104
  //     +--C-C-C--+
105
  //
106
  fact.SetTypeId (LiIonEnergySource::GetTypeId ());
107
  fact.Set ("LiIonEnergySourceInitialEnergyJ", DoubleValue (3888000.0));
108
  fact.Set ("InitialCellVoltage", DoubleValue (3.45 * 3));
109
  fact.Set ("NominalCellVoltage", DoubleValue (3.3 * 3));
110
  fact.Set ("ExpCellVoltage", DoubleValue (3.55 * 3));
111
  fact.Set ("RatedCapacity", DoubleValue (30.0 * 4));
112
  fact.Set ("NomCapacity", DoubleValue (27.0 * 4));
113
  fact.Set ("ExpCapacity", DoubleValue (15.0 * 4));
114
  // 0.145 ohm per cell, 3 in series and 4 string in parallel
115
  // Gstring = 1 / (0.145 * 3)
116
  // Rint = 1 / (Gstring * 4)
117
  fact.Set ("InternalResistance", DoubleValue (0.10875));
118
  fact.Set ("TypCurrent", DoubleValue (1.0 * 4));
119
  fact.Set ("ThresholdVoltage", DoubleValue (3.0 * 4));
120
  Ptr<LiIonEnergySource> devSource1 = fact.Create ()->GetObject<LiIonEnergySource> ();
121
  devSource1->SetNode (node);
122
  esContainer->Add (devSource1);
123
124
  node->AggregateObject (esContainer);
125
126
  // get the installed energy source container
127
  cont = node->GetObject<EnergySourceContainer> ();
128
  NS_ASSERT (cont != NULL);
129
130
  // glider energy model
131
  Ptr<GliderEnergyModel> gem = CreateObject<GliderEnergyModel> ();
132
  gem->SetEnergySource (devSource);
133
  gem->SetNode (node);
134
  devSource->AppendDeviceEnergyModel (gem);
135
  gem->SetEnergyDepletionCallback (MakeCallback (&AuvWaypointMobilityModel::HandleEnergyDepletion, wpmm));
136
  gem->SetEnergyRechargedCallback (MakeCallback (&AuvWaypointMobilityModel::HandleEnergyRecharged, wpmm));
137
}
138
139
} // namespace ns3
(-)a/src/auv/helper/auv-glider-helper.h (+95 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2010 Andrea Sacco
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: Andrea Sacco <andrea.sacco85@gmail.com>
19
 */
20
21
#ifndef AUV_GLIDER_HELPER_H
22
#define AUV_GLIDER_HELPER_H
23
24
#include "ns3/node-container.h"
25
#include "ns3/object-factory.h"
26
#include "ns3/names.h"
27
28
namespace ns3 {
29
30
/**
31
 * \ingroup auv
32
 * Install into a node (or set of nodes) the Seaglider's features:
33
 * - waypoint model with underlying glider mobility model
34
 * - glider energy model
35
 * - glider energy source
36
 * - micro modem energy model
37
 *
38
 * The glider mobility model is the GliderMobilityModel with default parameters.
39
 *
40
 * The glider energy model is the GliderEnergyModel with default parameters.
41
 *
42
 * Regarding the energy source, the Seaglider features two battery packs, one
43
 * for motor power and one for digital-analog power.
44
 * Each pack is composed of 12 (10V) and 42 (24V) lithium chloride DD-cell batteries,
45
 * respectively [1]. The total power capacity is around 17.5 MJ (3.9 MJ + 13.6 MJ).
46
 * In the original version of the Seaglider there was 18 + 63 D-cell with a total
47
 * power capacity of 10MJ.
48
 *
49
 * The packs design is as follows:
50
 * 10V - 3 in-series string x 4 strings = 12 cells - typical capacity ~100 Ah
51
 * 24V - 7 in-series-strings x 6 strings = 42 cells - typical capacity ~150 Ah
52
 *
53
 * Battery cells are Electrochem 3B36, with 3.6 V nominal voltage and 30.0 Ah
54
 * nominal capacity.
55
 *
56
 * The 10V battery pack is associated with the electronic devices, while the 24V one
57
 * is associated with the pump motor.
58
 *
59
 * The micro modem energy model is the AcousticModemEnergyModel with default parameters.
60
 *
61
 * References:
62
 * [1] Eriksen et al, "Seaglider: A Long-Range Autonomous Underwater Vehicle for Oceanographic Research"
63
 *     URL: http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=972073&userType=inst
64
 */
65
class AuvGliderHelper
66
{
67
public:
68
  AuvGliderHelper ();
69
70
  /**
71
   * Install the Glider features into a set of nodes.
72
   *
73
   * \param c NodeContainer where to install the features
74
   */
75
  void Install (NodeContainer c) const;
76
77
  /**
78
   * Install the Glider features into a single node.
79
   *
80
   * \param nodeName Name of the node where to install the features.
81
   */
82
  void Install (std::string nodeName) const;
83
84
  /**
85
   * Install the Glider features into a single node.
86
   *
87
   * \param node Pointer of the node where to install the features.
88
   */
89
  void Install (Ptr<Node> node) const;
90
91
};
92
93
} // namespace ns3
94
95
#endif /* AUV_GLIDER_HELPER_H */
(-)a/src/auv/helper/auv-mobility-helper.cc (+112 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2010 Andrea Sacco
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: Andrea Sacco <andrea.sacco85@gmail.com>
19
 */
20
#include "auv-mobility-helper.h"
21
#include "ns3/remus-mobility-model.h"
22
#include "ns3/string.h"
23
24
namespace ns3 {
25
26
AuvMobilityHelper::AuvMobilityHelper ()
27
{
28
  m_factory.SetTypeId ("ns3::RemusMobilityModel");
29
30
  m_allocator = CreateObjectWithAttributes<RandomBoxPositionAllocator>
31
      ("X", StringValue ("ns3::ConstantRandomVariable[Constant=0.0]"),
32
      "Y", StringValue ("ns3::ConstantRandomVariable[Constant=0.0]"),
33
      "Z", StringValue ("ns3::ConstantRandomVariable[Constant=0.0]"));
34
}
35
36
void
37
AuvMobilityHelper::SetType (std::string type)
38
{
39
  m_factory.SetTypeId (type);
40
}
41
42
void AuvMobilityHelper::SetAttribute (std::string name,
43
                                      const AttributeValue &value)
44
{
45
  m_factory.Set (name,
46
                 value);
47
}
48
49
void
50
AuvMobilityHelper::SetPositionAllocator (Ptr<PositionAllocator> allocator)
51
{
52
  m_allocator = allocator;
53
}
54
55
void
56
AuvMobilityHelper::SetPositionAllocator (std::string type,
57
                                         std::string n1, const AttributeValue &v1,
58
                                         std::string n2, const AttributeValue &v2,
59
                                         std::string n3, const AttributeValue &v3,
60
                                         std::string n4, const AttributeValue &v4,
61
                                         std::string n5, const AttributeValue &v5,
62
                                         std::string n6, const AttributeValue &v6,
63
                                         std::string n7, const AttributeValue &v7,
64
                                         std::string n8, const AttributeValue &v8,
65
                                         std::string n9, const AttributeValue &v9)
66
{
67
  ObjectFactory pos;
68
  pos.SetTypeId (type);
69
  pos.Set (n1, v1);
70
  pos.Set (n2, v2);
71
  pos.Set (n3, v3);
72
  pos.Set (n4, v4);
73
  pos.Set (n5, v5);
74
  pos.Set (n6, v6);
75
  pos.Set (n7, v7);
76
  pos.Set (n8, v8);
77
  pos.Set (n9, v9);
78
  m_allocator = pos.Create ()->GetObject<PositionAllocator> ();
79
}
80
81
void
82
AuvMobilityHelper::Install (NodeContainer c) const
83
{
84
  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
85
    {
86
      Install (*i);
87
    }
88
}
89
90
void
91
AuvMobilityHelper::Install (std::string nodeName) const
92
{
93
  Ptr<Node> node = Names::Find<Node> (nodeName);
94
  Install (node);
95
}
96
97
void
98
AuvMobilityHelper::Install (Ptr<Node> node) const
99
{
100
  Ptr<AuvMobilityModel> model = m_factory.Create ()->GetObject<AuvMobilityModel> ();
101
102
  NS_ASSERT_MSG (model != NULL,
103
                 "The requested mobility model is not an auv mobility model: \"" <<
104
                 m_factory.GetTypeId ().GetName () << "\"");
105
106
  Vector pos = m_allocator->GetNext ();
107
  model->SetPosition (pos);
108
  model->SetNode (node);
109
  node->AggregateObject (model);
110
}
111
112
} // namespace ns3
(-)a/src/auv/helper/auv-mobility-helper.h (+138 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2010 Andrea Sacco
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: Andrea Sacco <andrea.sacco85@gmail.com>
19
 */
20
21
#ifndef AUV_MOBILITY_HELPER_H
22
#define AUV_MOBILITY_HELPER_H
23
24
25
#include "ns3/node-container.h"
26
#include "ns3/object-factory.h"
27
#include "ns3/position-allocator.h"
28
#include "ns3/names.h"
29
30
namespace ns3 {
31
32
/**
33
 * \ingroup auv
34
 * \brief Install into a set of nodes an AuvMobilityModel
35
 *
36
 * Install into a set of nodes (or single node) the specified AuvMobilityModel.
37
 * The specific AuvMobilityModel can be specified with the SetType method.
38
 *
39
 * The helper also uses a PositionAllocator to set the nodes positions.
40
 *
41
 * By default the mobility model is the RemusMobilityModel and the position
42
 * allocator is a RandomBoxPositionAllocator with X, Y and Z variables set to
43
 * constant zero.
44
 */
45
class AuvMobilityHelper
46
{
47
public:
48
  /**
49
   * Set the default mobility model (RemusMobilityModel) and the
50
   * default position allocator (RandomBoxPositionAllocator with
51
   * constant position in 0,0,0)
52
   */
53
  AuvMobilityHelper ();
54
55
  /**
56
   * \param type the AUV mobility model TypeId
57
   */
58
  void SetType (std::string type);
59
60
  /**
61
   * Set an attribute of the specified auv mobility model
62
   *
63
   * \param name name of the parameter
64
   * \param value value of the parameter
65
   */
66
  void SetAttribute (std::string name, const AttributeValue &value);
67
  /**
68
   * Set the position allocator to be used during the install process
69
   * to give each node an initial position
70
   *
71
   * \param allocator the position allocator to be set
72
   */
73
  void SetPositionAllocator (Ptr<PositionAllocator> allocator);
74
  /**
75
   * Set the position allocator to be used during the install process
76
   * to give each node an initial position
77
   *
78
   * \param type the position allocator TypeId
79
   * \param n1 the name of the attribute to set
80
   * \param v1 the value of the attribute to set
81
   * \param n2 the name of the attribute to set
82
   * \param v2 the value of the attribute to set
83
   * \param n3 the name of the attribute to set
84
   * \param v3 the value of the attribute to set
85
   * \param n4 the name of the attribute to set
86
   * \param v4 the value of the attribute to set
87
   * \param n5 the name of the attribute to set
88
   * \param v5 the value of the attribute to set
89
   * \param n6 the name of the attribute to set
90
   * \param v6 the value of the attribute to set
91
   * \param n7 the name of the attribute to set
92
   * \param v7 the value of the attribute to set
93
   * \param n8 the name of the attribute to set
94
   * \param v8 the value of the attribute to set
95
   * \param n9 the name of the attribute to set
96
   * \param v9 the value of the attribute to set
97
   */
98
  void SetPositionAllocator (std::string type,
99
                             std::string n1, const AttributeValue &v1,
100
                             std::string n2, const AttributeValue &v2,
101
                             std::string n3, const AttributeValue &v3,
102
                             std::string n4, const AttributeValue &v4,
103
                             std::string n5, const AttributeValue &v5,
104
                             std::string n6, const AttributeValue &v6,
105
                             std::string n7, const AttributeValue &v7,
106
                             std::string n8, const AttributeValue &v8,
107
                             std::string n9, const AttributeValue &v9);
108
109
  /**
110
   * For each of the input nodes a new mobility model of the specified type
111
   * is created and attached to the node.
112
   *
113
   * \param c a set of nodes
114
   */
115
  void Install (NodeContainer c) const;
116
117
  /**
118
   * Install the specified auv mobility model into the node with the specified
119
   * name.
120
   *
121
   * \param nodeName name of the node
122
   */
123
  void Install (std::string nodeName) const;
124
125
  /**
126
   * Install the specified auv mobility model into the specified node
127
   *
128
   * \param node Pointer of the node where to install the mobility model
129
   */
130
  void Install (Ptr<Node> node) const;
131
132
  ObjectFactory m_factory;
133
  Ptr<PositionAllocator> m_allocator;
134
};
135
136
} // namespace ns3
137
138
#endif /* AUV_MOBILITY_HELPER_H */
(-)a/src/auv/helper/auv-remus-helper.cc (+83 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2010 Andrea Sacco
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: Andrea Sacco <andrea.sacco85@gmail.com>
19
 */
20
#include "auv-remus-helper.h"
21
#include "ns3/auv-mobility-helper.h"
22
#include "ns3/basic-energy-source-helper.h"
23
#include "ns3/remus-energy-model.h"
24
#include "ns3/remus-mobility-model.h"
25
#include "ns3/auv-waypoint-mobility-model.h"
26
#include "ns3/acoustic-modem-energy-model-helper.h"
27
#include "ns3/uan-channel.h"
28
#include "ns3/uan-net-device.h"
29
#include "ns3/uan-helper.h"
30
#include "ns3/net-device-container.h"
31
#include "ns3/net-device-container.h"
32
33
namespace ns3 {
34
35
AuvRemusHelper::AuvRemusHelper ()
36
{
37
}
38
39
void
40
AuvRemusHelper::Install (NodeContainer c) const
41
{
42
  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
43
    {
44
      Install (*i);
45
    }
46
}
47
48
void
49
AuvRemusHelper::Install (std::string nodeName) const
50
{
51
  Ptr<Node> node = Names::Find<Node> (nodeName);
52
  Install (node);
53
}
54
55
void
56
AuvRemusHelper::Install (Ptr<Node> node) const
57
{
58
  // waypoint mobility model with underlying remus mobility model
59
  Ptr<RemusMobilityModel> rmm = CreateObject<RemusMobilityModel> ();
60
  rmm->SetNode (node);
61
  Ptr<AuvWaypointMobilityModel> wpmm = CreateObject<AuvWaypointMobilityModel> ();
62
  wpmm->SetValidatorMobilityModel (rmm);
63
  node->AggregateObject (wpmm);
64
65
  // 1.1 kWh -> 1.1 * 1000 * 3600 = 3960000J
66
  // remus energy source
67
  BasicEnergySourceHelper eh;
68
  eh.Set ("BasicEnergySourceInitialEnergyJ", DoubleValue (3960000.0));
69
  eh.Install (node);
70
71
  // remus energy model
72
  Ptr<RemusEnergyModel> rem = CreateObject<RemusEnergyModel> ();
73
  Ptr<EnergySource> source = node->GetObject<EnergySourceContainer> ()->Get (0);
74
  NS_ASSERT (source != NULL);
75
  rem->SetEnergySource (source);
76
  source->AppendDeviceEnergyModel (rem);
77
  source->SetNode (node);
78
  rem->SetNode (node);
79
  rem->SetEnergyDepletionCallback (MakeCallback (&AuvWaypointMobilityModel::HandleEnergyDepletion, wpmm));
80
  rem->SetEnergyRechargedCallback (MakeCallback (&AuvWaypointMobilityModel::HandleEnergyRecharged, wpmm));
81
}
82
83
} // namespace ns3
(-)a/src/auv/helper/auv-remus-helper.h (+85 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2010 Andrea Sacco
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: Andrea Sacco <andrea.sacco85@gmail.com>
19
 */
20
21
#ifndef AUV_REMUS_HELPER_H
22
#define AUV_REMUS_HELPER_H
23
24
#include "ns3/node.h"
25
#include "ns3/node-container.h"
26
#include "ns3/object-factory.h"
27
#include "ns3/names.h"
28
29
namespace ns3 {
30
31
/**
32
 * \ingroup auv
33
 * Install into a node (or set of nodes) the REMUS features:
34
 * - waypoint model with REMUS mobility model validation
35
 * - REMUS energy model
36
 * - REMUS energy source
37
 * - micro modem energy model
38
 *
39
 * The REMUS mobility model is the RemusMobilityModel with default parameters.
40
 *
41
 * The REMUS energy model is the RemusEnergyModel with default parameters.
42
 *
43
 * Regarding the energy source, the REMUS features a rechargeable lithium ion
44
 * battery pack rated 1.1 kWh @ 27 V (40 Ah) in operating conditions (specifications
45
 * from [1] and Hydroinc European salesman).
46
 * Since more detailed information about battery pack were not publicly available,
47
 * the energy source used is a BasicEnergySource.
48
 *
49
 * The micro modem energy model is the AcousticModemEnergyModel with default parameters.
50
 *
51
 * References:
52
 *
53
 * [1] Hydroinc Products; http://www.hydroidinc.com/products.html
54
 */
55
class AuvRemusHelper
56
{
57
public:
58
  AuvRemusHelper ();
59
60
  /**
61
   * Install the REMUS features into a set of nodes
62
   *
63
   * \param c NodeContainer where to install the features
64
   */
65
  void Install (NodeContainer c) const;
66
67
  /**
68
   * Install the REMUS features into a single node
69
   *
70
   * \param nodeName Name of the node where to install the features
71
   */
72
  void Install (std::string nodeName) const;
73
74
  /**
75
   * Install the REMUS features into a single node
76
   *
77
   * \param node Pointer of the node where to install the features
78
   */
79
  void Install (Ptr<Node> node) const;
80
81
};
82
83
} // namespace ns3
84
85
#endif /* AUV_REMUS_HELPER_H */
(-)a/src/auv/model/auv-mobility-model.cc (+114 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2010 Andrea Sacco
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: Andrea Sacco <andrea.sacco85@gmail.com>
19
 */
20
21
#include "auv-mobility-model.h"
22
23
namespace ns3 {
24
25
TypeId
26
AuvMobilityModel::GetTypeId (void)
27
{
28
  static TypeId tid = TypeId ("ns3::AuvMobilityModel")
29
    .SetParent (MobilityModel::GetTypeId ())
30
  ;
31
  return tid;
32
}
33
34
AuvMobilityModel::AuvMobilityModel ()
35
{
36
}
37
38
AuvMobilityModel::~AuvMobilityModel ()
39
{
40
}
41
42
void
43
AuvMobilityModel::Move (void)
44
{
45
  return DoMove ();
46
}
47
48
void
49
AuvMobilityModel::Stop (void)
50
{
51
  return DoStop ();
52
}
53
54
void
55
AuvMobilityModel::Emerge (double depth)
56
{
57
  return DoEmerge (depth);
58
}
59
60
void
61
AuvMobilityModel::Submerge (double depth)
62
{
63
  return DoSubmerge (depth);
64
}
65
66
double
67
AuvMobilityModel::GetPitch () const
68
{
69
  return DoGetPitch ();
70
}
71
72
void
73
AuvMobilityModel::SetPitch (double pitch)
74
{
75
  return DoSetPitch (pitch);
76
}
77
78
double
79
AuvMobilityModel::GetDepth (void)
80
{
81
  return DoGetDepth ();
82
}
83
84
double
85
AuvMobilityModel::GetDirection (void) const
86
{
87
  return DoGetDirection ();
88
}
89
90
void
91
AuvMobilityModel::SetDirection (double dir)
92
{
93
  return DoSetDirection (dir);
94
}
95
96
double
97
AuvMobilityModel::GetSpeed () const
98
{
99
  return DoGetSpeed ();
100
}
101
102
void
103
AuvMobilityModel::SetSpeed (double speed)
104
{
105
  return DoSetSpeed (speed);
106
}
107
108
void
109
AuvMobilityModel::SetVelocity (const Vector &velocity)
110
{
111
  return DoSetVelocity (velocity);
112
}
113
114
} // namespace ns3
(-)a/src/auv/model/auv-mobility-model.h (+198 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2010 Andrea Sacco
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: Andrea Sacco <andrea.sacco85@gmail.com>
19
 */
20
21
#ifndef AUV_MOBILITY_MODEL_H_
22
#define AUV_MOBILITY_MODEL_H_
23
24
#include "ns3/constant-velocity-mobility-model.h"
25
#include "ns3/node.h"
26
27
namespace ns3 {
28
29
/**
30
 * \ingroup auv
31
 * \brief keep track of the current position of an Autonomous Underwater Vehicle (AUV)
32
 *
33
 * Define an interface for AUV mobility models. Every AUV mobility model should derive
34
 * from this interface, and implements all the pure virtual methods.
35
 *
36
 * The interface allow the client to move/stop the vehicle's movement, makes it submerge
37
 * or emerge to a target depth, and getting and setting the main navigation's parameter
38
 * like pitch, direction, speed.
39
 *
40
 * The emerge and submerge callback are called when the vehicle reach the target depth.
41
 */
42
class AuvMobilityModel : public MobilityModel
43
{
44
public:
45
  static TypeId GetTypeId (void);
46
  AuvMobilityModel ();
47
  virtual ~AuvMobilityModel () = 0;
48
49
  /**
50
   * Makes the AUV to move along the given direction
51
   */
52
  void Move (void);
53
  /**
54
   * Makes the AUV to stop
55
   */
56
  void Stop (void);
57
  /**
58
   * Makes the AUV to emerge at the maximum velocity
59
   * to the given depth
60
   * \param depth the depth to which emerge to, in m (negative)
61
   */
62
  void Emerge (double depth);
63
  /**
64
   * Makes the AUV to submerge at the maximum velocity
65
   * to the given depth
66
   * \param depth the depth to which submerge to, in m (negative)
67
   */
68
  void Submerge (double depth);
69
  /**
70
   * \returns the current pitch in degrees
71
   */
72
  double GetPitch () const;
73
74
  /**
75
   * \param pitch the pitch to set in degrees
76
   */
77
  void SetPitch (double pitch);
78
  /**
79
   * \returns the current depth
80
   */
81
  double GetDepth (void);
82
  /**
83
   * \returns the current direction in degrees
84
   */
85
  double GetDirection (void) const;
86
  /**
87
   * \param dir the heading direction in degrees
88
   */
89
  void SetDirection (double dir);
90
  /**
91
   * \returns the current speed in m/s
92
   */
93
  double GetSpeed () const;
94
  /**
95
   * \param speed the speed to set in m/s
96
   */
97
  void SetSpeed (double speed);
98
  /**
99
   * \param velocity the velocity vector to set
100
   */
101
  void SetVelocity (const Vector &velocity);
102
  /**
103
   * \param node the node associated with the mobility model
104
   */
105
  virtual void SetNode (const Ptr<Node> node) = 0;
106
  /**
107
   * \returns the associated node
108
   */
109
  virtual Ptr<Node> GetNode (void) const = 0;
110
  /**
111
   * \param cb the callback being called at the end of the emerging process
112
   */
113
  virtual void SetEmergeCallback (Callback<void, Ptr<MobilityModel> > cb) = 0;
114
115
  /**
116
   ** \param cb the callback being called at the end of the submerging process
117
   */
118
  virtual void SetSubmergeCallback (Callback<void, Ptr<MobilityModel> > cb) = 0;
119
120
private:
121
  /**
122
   * Concrete subclasses of this base class must
123
   * implement this methods.
124
   */
125
126
  /**
127
   * Makes the AUV to move along the given direction
128
   */
129
  virtual void DoMove (void) = 0;
130
  /**
131
   * Makes the AUV to stop
132
   */
133
  virtual void DoStop (void) = 0;
134
  /**
135
   * Makes the AUV to emerge at the maximum velocity
136
   * to the given depth. When reaching the target depth, it
137
   * will be called the EmergeCallback, if set.
138
   * \param depth the depth to which emerge to, in m (negative)
139
   */
140
  virtual void DoEmerge (double depth) = 0;
141
  /**
142
   * Makes the AUV to submerge at the maximum velocity
143
   * to the given depth. When reaching the target depth, it
144
   * will be called the SubmergeCallback, if set.
145
   * \param depth the depth to which submerge to, in m (negative)
146
   */
147
  virtual void DoSubmerge (double depth) = 0;
148
  /**
149
   * \returns the current pitch in degrees
150
   */
151
  virtual double DoGetPitch () const = 0;
152
  /**
153
   * \param pitch the pitch to set in degrees
154
   */
155
  virtual void DoSetPitch (double pitch) = 0;
156
  /**
157
   * \returns the current depth
158
   */
159
  virtual double DoGetDepth (void) = 0;
160
  /**
161
   * \returns the current direction in degrees
162
   */
163
  virtual double DoGetDirection (void) const = 0;
164
  /**
165
   * \param direction the heading direction in degrees
166
   */
167
  virtual void DoSetDirection (double dir) = 0;
168
  /**
169
   * \returns the current speed in m/s
170
   */
171
  virtual double DoGetSpeed () const = 0;
172
  /**
173
   * \param speed the speed to set in m/s
174
   */
175
  virtual void DoSetSpeed (double speed) = 0;
176
  /**
177
   * \param velocity the velocity vector to set
178
   */
179
  virtual void DoSetVelocity (const Vector &velocity) = 0;
180
181
  // inherited from MobilityModel
182
  /**
183
   * \returns the current position
184
   */
185
  virtual Vector DoGetPosition (void) const = 0;
186
  /**
187
   * \param position the position to set
188
   */
189
  virtual void DoSetPosition (const Vector &position) = 0;
190
  /**
191
   * \returns the current velocity vector
192
   */
193
  virtual Vector DoGetVelocity (void) const = 0;
194
};
195
196
}   // namespace ns3
197
198
#endif /* AUV_MOBILITY_MODEL_H_ */
(-)a/src/auv/model/auv-waypoint-mobility-model.cc (+280 lines)
Line 0    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: Andrea Sacco <andrea.sacco85@gmail.com>
17
 */
18
#include "auv-waypoint-mobility-model.h"
19
20
namespace ns3 {
21
22
NS_LOG_COMPONENT_DEFINE ("AuvWaypointMobilityModel");
23
24
NS_OBJECT_ENSURE_REGISTERED (AuvWaypointMobilityModel);
25
26
27
TypeId
28
AuvWaypointMobilityModel::GetTypeId (void)
29
{
30
  static TypeId tid = TypeId ("ns3::AuvWaypointMobilityModel")
31
    .SetParent<WaypointMobilityModel> ()
32
    .SetGroupName ("AUV")
33
    .AddConstructor<AuvWaypointMobilityModel> ()
34
    .AddAttribute ("ValidatorMobilityModel", "The MobilityModel going to be used for the position's validation, must be a constant velocity model",
35
                   PointerValue (),
36
                   MakePointerAccessor (&AuvWaypointMobilityModel::m_auvMobilityModel),
37
                   MakePointerChecker<ConstantVelocityMobilityModel> ())
38
39
  ;
40
  return tid;
41
}
42
43
44
AuvWaypointMobilityModel::AuvWaypointMobilityModel ()
45
  : m_lazyNotify (false),
46
  m_initialPositionIsWaypoint (true),
47
  m_auvMobilityModel (NULL),
48
  m_energyDepleted (false),
49
  m_lastUpdate (Seconds (-1)),
50
  m_callbackDone (false)
51
{
52
  m_waypointReachedCallback.Nullify ();
53
}
54
55
56
AuvWaypointMobilityModel::~AuvWaypointMobilityModel ()
57
{
58
  m_auvMobilityModel = NULL;
59
  m_waypointReachedCallback.Nullify ();
60
}
61
62
void
63
AuvWaypointMobilityModel::SetValidatorMobilityModel (Ptr<AuvMobilityModel> auvMobilityModel)
64
{
65
  m_auvMobilityModel = auvMobilityModel;
66
}
67
68
Ptr<AuvMobilityModel>
69
AuvWaypointMobilityModel::GetValidatorMobilityModel (void) const
70
{
71
  return m_auvMobilityModel;
72
}
73
74
void
75
AuvWaypointMobilityModel::DoDispose (void)
76
{
77
  MobilityModel::DoDispose ();
78
}
79
80
void
81
AuvWaypointMobilityModel::Update (void) const
82
{
83
  const Time now = Simulator::Now ();
84
  bool newWaypoint = false;
85
86
  if ( now == m_lastUpdate )
87
    {
88
      return;
89
    }
90
91
  if ( now < m_current.time )
92
    {
93
      return;
94
    }
95
96
  while ( now >= m_next.time  )
97
    {
98
99
      if ( m_waypoints.empty () &&  m_waypointReachedCallback.IsNull () )
100
        {
101
          if ( m_current.time <= m_next.time )
102
            {
103
              /*
104
                Set m_next.time = -1 to make sure this doesn't happen more than once.
105
                The comparison here still needs to be '<=' in the case of mobility with one waypoint.
106
              */
107
              m_next.time = Seconds (-1.0);
108
              m_current.position = m_next.position;
109
              m_current.time = now;
110
              m_velocity = Vector (0,0,0);
111
              m_auvMobilityModel->SetVelocity (m_velocity);
112
              NotifyCourseChange ();
113
            }
114
          else
115
            {
116
              m_current.time = now;
117
            }
118
          return;
119
        }
120
121
      if ( m_energyDepleted )
122
        {
123
          return;
124
        }
125
126
      if ( !m_waypoints.empty () )
127
        {
128
          m_current = m_next;
129
          m_next = m_waypoints.front ();
130
          m_waypoints.pop_front ();
131
          newWaypoint = true;
132
        }
133
134
      const double t_span = (m_next.time - m_current.time).GetSeconds ();
135
136
      if (t_span > 0)
137
        {
138
          m_velocity.x = (m_next.position.x - m_current.position.x) / t_span;
139
          m_velocity.y = (m_next.position.y - m_current.position.y) / t_span;
140
          m_velocity.z = (m_next.position.z - m_current.position.z) / t_span;
141
        }
142
      else
143
        {
144
          m_velocity = Vector (0,0,0);
145
        }
146
147
      m_auvMobilityModel->SetVelocity (m_velocity);
148
149
      if ( now > m_lastUpdate )
150
        {
151
          m_callbackDone = false;
152
        }
153
      m_lastUpdate = now;
154
      if ( !m_waypointReachedCallback.IsNull ()  && (!m_callbackDone) )
155
        {
156
          m_callbackDone = true;
157
          // if the callback causes a call to AddWaypoint()
158
          // this will prevent it from overriding m_current and m_next
159
          bool waypointsEmpty = m_waypoints.empty ();
160
          if (waypointsEmpty)
161
            {
162
              m_waypoints.push_back (Waypoint (Seconds (0), Vector (0,0,0)));
163
            }
164
          m_waypointReachedCallback ();
165
          if (waypointsEmpty)
166
            {
167
              m_waypoints.pop_front ();
168
            }
169
        }
170
      if ( m_waypoints.empty () && !m_waypointReachedCallback.IsNull () )
171
        {
172
          break;
173
        }
174
    }
175
176
  if ( now > m_current.time ) // Won't ever be less, but may be equal
177
    {
178
      const double t_diff = (now - m_current.time).GetSeconds ();
179
      m_current.position.x += m_velocity.x * t_diff;
180
      m_current.position.y += m_velocity.y * t_diff;
181
      m_current.position.z += m_velocity.z * t_diff;
182
      m_current.time = now;
183
    }
184
185
  if ( newWaypoint )
186
    {
187
      NotifyCourseChange ();
188
    }
189
190
  else if ( !m_waypointReachedCallback.IsNull () && m_current.time == m_next.time )
191
    {
192
      m_velocity = Vector (0,0,0);
193
      m_auvMobilityModel->SetVelocity (m_velocity);
194
      NotifyCourseChange ();
195
    }
196
}
197
198
void
199
AuvWaypointMobilityModel::DoSetPosition (const Vector &position)
200
{
201
  const Time now = Simulator::Now ();
202
203
  if ( m_initialPositionIsWaypoint )
204
    {
205
      AddWaypoint (Waypoint (now, position));
206
      return;
207
    }
208
209
  Update ();
210
  m_current.time = std::max (now, m_next.time);
211
  m_current.position = position;
212
  m_velocity = Vector (0,0,0);
213
  m_auvMobilityModel->SetVelocity (m_velocity);
214
215
  if ( now >= m_current.time )
216
    {
217
      // This is only a course change if the node is actually moving
218
      NotifyCourseChange ();
219
    }
220
}
221
222
Vector
223
AuvWaypointMobilityModel::DoGetPosition (void) const
224
{
225
  AuvWaypointMobilityModel::Update ();
226
  return m_current.position;
227
}
228
229
230
void
231
AuvWaypointMobilityModel::AddWaypoint (const Waypoint &waypoint)
232
{
233
  NS_ABORT_MSG_IF ((Simulator::Now () <= waypoint.time) && waypoint.time < Seconds (0),
234
                   "Waypoint time should be in the future");
235
  NS_ABORT_MSG_IF ( !m_waypoints.empty () && (m_waypoints.back ().time >= waypoint.time),
236
                    "Waypoints must be added in ascending time order");
237
238
  if (m_waypoints.empty ())
239
    {
240
      m_current = m_next = waypoint;
241
    }
242
  m_waypoints.push_back (waypoint);
243
  if ( !m_lazyNotify )
244
    {
245
      Simulator::Schedule (waypoint.time - Simulator::Now (), &AuvWaypointMobilityModel::Update, this);
246
    }
247
}
248
249
250
void
251
AuvWaypointMobilityModel::SetWaypointReachedCallback (WaypointReachedCallback callback)
252
{
253
  NS_LOG_FUNCTION (this);
254
  if (callback.IsNull ())
255
    {
256
      NS_LOG_DEBUG ("AuvWaypointMobilityModel:Setting NULL waypoint reached callback!");
257
    }
258
  m_waypointReachedCallback = callback;
259
}
260
261
void
262
AuvWaypointMobilityModel::HandleEnergyDepletion ()
263
{
264
  m_energyDepleted = true;
265
  m_waypoints.clear ();
266
  m_current.time = Simulator::Now ();
267
  m_next = m_current;
268
  m_velocity = Vector (0,0,0);
269
  m_auvMobilityModel->SetVelocity (m_velocity);
270
  NotifyCourseChange ();
271
}
272
273
void
274
AuvWaypointMobilityModel::HandleEnergyRecharged ()
275
{
276
  m_energyDepleted = false;
277
}
278
279
} // namespace ns3
280
(-)a/src/auv/model/auv-waypoint-mobility-model.h (+105 lines)
Line 0    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: Andrea Sacco <andrea.sacco85@gmail.com>
17
 */
18
19
#ifndef AUV_WAYPOINT_MOBILITY_MODEL_H
20
#define AUV_WAYPOINT_MOBILITY_MODEL_H
21
22
#include "ns3/log.h"
23
#include "ns3/abort.h"
24
#include "ns3/simulator.h"
25
#include "ns3/pointer.h"
26
#include "ns3/auv-mobility-model.h"
27
#include "ns3/waypoint-mobility-model.h"
28
29
namespace ns3 {
30
31
/**
32
 * \ingroup auv
33
 *
34
 *
35
 */
36
37
38
class AuvWaypointMobilityModel : public WaypointMobilityModel
39
{
40
public:
41
  typedef Callback<void> WaypointReachedCallback;
42
43
  /**
44
   * Register this type with the TypeId system.
45
   * \return the object TypeId
46
   */
47
  static TypeId GetTypeId (void);
48
49
  /**
50
   * Create a path with no waypoints at location (0,0,0).
51
   */
52
  AuvWaypointMobilityModel ();
53
  virtual ~AuvWaypointMobilityModel ();
54
55
  /**
56
  * \param model mobility model to be used as waypoint validator
57
  */
58
  void SetValidatorMobilityModel (Ptr<AuvMobilityModel> auvMobilityModel);
59
60
  /**
61
   * \return the underlying mobility model
62
   */
63
  Ptr<AuvMobilityModel> GetValidatorMobilityModel (void) const;
64
65
  /**
66
   * \param waypoint waypoint to append to the object path.
67
   *
68
   * Add a waypoint to the path of the object. The time must
69
   * be greater than the previous waypoint added, otherwise
70
   * a fatal error occurs. The first waypoint is set as the
71
   * current position with a velocity of zero.
72
   *
73
   */
74
  void AddWaypoint (const Waypoint &waypoint);
75
76
  void SetWaypointReachedCallback (WaypointReachedCallback callback);
77
78
  void HandleEnergyDepletion ();
79
  void HandleEnergyRecharged ();
80
81
private:
82
  void Update (void) const;
83
  virtual void DoSetPosition (const Vector &position);
84
  virtual Vector DoGetPosition (void) const;
85
  virtual void DoDispose (void);
86
  bool m_lazyNotify;
87
  mutable Waypoint m_current;
88
  mutable Vector m_velocity;
89
  mutable Waypoint m_next;
90
  bool m_initialPositionIsWaypoint;
91
  mutable std::deque<Waypoint> m_waypoints;
92
  Ptr<AuvMobilityModel> m_auvMobilityModel;
93
  WaypointReachedCallback m_waypointReachedCallback;
94
  bool m_energyDepleted;
95
  mutable Time m_lastUpdate;
96
  mutable bool m_callbackDone;
97
98
99
100
};
101
102
} // namespace ns3
103
104
#endif /* AUV_WAYPOINT_MOBILITY_MODEL_H */
105
(-)a/src/auv/model/glider-energy-model.cc (+217 lines)
Line 0    Link Here 
1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2010 Andrea Sacco
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: Andrea Sacco <andrea.sacco85@gmail.com>
19
 */
20
#include "glider-energy-model.h"
21
22
NS_LOG_COMPONENT_DEFINE ("GliderEnergyModel");
23
24
namespace ns3 {
25
26
NS_OBJECT_ENSURE_REGISTERED (GliderEnergyModel);
27
28
TypeId
29
GliderEnergyModel::GetTypeId (void)
30
{
31
  static TypeId tid = TypeId ("ns3::GliderEnergyModel")
32
    .SetParent<DeviceEnergyModel> ()
33
    .AddConstructor<GliderEnergyModel> ()
34
    .AddTraceSource ("TotalEnergyConsumption",
35
                     "Total energy consumption of the glider AUV.",
36
                     MakeTraceSourceAccessor (&GliderEnergyModel::m_totalEnergyConsumption),
37
                     "ns3::TracedValueCallback::Double")
38
  ;
39
  return tid;
40
}
41
42
GliderEnergyModel::GliderEnergyModel ()
43
{
44
  NS_LOG_FUNCTION (this);
45
  m_currentBuoyancy = 0.0;
46
  m_currentW = 0.0;
47
  m_actualCurrentDrain = 0.0;
48
  m_lastUpdateTime = Seconds (0.0);
49
  m_energyDepletionCallback.Nullify ();
50
  m_energyRechargedCallback.Nullify ();
51
  m_node = NULL;
52
  m_source = NULL;
53
}
54
55
GliderEnergyModel::~GliderEnergyModel ()
56
{
57
  m_energyDepletionCallback.Nullify ();
58
  m_energyRechargedCallback.Nullify ();
59
  m_node = NULL;
60
  m_source = NULL;
61
}
62
63
void
64
GliderEnergyModel::SetNode (Ptr<Node> node)
65
{
66
  NS_LOG_FUNCTION (this << node);
67
  NS_ASSERT (node != NULL);
68
  m_node = node;
69
}
70
71
Ptr<Node>
72
GliderEnergyModel::GetNode (void) const
73
{
74
  return m_node;
75
}
76
77
void
78
GliderEnergyModel::SetEnergySource (Ptr<EnergySource> source)
79
{
80
  NS_LOG_FUNCTION (this << source);
81
  NS_ASSERT (source != NULL);
82
  m_source = source;
83
}
84
85
double
86
GliderEnergyModel::GetTotalEnergyConsumption (void) const
87
{
88
  NS_LOG_FUNCTION (this);
89
90
  Time duration = Simulator::Now () - m_lastUpdateTime;
91
  double power = GetPower (m_currentBuoyancy, m_currentW);
92
  double energyToDecrease = duration.GetSeconds () * power;
93
94
  return m_totalEnergyConsumption + energyToDecrease;
95
}
96
97
void
98
GliderEnergyModel::ChangeState (int newState)
99
{
100
  NS_FATAL_ERROR ("ChangeState not implemented, use ChangeEnergyConsumption instead.");
101
}
102
103
void
104
GliderEnergyModel::ChangeEnergyConsumption (const double buoyancy, const double W)
105
{
106
  NS_LOG_FUNCTION (this << buoyancy << W);
107
108
  Time duration = Simulator::Now () - m_lastUpdateTime;
109
  NS_ASSERT (duration.GetNanoSeconds () >= 0); // check if duration is valid
110
111
  // update remaining energy accordingly
112
  double power = GetPower (m_currentBuoyancy, m_currentW);
113
  double energyToDecrease = duration.GetSeconds () * power;
114
115
  // update total energy consumption
116
  m_totalEnergyConsumption += energyToDecrease;
117
118
  // update current buoyancy
119
  m_currentBuoyancy = buoyancy;
120
  // update current vertical speed
121
  m_currentW = W;
122
  // update current drain
123
  power = GetPower (m_currentBuoyancy, m_currentW);
124
  double supplyVoltage = m_source->GetSupplyVoltage ();
125
  m_actualCurrentDrain = power / supplyVoltage;
126
127
  // update last update time stamp
128
  m_lastUpdateTime = Simulator::Now ();
129
130
  // notify energy source
131
  m_source->UpdateEnergySource ();
132
133
  // some debug message
134
  NS_LOG_DEBUG ("GliderEnergyModel:Total energy consumption at node #" <<
135
                m_node->GetId () << " is " << m_totalEnergyConsumption << "J");
136
}
137
138
void
139
GliderEnergyModel::SetEnergyDepletionCallback (GliderEnergyDepletionCallback callback)
140
{
141
  NS_LOG_FUNCTION (this);
142
  if (callback.IsNull ())
143
    {
144
      NS_LOG_DEBUG ("GliderEnergyModel:Setting NULL energy depletion callback!");
145
    }
146
  m_energyDepletionCallback = callback;
147
}
148
149
void
150
GliderEnergyModel::SetEnergyRechargedCallback (GliderEnergyRechargedCallback callback)
151
{
152
  NS_LOG_FUNCTION (this);
153
  if (callback.IsNull ())
154
    {
155
      NS_LOG_DEBUG ("GliderEnergyModel:Setting NULL energy recharged callback!");
156
    }
157
  m_energyRechargedCallback = callback;
158
}
159
160
void
161
GliderEnergyModel::HandleEnergyDepletion (void)
162
{
163
  NS_LOG_FUNCTION (this);
164
  NS_LOG_DEBUG ("GliderEnergyModel:Energy is depleted at node #" <<
165
                m_node->GetId ());
166
167
  // invoke energy depletion callback, if set.
168
  if (!m_energyDepletionCallback.IsNull ())
169
    {
170
      m_energyDepletionCallback ();
171
    }
172
}
173
174
void
175
GliderEnergyModel::HandleEnergyRecharged (void)
176
{
177
  NS_LOG_FUNCTION (this);
178
  NS_LOG_DEBUG ("GliderEnergyModel:Energy is recharged at node #" <<
179
                m_node->GetId ());
180
181
  if (!m_energyRechargedCallback.IsNull ())
182
    {
183
      m_energyRechargedCallback ();
184
    }
185
}
186
/*
187
 * Private functions start here.
188
 */
189
190
void
191
GliderEnergyModel::DoDispose (void)
192
{
193
  NS_LOG_FUNCTION (this);
194
  m_node = NULL;
195
  m_source = NULL;
196
  m_energyDepletionCallback.Nullify ();
197
}
198
199
double
200
GliderEnergyModel::DoGetCurrentA (void) const
201
{
202
  NS_LOG_FUNCTION (this);
203
204
  return m_actualCurrentDrain;
205
}
206
207
double
208
GliderEnergyModel::GetPower (double buoyancy, double W) const
209
{
210
  // power needed to get the buoyancy, in watts
211
  double power = buoyancy / 100 * W;
212
213
  return power;
214
}
215
216
} // namespace ns3
217
(-)a/src/auv/model/glider-energy-model.h (+184 lines)
Line 0    Link Here 
1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2010 Andrea Sacco
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: Andrea Sacco <andrea.sacco85@gmail.com>
19
 */
20
21
#ifndef GLIDER_ENERGY_MODEL_H
22
#define GLIDER_ENERGY_MODEL_H
23
24
#include "ns3/device-energy-model.h"
25
#include "ns3/energy-source.h"
26
#include "ns3/traced-value.h"
27
#include "ns3/log.h"
28
#include "ns3/simulator.h"
29
30
31
namespace ns3 {
32
33
/**
34
 * \ingroup auv
35
 * \brief Keeps track of the Seaglider's energy consumption
36
 *
37
 * Implement the DeviceEnergyModel interface for the Seaglider
38
 * AUV. The energy consumption is calculated with the product of
39
 * buoyancy with vertical speed [1].
40
 *
41
 * This model should be used in conjunction with the GliderMobilityModel.
42
 * The mobility model, in fact, on every course change, updates the
43
 * energy consumption with the new buoyancy/speed values.
44
 *
45
 * References:
46
 *
47
 * [1] Eriksen et al, "Seaglider: A Long-Range Autonomous Underwater Vehicle for Oceanographic Research"
48
 *     URL: http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=972073&userType=inst
49
 */
50
class GliderEnergyModel : public DeviceEnergyModel
51
{
52
public:
53
  // / Callback type for energy depletion handling.
54
  typedef Callback<void> GliderEnergyDepletionCallback;
55
  typedef Callback<void> GliderEnergyRechargedCallback;
56
57
public:
58
  static TypeId GetTypeId (void);
59
  GliderEnergyModel ();
60
  virtual ~GliderEnergyModel ();
61
62
  /**
63
   * \brief Sets pointer to node.
64
   *
65
   * \param node Pointer to node.
66
   *
67
   * Implements DeviceEnergyModel::SetNode.
68
   */
69
  virtual void SetNode (Ptr<Node> node);
70
71
  /**
72
   * \brief Gets pointer to node.
73
   *
74
   * \returns Pointer to node.
75
   *
76
   * Implements DeviceEnergyModel::GetNode.
77
   */
78
  virtual Ptr<Node> GetNode (void) const;
79
80
  /**
81
   * \brief Sets pointer to EnergySouce installed on node.
82
   *
83
   * \param source Pointer to EnergySource installed on node.
84
   *
85
   * Implements DeviceEnergyModel::SetEnergySource.
86
   */
87
  virtual void SetEnergySource (Ptr<EnergySource> source);
88
89
  /**
90
   * \returns Total energy consumption of the vehicle.
91
   *
92
   * Implements DeviceEnergyModel::GetTotalEnergyConsumption.
93
   */
94
  virtual double GetTotalEnergyConsumption (void) const;
95
96
  /**
97
   * \param newState New state the device is in.
98
   *
99
   * DeviceEnergyModel is a state based model. This function is implemented by
100
   * all child of DeviceEnergyModel to change the model's state. States are to
101
   * be defined by each child using an enum (int).
102
   */
103
  virtual void ChangeState (int newState);
104
105
  /**
106
   * \param buoyancy buoyancy value in grams
107
   * \param W vertical speed value in m/s
108
   *
109
   * Update the energy consumption according to the buoyancy value and vertical
110
   * speed value.
111
   */
112
  void ChangeEnergyConsumption (const double buoyancy, const double W);
113
114
  /**
115
   * \param callback Callback function.
116
   *
117
   * Sets callback for energy depletion handling.
118
   */
119
  void SetEnergyDepletionCallback (GliderEnergyDepletionCallback callback);
120
121
  /**
122
   * \param callback Callback function.
123
   *
124
   * Sets callback for energy recharged handling.
125
   */
126
  void SetEnergyRechargedCallback (GliderEnergyRechargedCallback callback);
127
128
  /**
129
   * \brief Handles energy depletion.
130
   *
131
   * Implements DeviceEnergyModel::HandleEnergyDepletion
132
   */
133
  virtual void HandleEnergyDepletion (void);
134
135
  /**
136
   * \brief Handles energy recharge.
137
   *
138
   * Implements DeviceEnergyModel::HandleEnergyRecharged
139
   */
140
  virtual void HandleEnergyRecharged (void);
141
142
private:
143
  void DoDispose (void);
144
145
  /**
146
   * \returns Current draw of device, at current state.
147
   *
148
   * Implements DeviceEnergyModel::GetCurrentA.
149
   */
150
  virtual double DoGetCurrentA (void) const;
151
152
  /**
153
   * \param buoyancy the buoyancy value in grams
154
   * \param W the vertical speed in m/s
155
   * \return the needed power in watts
156
   *
157
   * This get the power needed to maintain a given buoyancy and vertical speed
158
   */
159
  double GetPower (double buoyancy, double W) const;
160
161
private:
162
  Ptr<Node> m_node;
163
  Ptr<EnergySource> m_source;
164
165
  // This variable keeps track of the total energy consumed by this particular model.
166
  TracedValue<double> m_totalEnergyConsumption;
167
168
  // actual current drain
169
  double m_actualCurrentDrain;
170
  // current buoyancy value in grams
171
  double m_currentBuoyancy;
172
  // current vertical speed value in m/s
173
  double m_currentW;
174
  // time stamp of previous energy update
175
  Time m_lastUpdateTime;
176
177
  // energy depletion callback
178
  GliderEnergyDepletionCallback m_energyDepletionCallback;
179
  GliderEnergyRechargedCallback m_energyRechargedCallback;
180
};
181
182
} // namespace ns3
183
184
#endif /* GLIDER_ENERGY_MODEL_H */
(-)a/src/auv/model/glider-mobility-model.cc (+470 lines)
Line 0    Link Here 
1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2010 Andrea Sacco
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: Andrea Sacco <andrea.sacco85@gmail.com>
19
 */
20
#include "glider-mobility-model.h"
21
22
namespace ns3 {
23
24
NS_LOG_COMPONENT_DEFINE ("GliderMobilityModel");
25
26
NS_OBJECT_ENSURE_REGISTERED (GliderMobilityModel);
27
28
TypeId
29
GliderMobilityModel::GetTypeId (void)
30
{
31
  static TypeId tid = TypeId ("ns3::GliderMobilityModel")
32
    .SetParent (AuvMobilityModel::GetTypeId ())
33
    .AddConstructor<GliderMobilityModel> ()
34
    .AddAttribute ("MaxDepth", "The maximum operational depth, in m",
35
                   DoubleValue (-1000.0),
36
                   MakeDoubleAccessor (&GliderMobilityModel::m_maxDepth),
37
                   MakeDoubleChecker<double> ())
38
    .AddAttribute ("MinGlideAngle", "The minimum glide angle of the glider, in degrees.",
39
                   DoubleValue (14.0), // correspond to a 1/4 glide angle
40
                   MakeDoubleAccessor (&GliderMobilityModel::m_minGlideAngle),
41
                   MakeDoubleChecker<double> ())
42
    .AddAttribute ("MaxGlideAngle", "The maximum glide angle of the glider, in degrees.",
43
                   DoubleValue (68.2), // correspond to a 5/2 glide angle, derived from the paper
44
                   MakeDoubleAccessor (&GliderMobilityModel::m_maxGlideAngle),
45
                   MakeDoubleChecker<double> ())
46
//    .AddAttribute ("MaxHSpeed", "The maximum horizontal speed of the glider, in m/s.",
47
//                   DoubleValue (0.32), // derived from the paper
48
//                   MakeDoubleAccessor (&GliderMobilityModel::m_maxU),
49
//                   MakeDoubleChecker<double> ())
50
    .AddAttribute ("MaxWSpeed", "The maximum vertical speed of the glider, in m/s.",
51
                   DoubleValue (0.5), // derived from the paper
52
                   MakeDoubleAccessor (&GliderMobilityModel::m_maxW),
53
                   MakeDoubleChecker<double> ())
54
    .AddAttribute ("MaxBuoyancy", "The maximum buoyancy supported by the glider buoyancy control system, in grammes",
55
                   DoubleValue (200), // derived from the paper
56
                   MakeDoubleAccessor (&GliderMobilityModel::m_maxBuoyancy),
57
                   MakeDoubleChecker<double> ())
58
  ;
59
  return tid;
60
}
61
62
GliderMobilityModel::GliderMobilityModel ()
63
  : m_direction (0),
64
  m_speed (0),
65
  m_pitch (0),
66
  m_depth (0),
67
  m_deployed (false),
68
  m_node (NULL)
69
{
70
  m_emergeCb.Nullify ();
71
  m_submergeCb.Nullify ();
72
}
73
74
GliderMobilityModel::~GliderMobilityModel ()
75
{
76
  m_emergeCb.Nullify ();
77
  m_submergeCb.Nullify ();
78
  m_node = NULL;
79
}
80
81
Vector
82
GliderMobilityModel::RoundPosition (const Vector &pos, uint16_t decimals) const
83
{
84
  Vector roundPos;
85
86
  double off = std::pow (10, decimals);
87
  roundPos.x = (std::floor ((pos.x * off) + 0.5)) / off;
88
  roundPos.y = (std::floor ((pos.y * off) + 0.5)) / off;
89
  roundPos.z = (std::floor ((pos.z * off) + 0.5)) / off;
90
91
  return roundPos;
92
}
93
94
double
95
GliderMobilityModel::GetBuoyancy (void) const
96
{
97
  return m_buoyancy;
98
}
99
100
void
101
GliderMobilityModel::SetNode (const Ptr<Node> node)
102
{
103
  NS_ASSERT (node != NULL);
104
  m_node = node;
105
}
106
107
Ptr<Node>
108
GliderMobilityModel::GetNode (void) const
109
{
110
  return m_node;
111
}
112
113
void
114
GliderMobilityModel::SetEmergeCallback (Callback<void, Ptr<MobilityModel> > cb)
115
{
116
  m_emergeCb = cb;
117
}
118
119
void
120
GliderMobilityModel::SetSubmergeCallback (Callback<void, Ptr<MobilityModel> > cb)
121
{
122
  m_submergeCb = cb;
123
}
124
125
Vector
126
GliderMobilityModel::DoGetPosition (void) const
127
{
128
  m_helper.Update ();
129
130
  // get the current position
131
  Vector pos = m_helper.GetCurrentPosition ();
132
133
  // get the rounded precision position
134
  Vector rpos = RoundPosition (pos, 4);
135
136
  return rpos;
137
}
138
139
void
140
GliderMobilityModel::DoSetPosition (const Vector &position)
141
{
142
  NS_ASSERT (!m_deployed);
143
144
  m_helper.SetPosition (position);
145
}
146
147
Vector
148
GliderMobilityModel::DoGetVelocity (void) const
149
{
150
  return m_helper.GetVelocity ();
151
}
152
153
void
154
GliderMobilityModel::DoSetVelocity (const Vector &velocity)
155
{
156
  // if velocity is 0
157
  if (CalculateDistance (velocity,Vector (0, 0, 0)) == 0)
158
    {
159
      // stop the vehicle
160
      DoStop ();
161
162
      return;
163
    }
164
165
  // get the total speed magnitude
166
  double speed = std::sqrt ((velocity.x * velocity.x) +
167
                            (velocity.y * velocity.y) +
168
                            (velocity.z * velocity.z));
169
170
  // calculate the pitch
171
  double pitch = std::asin ((velocity.z / speed));
172
173
  NS_ASSERT (std::abs (pitch * 180 / M_PI) <= m_maxGlideAngle);
174
175
  // get horizontal and vertical speeds
176
  double u = speed * std::cos (pitch);
177
  double w = speed * std::sin (pitch);
178
  // get the required buoyancy for the given speed
179
  double buoyancy = GetBuoyancy (std::abs (u), std::abs (w));
180
181
  NS_ASSERT (buoyancy <= m_maxBuoyancy);
182
  m_buoyancy = buoyancy;
183
  m_speed = speed;
184
  m_pitch = pitch;
185
186
  // get the direction
187
  double dir = std::atan2 (velocity.y, velocity.x);
188
  m_direction = dir;
189
190
  m_helper.SetVelocity (velocity);
191
192
  Move ();
193
}
194
195
void
196
GliderMobilityModel::UpdatePowerConsumption (double buoyancy, double W)
197
{
198
  Ptr<EnergySourceContainer> source = m_node->GetObject<EnergySourceContainer> ();
199
  if (source != NULL)
200
    {
201
      // retrieve device energy model from energy source
202
      DeviceEnergyModelContainer modelCont;
203
      for (EnergySourceContainer::Iterator it = source->Begin (); it != source->End (); it++)
204
        {
205
          Ptr<EnergySource> source = *it;
206
207
          modelCont = source->FindDeviceEnergyModels ("ns3::GliderEnergyModel");
208
          if (modelCont.GetN () != 0)
209
            {
210
              break;
211
            }
212
        }
213
      NS_ASSERT (modelCont.GetN () != 0);
214
215
      // get pointer
216
      Ptr<GliderEnergyModel> devModel = DynamicCast<GliderEnergyModel> (modelCont.Get (0));
217
      devModel->ChangeEnergyConsumption (buoyancy, std::abs (W));
218
    }
219
}
220
221
void
222
GliderMobilityModel::Update (void)
223
{
224
  // get the vector components
225
  double cosD = std::cos (m_direction);
226
  double cosP = std::cos (m_pitch);
227
  double sinD = std::sin (m_direction);
228
  double sinP = std::sin (m_pitch);
229
230
  // set the velocity vector
231
  m_helper.SetVelocity (Vector (m_speed * cosD * cosP,
232
                                m_speed * sinD * cosP,
233
                                m_speed * sinP));
234
235
  // update buoyancy
236
  m_buoyancy = GetBuoyancy (std::abs (m_speed * cosP),
237
                            std::abs (m_speed * sinP));
238
239
  // update depth
240
  m_depth = GetDepth ();
241
242
  // update the helper
243
  m_helper.Update ();
244
245
  // notify the change
246
  NotifyCourseChange ();
247
}
248
249
void
250
GliderMobilityModel::DoMove (void)
251
{
252
  if (!m_deployed)
253
    {
254
      // the vehicle has just been deployed
255
      m_deployed = true;
256
    }
257
258
  // unpause the helper
259
  m_helper.Unpause ();
260
261
  // update the helper with the new nav params
262
  Update ();
263
264
  // update the energy consumption
265
  UpdatePowerConsumption (m_buoyancy, std::abs (m_speed * std::sin (m_pitch)));
266
267
  // compute the necessary time to reach the maximum operative depth
268
  // or water surface and set a stop event
269
  double vertVel = m_helper.GetVelocity ().z;
270
271
  if (vertVel != 0)
272
    {
273
      double stopTime = 0;
274
      if (vertVel < 0)
275
        {
276
          stopTime = (m_maxDepth - DoGetDepth ()) / vertVel;
277
        }
278
      else
279
        {
280
          stopTime = (0 - DoGetDepth ()) / vertVel;
281
        }
282
283
      Simulator::Cancel (m_stop);
284
      m_stop = Simulator::Schedule (Seconds (stopTime),
285
                                    &GliderMobilityModel::Stop,
286
                                    this);
287
    }
288
}
289
290
void
291
GliderMobilityModel::DoStop (void)
292
{
293
  // Update ();
294
  m_helper.Update ();
295
296
  // now the vehicle is stopped
297
  m_speed = 0;
298
  m_buoyancy = 0;
299
300
  // update the energy consumption
301
  UpdatePowerConsumption (m_buoyancy, 0);
302
303
  Simulator::Cancel (m_stop);
304
  m_helper.Pause ();
305
}
306
307
void
308
GliderMobilityModel::DoEmerge (double depth)
309
{
310
  NS_ASSERT (depth <= 0 && depth >= m_maxDepth);
311
312
  double deltaDepth = depth - GetDepth ();
313
314
  // we want to emerge so the delta depth must be positive
315
  NS_ASSERT (deltaDepth > 0);
316
  // set the maximum pitch value
317
  SetPitch (m_maxGlideAngle);
318
  // set the maximum speed value
319
  // from the paper, the vertical speed seems to not go over 0.15 m/s
320
  // even if there are "outlayers" at 0.5 m/s
321
  SetSpeed (m_maxW / std::sin (m_pitch));
322
323
  // compute the time needed to reach to the specified depth
324
  double emergeTime = deltaDepth / m_maxW;
325
326
  // set an event to stop the vehicle when it have reached the specified depth
327
  m_stop = Simulator::Schedule (Seconds (emergeTime),
328
                                &GliderMobilityModel::DoStop,
329
                                this);
330
331
  if (!m_emergeCb.IsNull ())
332
    {
333
      // schedule the call to the emerge callback
334
      Simulator::Schedule (Seconds (emergeTime),
335
                           &GliderMobilityModel::m_emergeCb,
336
                           this,
337
                           this);
338
    }
339
}
340
341
void
342
GliderMobilityModel::DoSubmerge (double depth)
343
{
344
  NS_ASSERT (depth >= m_maxDepth && depth <= 0);
345
346
  double deltaDepth = depth - GetDepth ();
347
348
  // we want to submerge so the delta depth must be negative
349
  NS_ASSERT (deltaDepth < 0);
350
  // set the maximum pitch value
351
  SetPitch (-m_maxGlideAngle);
352
  // set the maximum speed value
353
  SetSpeed (-m_maxW / std::sin (m_pitch));
354
355
  // compute the time needed to reach to the specified depth
356
  double submergeTime = deltaDepth / -m_maxW;
357
  // set an event to stop the vehicle when it have reached the specified depth
358
  m_stop = Simulator::Schedule (Seconds (submergeTime),
359
                                &GliderMobilityModel::DoStop,
360
                                this);
361
362
  if (!m_submergeCb.IsNull ())
363
    {
364
      // schedule the call to the submerge callback
365
      Simulator::Schedule (Seconds (submergeTime),
366
                           &GliderMobilityModel::m_submergeCb,
367
                           this,
368
                           this);
369
    }
370
}
371
372
double
373
GliderMobilityModel::DoGetPitch () const
374
{
375
  return m_pitch * 180 / M_PI;
376
}
377
378
void
379
GliderMobilityModel::DoSetPitch (double pitch)
380
{
381
  // actually sets the glide angle
382
  NS_ASSERT_MSG (std::abs (pitch) <= m_maxGlideAngle,
383
                 "An excessive glide angle has been set");
384
385
  NS_ASSERT_MSG (std::abs (pitch) >= m_minGlideAngle,
386
                 "An insufficient glide angle has been set");
387
388
  // the pitch angle is stored in radians
389
  m_pitch = pitch * M_PI / 180;
390
391
  Update ();
392
}
393
394
double
395
GliderMobilityModel::DoGetDepth (void)
396
{
397
  // update the current depth
398
  Vector pos = GetPosition ();
399
  m_depth = pos.z;
400
401
  return m_depth;
402
}
403
404
double
405
GliderMobilityModel::DoGetDirection (void) const
406
{
407
  return m_direction * 180 / M_PI;
408
}
409
410
void
411
GliderMobilityModel::DoSetDirection (double dir)
412
{
413
  m_direction = dir * M_PI / 180;
414
415
  Update ();
416
}
417
418
double
419
GliderMobilityModel::DoGetSpeed () const
420
{
421
  return m_speed;
422
}
423
424
void
425
GliderMobilityModel::DoSetSpeed (double speed)
426
{
427
  NS_ASSERT ((float) speed <= (float) m_maxW / std::sin (m_maxGlideAngle * M_PI / 180));
428
429
  m_speed = speed;
430
431
  Update ();
432
  Move ();
433
}
434
435
double
436
GliderMobilityModel::GetBuoyancy (double U, double W) const
437
{
438
  // here we get the bouyancy needed to mantain
439
  // the given velocity at the given glide anlge
440
  double a = 0.0022436;
441
  double b = 0.01249;
442
  double c = 9.8016e-6;
443
  // v^2=U^2+W^2
444
  double v = std::sqrt (U * U + W * W);
445
  // water density kg/m^3
446
  double rho = 1023;
447
  // dynamic pressure
448
  double q = 0.5 * rho * (v * v);
449
  // seaglider hull length, in m
450
  double l = 1.8;
451
452
  double tgteta = W / U;
453
  double teta = std::atan (tgteta);
454
455
  double lambda = (a * a) / (b * (1 / std::pow (q, 0.25)) * c);
456
457
  double temp = (q * (l * l) * (a * a) * std::sin (teta)) /
458
    (2 * c * (std::cos (teta) * std::cos (teta)));
459
460
  // positive sqrt solution for Buoyancy
461
  // double Bp = temp*(1 + std::sqrt(1 - 4/(lambda*(tgteta * tgteta))));
462
  // negative sqrt solution for Buoyancy
463
  double Bn = temp * (1 - std::sqrt (1 - 4 / (lambda * (tgteta * tgteta))));
464
465
  // the negative solution is returned, as the more efficient, as said into the article
466
  // TODO discrepancies with paper values
467
  return Bn * 100;
468
}
469
470
} // namespace ns3
(-)a/src/auv/model/glider-mobility-model.h (+133 lines)
Line 0    Link Here 
1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2010 Andrea Sacco
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: Andrea Sacco <andrea.sacco85@gmail.com>
19
 */
20
21
#ifndef GLIDER_MOBILITY_MODEL_H_
22
#define GLIDER_MOBILITY_MODEL_H_
23
24
#include "auv-mobility-model.h"
25
#include "ns3/event-id.h"
26
#include "ns3/glider-energy-model.h"
27
28
namespace ns3 {
29
30
/**
31
 * \ingroup auv
32
 * \brief keep track of the position of a Seaglider AUV
33
 *
34
 * The model is based on the constant velocity mobility model but introduces the physical
35
 * constraints characteristics of the Seaglider AUV:
36
 *
37
 * - maximum operational depth, 1000 m
38
 * - minimum glide angle, +/- 14 degrees
39
 * - maximum glide angle, +/- 68,2 degrees
40
 * - maximum horizontal speed, 0.32 m/s
41
 * - maximum vertical speed, 0.5
42
 * - maximum buoyancy, 200 grams
43
 *
44
 * Unlike motor propelled AUV, Seaglider exploits small changes in its buoyancy that,
45
 * in conjunction with wings, can convert vertical motion to horizontal.
46
 * So, a glider will reach a point into the water by describing a "saw-tooth" movement.
47
 * Thus the model, keeps track also of the buoyancy needed to maintain a given speed value.
48
 *
49
 * All the technical details and model's equations, can be found in [1]
50
 *
51
 * References:
52
 * [1] Eriksen et al, "Seaglider: A Long-Range Autonomous Underwater Vehicle for Oceanographic Research"
53
 *     URL: http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=972073&userType=inst
54
 */
55
class GliderMobilityModel : public AuvMobilityModel
56
{
57
public:
58
  static TypeId GetTypeId (void);
59
  GliderMobilityModel ();
60
  ~GliderMobilityModel ();
61
62
  /**
63
   * \returns the current buoyancy of the glider in grams
64
   */
65
  double GetBuoyancy (void) const;
66
  /**
67
   * \param node the node associated with the mobility model
68
   */
69
  void SetNode (const Ptr<Node> node);
70
  /**
71
   * \returns the associated node
72
   */
73
  Ptr<Node> GetNode (void) const;
74
75
  virtual void SetEmergeCallback (Callback<void, Ptr<MobilityModel> > cb);
76
  virtual void SetSubmergeCallback (Callback<void, Ptr<MobilityModel> > cb);
77
78
private:
79
  /**
80
   * Round a Vector of double, to the given decimal precision
81
   *
82
   * \param pos the position vector to be rounded
83
   * \param decimals the decimal precision
84
   * \returns the rounded position vector
85
   */
86
  Vector RoundPosition (const Vector &pos, uint16_t decimals) const;
87
  void Update (void);
88
  void UpdatePowerConsumption (double buoyancy, double W);
89
90
  virtual Vector DoGetPosition (void) const;
91
  virtual void DoSetPosition (const Vector &position);
92
  virtual Vector DoGetVelocity (void) const;
93
94
  virtual void DoMove (void);
95
  virtual void DoStop (void);
96
  virtual void DoEmerge (double depth);
97
  virtual void DoSubmerge (double depth);
98
  virtual double DoGetPitch () const;
99
  virtual void DoSetPitch (double pitch);
100
  virtual double DoGetDepth (void);
101
  virtual double DoGetDirection (void) const;
102
  virtual void DoSetDirection (double dir);
103
  virtual double DoGetSpeed () const;
104
  virtual void DoSetSpeed (double speed);
105
  virtual void DoSetVelocity (const Vector &velocity);
106
107
  // get the buoyancy value in grams from vertical and horizontal speed values
108
  double GetBuoyancy (double U, double W) const;
109
110
  ConstantVelocityHelper m_helper;
111
  double m_direction;
112
  double m_speed;
113
  double m_pitch;
114
  double m_depth;
115
  double m_buoyancy;
116
  double m_minGlideAngle;
117
  double m_maxGlideAngle;
118
  // double m_maxU;
119
  double m_maxW;
120
  double m_maxBuoyancy;
121
  double m_maxDepth;
122
  bool m_deployed;
123
124
  EventId m_stop;
125
  Ptr<Node> m_node;
126
127
  Callback<void, Ptr<MobilityModel> > m_emergeCb;
128
  Callback<void, Ptr<MobilityModel> > m_submergeCb;
129
};
130
131
}  // namespace ns3
132
133
#endif /* GLIDER_MOBILITY_MODEL_H_ */
(-)a/src/auv/model/remus-energy-model.cc (+218 lines)
Line 0    Link Here 
1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2010 Andrea Sacco
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: Andrea Sacco <andrea.sacco85@gmail.com>
19
 */
20
#include "remus-energy-model.h"
21
22
NS_LOG_COMPONENT_DEFINE ("RemusEnergyModel");
23
24
namespace ns3 {
25
26
NS_OBJECT_ENSURE_REGISTERED (RemusEnergyModel);
27
28
TypeId
29
RemusEnergyModel::GetTypeId (void)
30
{
31
  static TypeId tid = TypeId ("ns3::RemusEnergyModel")
32
    .SetParent<DeviceEnergyModel> ()
33
    .AddConstructor<RemusEnergyModel> ()
34
    .AddAttribute ("PowerSpeedRatio",
35
                   "Consumed power ratio with respect to motor speed",
36
                   DoubleValue (10.0), // in W*s/m
37
                   MakeDoubleAccessor (&RemusEnergyModel::m_powerSpeedRatio),
38
                   MakeDoubleChecker<double> ())
39
    .AddTraceSource ("TotalEnergyConsumption",
40
                     "Total energy consumption of the radio device.",
41
                     MakeTraceSourceAccessor (&RemusEnergyModel::m_totalEnergyConsumption),
42
                     "ns3::TracedValueCallback::Double")
43
  ;
44
  return tid;
45
}
46
47
RemusEnergyModel::RemusEnergyModel ()
48
{
49
  NS_LOG_FUNCTION (this);
50
  m_currentSpeed = 0.0;
51
  m_lastUpdateTime = Seconds (0.0);
52
  m_energyDepletionCallback.Nullify ();
53
  m_energyRechargedCallback.Nullify ();
54
  m_node = NULL;
55
  m_source = NULL;
56
}
57
58
RemusEnergyModel::~RemusEnergyModel ()
59
{
60
  m_energyDepletionCallback.Nullify ();
61
  m_energyRechargedCallback.Nullify ();
62
  m_node = NULL;
63
  m_source = NULL;
64
}
65
void
66
RemusEnergyModel::SetNode (Ptr<Node> node)
67
{
68
  NS_LOG_FUNCTION (this << node);
69
  NS_ASSERT (node != NULL);
70
  m_node = node;
71
}
72
73
Ptr<Node>
74
RemusEnergyModel::GetNode (void) const
75
{
76
  return m_node;
77
}
78
79
void
80
RemusEnergyModel::SetEnergySource (Ptr<EnergySource> source)
81
{
82
  NS_LOG_FUNCTION (this << source);
83
  NS_ASSERT (source != NULL);
84
  m_source = source;
85
}
86
87
double
88
RemusEnergyModel::GetTotalEnergyConsumption (void) const
89
{
90
  NS_LOG_FUNCTION (this);
91
92
  Time duration = Simulator::Now () - m_lastUpdateTime;
93
  double power = GetPower (m_currentSpeed);
94
  double energyToDecrease = duration.GetSeconds () * power;
95
96
  return m_totalEnergyConsumption + energyToDecrease;
97
}
98
99
void
100
RemusEnergyModel::ChangeState (int newState)
101
{
102
  NS_FATAL_ERROR ("ChangeState not implemented, use ChangeEnergyConsumption instead.");
103
}
104
105
void
106
RemusEnergyModel::ChangeEnergyConsumption (const double speed)
107
{
108
  NS_LOG_FUNCTION (this << speed);
109
110
  Time duration = Simulator::Now () - m_lastUpdateTime;
111
  NS_ASSERT (duration.GetNanoSeconds () >= 0); // check if duration is valid
112
113
  // update remaining energy accordingly
114
  double power = GetPower (m_currentSpeed);
115
  double energyToDecrease = duration.GetSeconds () * power;
116
117
  // update total energy consumption
118
  m_totalEnergyConsumption += energyToDecrease;
119
120
  // update current speed value
121
  m_currentSpeed = speed;
122
  // update current drain
123
  power = GetPower (m_currentSpeed);
124
  double supplyVoltage = m_source->GetSupplyVoltage ();
125
  m_actualCurrentDrain = power / supplyVoltage;
126
127
  // update last update time stamp
128
  m_lastUpdateTime = Simulator::Now ();
129
130
  // notify energy source
131
  m_source->UpdateEnergySource ();
132
133
  // some debug message
134
  NS_LOG_DEBUG ("RemusEnergyModel:Total energy consumption at node #" <<
135
                m_node->GetId () << " is " << m_totalEnergyConsumption << "J");
136
}
137
138
void
139
RemusEnergyModel::SetEnergyDepletionCallback (RemusEnergyDepletionCallback callback)
140
{
141
  NS_LOG_FUNCTION (this);
142
  if (callback.IsNull ())
143
    {
144
      NS_LOG_DEBUG ("RemusEnergyModel:Setting NULL energy depletion callback!");
145
    }
146
  m_energyDepletionCallback = callback;
147
}
148
149
void
150
RemusEnergyModel::SetEnergyRechargedCallback (RemusEnergyRechargedCallback callback)
151
{
152
  NS_LOG_FUNCTION (this);
153
  if (callback.IsNull ())
154
    {
155
      NS_LOG_DEBUG ("RemusEnergyModel:Setting NULL energy recharged callback!");
156
    }
157
  m_energyRechargedCallback = callback;
158
}
159
160
void
161
RemusEnergyModel::HandleEnergyDepletion (void)
162
{
163
  NS_LOG_FUNCTION (this);
164
  NS_LOG_DEBUG ("RemusEnergyModel:Energy is depleted at node #" <<
165
                m_node->GetId ());
166
167
  // invoke energy depletion callback, if set.
168
  if (!m_energyDepletionCallback.IsNull ())
169
    {
170
      m_energyDepletionCallback ();
171
    }
172
}
173
174
void
175
RemusEnergyModel::HandleEnergyRecharged (void)
176
{
177
  NS_LOG_FUNCTION (this);
178
  NS_LOG_DEBUG ("RemusEnergyModel:Energy is recharged at node #" <<
179
                m_node->GetId ());
180
181
  if (!m_energyRechargedCallback.IsNull ())
182
    {
183
      m_energyRechargedCallback ();
184
    }
185
}
186
/*
187
 * Private functions start here.
188
 */
189
190
void
191
RemusEnergyModel::DoDispose (void)
192
{
193
  NS_LOG_FUNCTION (this);
194
  m_node = NULL;
195
  m_source = NULL;
196
  m_energyDepletionCallback.Nullify ();
197
}
198
199
double
200
RemusEnergyModel::DoGetCurrentA (void) const
201
{
202
  NS_LOG_FUNCTION (this);
203
204
  return m_actualCurrentDrain;
205
}
206
207
double
208
RemusEnergyModel::GetPower (double speed) const
209
{
210
  // power needed, in watts
211
  // it is about 10 times the speed in m/s, thus for 1.5 m/s of navigation speed
212
  // the electric motor will drain 15 W of power
213
  double power = speed * m_powerSpeedRatio;
214
215
  return power;
216
}
217
218
} // namespace ns3
(-)a/src/auv/model/remus-energy-model.h (+178 lines)
Line 0    Link Here 
1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2010 Andrea Sacco
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: Andrea Sacco <andrea.sacco85@gmail.com>
19
 */
20
#ifndef REMUS_ENERGY_MODEL_H
21
#define REMUS_ENERGY_MODEL_H
22
23
#include "ns3/device-energy-model.h"
24
#include "ns3/energy-source.h"
25
#include "ns3/traced-value.h"
26
#include "ns3/log.h"
27
#include "ns3/simulator.h"
28
29
namespace ns3 {
30
31
/**
32
 * \ingroup auv
33
 * \brief Keeps track of the REMUS AUV energy consumption
34
 *
35
 * The class model the energy consumed by the AUV for navigation.
36
 * The REMUS is propelled by a brush-less electric motor.
37
 *
38
 * Consumption values have been taken from [1] and Hydroinc European salesman.
39
 * A typical value is 15 W @ 1.5 m/s of navigation speed.
40
 *
41
 * Since there are not detailed datasheet and specifications publicly available,
42
 * a power consumption linear with speed, is considered.
43
 *
44
 * References:
45
 * [1] Hydroinc REMUS 100 specifications; http://www.hydroidinc.com/100spec.html
46
 */
47
class RemusEnergyModel : public DeviceEnergyModel
48
{
49
public:
50
  // / Callback type for energy depletion handling.
51
  typedef Callback<void> RemusEnergyDepletionCallback;
52
  typedef Callback<void> RemusEnergyRechargedCallback;
53
54
public:
55
  static TypeId GetTypeId (void);
56
  RemusEnergyModel ();
57
  virtual ~RemusEnergyModel ();
58
59
  /**
60
   * \brief Sets pointer to node.
61
   *
62
   * \param node Pointer to node.
63
   *
64
   * Implements DeviceEnergyModel::SetNode.
65
   */
66
  virtual void SetNode (Ptr<Node> node);
67
68
  /**
69
   * \brief Gets pointer to node.
70
   *
71
   * \returns Pointer to node.
72
   *
73
   * Implements DeviceEnergyModel::GetNode.
74
   */
75
  virtual Ptr<Node> GetNode (void) const;
76
77
  /**
78
   * \brief Sets pointer to EnergySouce installed on node.
79
   *
80
   * \param source Pointer to EnergySource installed on node.
81
   *
82
   * Implements DeviceEnergyModel::SetEnergySource.
83
   */
84
  virtual void SetEnergySource (Ptr<EnergySource> source);
85
86
  /**
87
   * \returns Total energy consumption of the vehicle.
88
   *
89
   * Implements DeviceEnergyModel::GetTotalEnergyConsumption.
90
   */
91
  virtual double GetTotalEnergyConsumption (void) const;
92
93
  /**
94
   * \param newState New state the device is in.
95
   *
96
   * DeviceEnergyModel is a state based model. This function is implemented by
97
   * all child of DeviceEnergyModel to change the model's state. States are to
98
   * be defined by each child using an enum (int).
99
   */
100
  virtual void ChangeState (int newState);
101
102
  /**
103
   * \param speed the speed value of the vehicle
104
   *
105
   * Update the energy consumption according to the speed value.
106
   */
107
  void ChangeEnergyConsumption (const double speed);
108
109
  /**
110
   * \param callback Callback function.
111
   *
112
   * Sets callback for energy depletion handling.
113
   */
114
  void SetEnergyDepletionCallback (RemusEnergyDepletionCallback callback);
115
116
  /**
117
   * \param callback Callback function.
118
   *
119
   * Sets callback for energy recharged handling.
120
   */
121
  void SetEnergyRechargedCallback (RemusEnergyRechargedCallback callback);
122
123
  /**
124
   * \brief Handles energy depletion.
125
   *
126
   * Implements DeviceEnergyModel::HandleEnergyDepletion
127
   */
128
  virtual void HandleEnergyDepletion (void);
129
130
  /**
131
   * \brief Handles energy recharge.
132
   *
133
   * Implements DeviceEnergyModel::HandleEnergyRecharged
134
   */
135
  virtual void HandleEnergyRecharged (void);
136
137
private:
138
  void DoDispose (void);
139
140
  /**
141
   * \returns Current draw of device, at current state.
142
   *
143
   * Implements DeviceEnergyModel::GetCurrentA.
144
   */
145
  virtual double DoGetCurrentA (void) const;
146
147
  /**
148
   * \param speed the navigation speed in m/s
149
   * \return the needed power in watts
150
   *
151
   * This get the power needed to maintain a given speed value.
152
   */
153
  double GetPower (double speed) const;
154
155
private:
156
  Ptr<Node> m_node;
157
  Ptr<EnergySource> m_source;
158
159
  // This variable keeps track of the total energy consumed by this particular model.
160
  TracedValue<double> m_totalEnergyConsumption;
161
162
  // actual current drain
163
  double m_actualCurrentDrain;
164
  // current navigation speed in m/s
165
  double m_currentSpeed;
166
  // time stamp of previous energy update
167
  Time m_lastUpdateTime;
168
  // the power consumption per 1 m/s speed
169
  double m_powerSpeedRatio;
170
171
  // energy depletion callback
172
  RemusEnergyDepletionCallback m_energyDepletionCallback;
173
  RemusEnergyRechargedCallback m_energyRechargedCallback;
174
};
175
176
} // namespace ns3
177
178
#endif /* REMUS_ENERGY_MODEL_H */
(-)a/src/auv/model/remus-mobility-model.cc (+398 lines)
Line 0    Link Here 
1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2010 Andrea Sacco
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: Andrea Sacco <andrea.sacco85@gmail.com>
19
 */
20
#include "remus-mobility-model.h"
21
#include "ns3/remus-energy-model.h"
22
23
namespace ns3 {
24
25
NS_LOG_COMPONENT_DEFINE ("RemusMobilityModel");
26
27
NS_OBJECT_ENSURE_REGISTERED (RemusMobilityModel);
28
29
TypeId
30
RemusMobilityModel::GetTypeId (void)
31
{
32
  static TypeId tid = TypeId ("ns3::RemusMobilityModel")
33
    .SetParent (AuvMobilityModel::GetTypeId ())
34
    .AddConstructor<RemusMobilityModel> ()
35
    .AddAttribute ("MaxDepth", "The maximum operational depth, in m",
36
                   DoubleValue (-100.0),
37
                   MakeDoubleAccessor (&RemusMobilityModel::m_maxDepth),
38
                   MakeDoubleChecker<double> ())
39
    .AddAttribute ("MinSpeed", "The minimum speed of the vehicle, in m/s.",
40
                   DoubleValue (0.25),
41
                   MakeDoubleAccessor (&RemusMobilityModel::m_minSpeed),
42
                   MakeDoubleChecker<double> ())
43
    .AddAttribute ("MaxSpeed", "The maximum speed of the vehicle, in m/s.",
44
                   DoubleValue (2.8),
45
                   MakeDoubleAccessor (&RemusMobilityModel::m_maxSpeed),
46
                   MakeDoubleChecker<double> ())
47
  ;
48
  return tid;
49
}
50
51
RemusMobilityModel::RemusMobilityModel ()
52
  : m_direction (0),
53
  m_speed (0),
54
  m_pitch (0),
55
  m_depth (0),
56
  m_maxPitch (60),
57
  m_deployed (false),
58
  m_node (NULL)
59
{
60
  m_emergeCb.Nullify ();
61
  m_submergeCb.Nullify ();
62
}
63
64
RemusMobilityModel::~RemusMobilityModel ()
65
{
66
  m_emergeCb.Nullify ();
67
  m_submergeCb.Nullify ();
68
  m_node = NULL;
69
}
70
71
Vector
72
RemusMobilityModel::RoundPosition (const Vector &pos, uint16_t decimals) const
73
{
74
  Vector roundPos;
75
76
  double off = std::pow (10, decimals);
77
  roundPos.x = (std::floor ((pos.x * off) + 0.5)) / off;
78
  roundPos.y = (std::floor ((pos.y * off) + 0.5)) / off;
79
  roundPos.z = (std::floor ((pos.z * off) + 0.5)) / off;
80
81
  return roundPos;
82
}
83
84
void
85
RemusMobilityModel::SetNode (const Ptr<Node> node)
86
{
87
  NS_ASSERT (node != NULL);
88
  m_node = node;
89
}
90
91
Ptr<Node>
92
RemusMobilityModel::GetNode (void) const
93
{
94
  return m_node;
95
}
96
97
void
98
RemusMobilityModel::SetEmergeCallback (Callback<void, Ptr<MobilityModel> > cb)
99
{
100
  m_emergeCb = cb;
101
}
102
103
void
104
RemusMobilityModel::SetSubmergeCallback (Callback<void, Ptr<MobilityModel> > cb)
105
{
106
  m_submergeCb = cb;
107
}
108
109
Vector
110
RemusMobilityModel::DoGetPosition (void) const
111
{
112
  // update the helper position
113
  m_helper.Update ();
114
115
  // get the current position
116
  Vector pos = m_helper.GetCurrentPosition ();
117
118
  // get the rounded precision position
119
  Vector rpos = RoundPosition (pos, 4);
120
121
  return rpos;
122
}
123
124
void
125
RemusMobilityModel::DoSetPosition (const Vector &position)
126
{
127
  NS_ASSERT (!m_deployed);
128
129
  m_helper.SetPosition (position);
130
}
131
132
Vector
133
RemusMobilityModel::DoGetVelocity (void) const
134
{
135
  return m_helper.GetVelocity ();
136
}
137
138
void
139
RemusMobilityModel::DoSetVelocity (const Vector &velocity)
140
{
141
  // if velocity is 0
142
  if (CalculateDistance (velocity,Vector (0, 0, 0)) == 0)
143
    {
144
      // stop the vehicle
145
      DoStop ();
146
147
      return;
148
    }
149
150
  // convert the cartesians coordinates into polar one
151
152
  double speed = std::sqrt ((velocity.x * velocity.x) +
153
                            (velocity.y * velocity.y) +
154
                            (velocity.z * velocity.z));
155
156
  NS_ASSERT (speed <= m_maxSpeed);
157
  m_speed = speed;
158
159
  double dir = std::atan2 (velocity.y, velocity.x);
160
  m_direction = dir;
161
162
  double pitch = std::asin ((velocity.z / speed));
163
  NS_ASSERT (std::abs (pitch * 180 / M_PI) <= m_maxPitch);
164
  m_pitch = pitch;
165
166
  m_helper.SetVelocity (velocity);
167
168
  Move ();
169
}
170
171
void
172
RemusMobilityModel::UpdatePowerConsumption (const double speed)
173
{
174
  Ptr<EnergySourceContainer> source = m_node->GetObject<EnergySourceContainer> ();
175
  if (source != NULL)
176
    {
177
      // retrieve device energy model from energy source
178
      DeviceEnergyModelContainer modelCont =
179
        source->Get (0)->FindDeviceEnergyModels ("ns3::RemusEnergyModel");
180
181
      NS_ASSERT (modelCont.GetN () != 0);
182
      // get pointer
183
      Ptr<RemusEnergyModel> devModel = DynamicCast<RemusEnergyModel> (modelCont.Get (0));
184
      devModel->ChangeEnergyConsumption (speed);
185
    }
186
}
187
188
void
189
RemusMobilityModel::Update (void)
190
{
191
  // get the vector components
192
  double cosD = std::cos (m_direction);
193
  double cosP = std::cos (m_pitch);
194
  double sinD = std::sin (m_direction);
195
  double sinP = std::sin (m_pitch);
196
197
  // set the velocity vector
198
  m_helper.SetVelocity (Vector (m_speed * cosD * cosP, m_speed * sinD * cosP, m_speed * sinP));
199
200
  // update depth
201
  m_depth = GetDepth ();
202
203
  // update the helper
204
  m_helper.Update ();
205
206
  // notify the change
207
  NotifyCourseChange ();
208
}
209
210
void
211
RemusMobilityModel::DoMove (void)
212
{
213
  if (!m_deployed)
214
    {
215
      // the vehicle has just been deployed
216
      m_deployed = true;
217
    }
218
219
  // unpause the helper
220
  m_helper.Unpause ();
221
222
  // update the helper with the new nav params
223
  Update ();
224
225
  // update the energy consumption
226
  UpdatePowerConsumption (m_speed);
227
228
  // compute the necessary time to reach the maximum operative depth
229
  // or water surface and set a stop event
230
  double vertVel = m_helper.GetVelocity ().z;
231
232
  if (vertVel != 0)
233
    {
234
      double stopTime = 0;
235
      if (vertVel < 0)
236
        {
237
          stopTime = (m_maxDepth - DoGetDepth ()) / vertVel;
238
        }
239
      else
240
        {
241
          stopTime = (0 - DoGetDepth ()) / vertVel;
242
        }
243
244
      Simulator::Cancel (m_stop);
245
      m_stop = Simulator::Schedule (Seconds (stopTime),
246
                                    &RemusMobilityModel::Stop,
247
                                    this);
248
    }
249
}
250
251
void
252
RemusMobilityModel::DoStop (void)
253
{
254
  // Update ();
255
  m_helper.Update ();
256
257
  // now the vehicle is stopped
258
  m_speed = 0;
259
260
  // update the energy consumption
261
  UpdatePowerConsumption (m_speed);
262
263
  Simulator::Cancel (m_stop);
264
  m_helper.Pause ();
265
}
266
267
void
268
RemusMobilityModel::DoEmerge (double depth)
269
{
270
  NS_ASSERT (depth <= 0 && depth >= m_maxDepth);
271
272
  double deltaDepth = depth - GetDepth ();
273
274
  // we want to emerge so the delta depth must be positive
275
  NS_ASSERT (deltaDepth > 0);
276
  // set the maximum pitch value
277
  SetPitch (m_maxPitch);
278
  // set the maximum speed value
279
  SetSpeed (m_maxSpeed);
280
281
  // compute the time needed to reach to the specified depth
282
  double emergeTime = deltaDepth / (m_speed * std::sin (m_pitch));
283
284
  // set an event to stop the vehicle when it have reached the specified depth
285
  m_stop = Simulator::Schedule (Seconds (emergeTime),
286
                                &RemusMobilityModel::DoStop,
287
                                this);
288
289
  // schedule the call to the emerge callback
290
  if (!m_emergeCb.IsNull ())
291
    {
292
      Simulator::Schedule (Seconds (emergeTime),
293
                           &RemusMobilityModel::m_emergeCb,
294
                           this,
295
                           this);
296
    }
297
}
298
299
void
300
RemusMobilityModel::DoSubmerge (double depth)
301
{
302
  NS_ASSERT (depth >= m_maxDepth && depth <= 0);
303
304
  double deltaDepth = depth - GetDepth ();
305
306
  // we want to submerge so the delta depth must be negative
307
  NS_ASSERT (deltaDepth < 0);
308
  // set the maximum pitch value, negative because we're going down
309
  SetPitch (-m_maxPitch);
310
  // set the maximum speed value
311
  SetSpeed (m_maxSpeed);
312
313
  // compute the time needed to reach to the specified depth
314
  double submergeTime = deltaDepth / (m_speed * std::sin (m_pitch));
315
316
  // set an event to stop the vehicle when it have reached the specified depth
317
  m_stop = Simulator::Schedule (Seconds (submergeTime),
318
                                &RemusMobilityModel::DoStop,
319
                                this);
320
321
  // schedule the call to the submerge callback
322
  if (!m_submergeCb.IsNull ())
323
    {
324
      Simulator::Schedule (Seconds (submergeTime),
325
                           &RemusMobilityModel::m_submergeCb,
326
                           this,
327
                           this);
328
    }
329
}
330
331
double
332
RemusMobilityModel::DoGetPitch () const
333
{
334
  // the pitch angle is stored in radians
335
  return m_pitch * 180 / M_PI;
336
}
337
338
void
339
RemusMobilityModel::DoSetPitch (double pitch)
340
{
341
  NS_ASSERT_MSG (std::abs (pitch) <= m_maxPitch,
342
                 "An excessive pitch angle has been set");
343
344
  // the pitch angle is stored in radians
345
  m_pitch = pitch * M_PI / 180;
346
347
  Update ();
348
}
349
350
double
351
RemusMobilityModel::DoGetDepth (void)
352
{
353
  // update the current depth
354
  Vector pos = GetPosition ();
355
  m_depth = pos.z;
356
357
  return m_depth;
358
}
359
360
double
361
RemusMobilityModel::DoGetDirection (void) const
362
{
363
  return m_direction * 180 / M_PI;
364
}
365
366
void
367
RemusMobilityModel::DoSetDirection (double dir)
368
{
369
  m_direction = dir * M_PI / 180;
370
371
  Update ();
372
}
373
374
double
375
RemusMobilityModel::DoGetSpeed () const
376
{
377
  return m_speed;
378
}
379
380
void
381
RemusMobilityModel::DoSetSpeed (double speed)
382
{
383
  NS_ASSERT (speed <= m_maxSpeed);
384
385
  if (speed < m_minSpeed)
386
    {
387
      m_speed = 0;
388
    }
389
  else
390
    {
391
      m_speed = speed;
392
    }
393
394
  Update ();
395
  Move ();
396
}
397
398
} // namespace ns3
(-)a/src/auv/model/remus-mobility-model.h (+125 lines)
Line 0    Link Here 
1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2010 Andrea Sacco
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: Andrea Sacco <andrea.sacco85@gmail.com>
19
 */
20
21
#ifndef REMUS_MOBILITY_MODEL_H_
22
#define REMUS_MOBILITY_MODEL_H_
23
24
#include "auv-mobility-model.h"
25
#include "ns3/event-id.h"
26
27
28
namespace ns3 {
29
30
/**
31
 * \ingroup auv
32
 * \brief keep track of the position of a REMUS AUV
33
 *
34
 * A REMUS class AUV is an submarine-like device, propelled by an electric motor linked with a propeller.
35
 *
36
 * The model is based on the constant velocity mobility model but introduces the physical
37
 * constraints characteristics of the REMUS AUV [1][2]:
38
 *
39
 * - maximum operational depth, 100 m
40
 * - minimum speed, 0.25 m/s
41
 * - maximum speed, 2.8 m/s
42
 * - pitch range, +/- 60 degrees
43
 *
44
 * References:
45
 * [1] Hydroinc Products; http://www.hydroidinc.com/products.html
46
 * [2] WHOI, Autonomous Underwater Vehicle, REMUS; http://www.whoi.edu/page.do?pid=29856
47
 */
48
class RemusMobilityModel : public AuvMobilityModel
49
{
50
public:
51
  static TypeId GetTypeId (void);
52
  RemusMobilityModel ();
53
  ~RemusMobilityModel ();
54
55
  /**
56
   * \param node the node associated with the mobility model
57
   */
58
  void SetNode (const Ptr<Node> node);
59
  /**
60
   * \returns the associated node
61
   */
62
  Ptr<Node> GetNode (void) const;
63
  /**
64
   * Set a callback to be called at the end of the emerging process
65
   *
66
   * \param cb the callback to be set
67
   */
68
  virtual void SetEmergeCallback (Callback<void, Ptr<MobilityModel> > cb);
69
  /**
70
   * Set a callback to be called at the end of the submerging process
71
   *
72
   * \param cb the callback to be set
73
   */
74
  virtual void SetSubmergeCallback (Callback<void, Ptr<MobilityModel> > cb);
75
76
private:
77
  /**
78
   * Round a Vector of double, to the given decimal precision
79
   *
80
   * \param pos the position vector to be rounded
81
   * \param decimals the decimal precision
82
   * \returns the rounded position vector
83
   */
84
  Vector RoundPosition (const Vector &pos, uint16_t decimals) const;
85
  void Update (void);
86
  void UpdatePowerConsumption (const double speed);
87
88
  virtual Vector DoGetPosition (void) const;
89
  virtual void DoSetPosition (const Vector &position);
90
  virtual Vector DoGetVelocity (void) const;
91
92
  virtual void DoMove (void);
93
  virtual void DoStop (void);
94
  virtual void DoEmerge (double depth);
95
  virtual void DoSubmerge (double depth);
96
  virtual double DoGetPitch () const;
97
  virtual void DoSetPitch (double pitch);
98
  virtual double DoGetDepth (void);
99
  virtual double DoGetDirection (void) const;
100
  virtual void DoSetDirection (double dir);
101
  virtual double DoGetSpeed () const;
102
  virtual void DoSetSpeed (double speed);
103
  virtual void DoSetVelocity (const Vector &velocity);
104
105
  ConstantVelocityHelper m_helper;
106
  double m_direction;
107
  double m_speed;
108
  double m_pitch;
109
  double m_depth;
110
  double m_minSpeed;
111
  double m_maxSpeed;
112
  double m_maxDepth;
113
  // maximum pitch value, in degrees
114
  double m_maxPitch;
115
  bool m_deployed;
116
  EventId m_stop;
117
  Ptr<Node> m_node;
118
119
  Callback<void, Ptr<MobilityModel> > m_emergeCb;
120
  Callback<void, Ptr<MobilityModel> > m_submergeCb;
121
};
122
123
}  // namespace ns3
124
125
#endif /* REMUS_MOBILITY_MODEL_H_ */
(-)a/src/auv/test/auv-energy-model-test.cc (+477 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2010 Andrea Sacco
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: Andrea Sacco <andrea.sacco85@gmail.com>
19
 */
20
21
#include "ns3/log.h"
22
#include "ns3/test.h"
23
#include "ns3/simple-device-energy-model.h"
24
#include "ns3/uan-net-device.h"
25
#include "ns3/simulator.h"
26
#include "ns3/packet.h"
27
#include "ns3/node.h"
28
#include "ns3/auv-glider-helper.h"
29
#include "ns3/auv-remus-helper.h"
30
#include "ns3/auv-waypoint-mobility-model.h"
31
#include "ns3/uan-helper.h"
32
#include "ns3/basic-energy-source-helper.h"
33
#include "ns3/acoustic-modem-energy-model-helper.h"
34
#include "ns3/acoustic-modem-energy-model.h"
35
#include "ns3/constant-position-mobility-model.h"
36
#include "ns3/uan-channel.h"
37
#include "ns3/uan-noise-model-default.h"
38
#include "ns3/uan-prop-model-ideal.h"
39
#include "ns3/uan-header-common.h"
40
#include "ns3/uan-phy.h"
41
42
namespace ns3 {
43
44
NS_LOG_COMPONENT_DEFINE ("AuvEnergyModelTestSuite");
45
46
class AcousticModemEnergyTestCase : public TestCase
47
{
48
public:
49
  AcousticModemEnergyTestCase ();
50
  ~AcousticModemEnergyTestCase ();
51
52
  bool RxPacket (Ptr<NetDevice> dev, Ptr<const Packet> pkt, uint16_t mode, const Address &sender);
53
  void SendOnePacket (Ptr<Node> node);
54
55
  void DoRun (void);
56
57
  double m_simTime;
58
  uint32_t m_bytesRx;
59
  uint32_t m_sentPackets;
60
  uint32_t m_packetSize;
61
  Ptr<Node> m_node;
62
  Ptr<Node> m_gateway;
63
};
64
65
AcousticModemEnergyTestCase::AcousticModemEnergyTestCase ()
66
  : TestCase ("Acoustic Modem energy model test case"),
67
  m_simTime (25),
68
  m_bytesRx (0),
69
  m_sentPackets (0),
70
  m_packetSize (17)
71
{
72
}
73
74
AcousticModemEnergyTestCase::~AcousticModemEnergyTestCase ()
75
{
76
  m_node = NULL;
77
  m_gateway = NULL;
78
}
79
80
void
81
AcousticModemEnergyTestCase::SendOnePacket (Ptr<Node> node)
82
{
83
  // create an empty 17 bytes packet
84
  Ptr<Packet> pkt = Create<Packet> (m_packetSize);
85
  // send the packet in broadcast
86
  Ptr<UanNetDevice> dev = node->GetDevice (0)->GetObject<UanNetDevice> ();
87
  dev->Send (pkt, dev->GetBroadcast (), 0);
88
  // increase the sent packets number
89
  ++m_sentPackets;
90
91
  Simulator::Schedule (Seconds (10),
92
                       &AcousticModemEnergyTestCase::SendOnePacket,
93
                       this,
94
                       node);
95
}
96
97
bool
98
AcousticModemEnergyTestCase::RxPacket (Ptr<NetDevice> dev, Ptr<const Packet> pkt, uint16_t mode, const Address &sender)
99
{
100
  // increase the total bytes received
101
  m_bytesRx += pkt->GetSize ();
102
103
  return true;
104
}
105
106
void
107
AcousticModemEnergyTestCase::DoRun ()
108
{
109
  // create a generic node
110
  m_node = CreateObject<Node> ();
111
112
  // create a default underwater channel
113
  Ptr<UanChannel> channel = CreateObject<UanChannel> ();
114
  Ptr<UanNoiseModelDefault> noise = CreateObject<UanNoiseModelDefault> ();
115
  channel->SetPropagationModel (CreateObject<UanPropModelIdeal> ());
116
  channel->SetNoiseModel (noise);
117
118
  // install the underwater communication stack
119
  UanHelper uan;
120
  Ptr<UanNetDevice> devNode = uan.Install (m_node, channel);
121
122
  // compute a packet (header + payload) duration
123
  uint32_t datarate = devNode->GetPhy ()->GetMode (0).GetDataRateBps ();
124
  UanHeaderCommon hd;
125
  double packetDuration = (m_packetSize + hd.GetSerializedSize ()) * 8.0 / (double) datarate;
126
127
  // energy source
128
  BasicEnergySourceHelper eh;
129
  eh.Set ("BasicEnergySourceInitialEnergyJ", DoubleValue (10000000.0));
130
  eh.Install (m_node);
131
132
  // mobility model
133
  Ptr<ConstantPositionMobilityModel> mobility = CreateObject<ConstantPositionMobilityModel> ();
134
  mobility->SetPosition (Vector (0,0,-500));
135
  m_node->AggregateObject (mobility);
136
137
  // micro modem energy model
138
  AcousticModemEnergyModelHelper modemHelper;
139
  Ptr<EnergySource> source = m_node->GetObject<EnergySourceContainer> ()->Get (0);
140
  DeviceEnergyModelContainer cont = modemHelper.Install (devNode,source);
141
142
  // Schedule a packet every 10 seconds
143
  Simulator::ScheduleNow (&AcousticModemEnergyTestCase::SendOnePacket,
144
                          this,
145
                          m_node);
146
147
  // create a gateway node
148
  m_gateway = CreateObject<Node> ();
149
150
  // install the underwater communication stack
151
  Ptr<UanNetDevice> devGateway = uan.Install (m_gateway, channel);
152
153
  // energy source
154
  eh.Set ("BasicEnergySourceInitialEnergyJ", DoubleValue (10000000.0));
155
  eh.Install (m_gateway);
156
157
  // mobility model
158
  Ptr<ConstantPositionMobilityModel> mobility2 = CreateObject<ConstantPositionMobilityModel> ();
159
  mobility2->SetPosition (Vector (0,0,0));
160
  m_gateway->AggregateObject (mobility2);
161
162
  // micro modem energy model
163
  Ptr<EnergySource> source2 = m_gateway->GetObject<EnergySourceContainer> ()->Get (0);
164
  DeviceEnergyModelContainer cont2 = modemHelper.Install (devGateway, source2);
165
166
  // set the receive callback
167
  Ptr<NetDevice> dev = m_gateway->GetDevice (0);
168
  dev->SetReceiveCallback (MakeCallback (&AcousticModemEnergyTestCase::RxPacket,
169
                                         this));
170
171
  // run the simulation
172
  Simulator::Stop (Seconds (m_simTime));
173
  Simulator::Run ();
174
  Simulator::Destroy ();
175
176
  uint32_t receivedPackets = m_bytesRx / m_packetSize;
177
  Ptr<EnergySource> src1 = m_gateway->GetObject<EnergySourceContainer> ()->Get (0);
178
  double consumed1 = src1->GetInitialEnergy () - src1->GetRemainingEnergy ();
179
  double computed1 = cont2.Get (0)->GetObject<AcousticModemEnergyModel> ()->GetRxPowerW () * packetDuration * receivedPackets +
180
    cont2.Get (0)->GetObject<AcousticModemEnergyModel> ()->GetIdlePowerW () * (m_simTime - (double) 2.0 / 3.0 - packetDuration * receivedPackets);
181
182
  NS_TEST_ASSERT_MSG_EQ_TOL (consumed1, computed1, 1.0e-5,
183
                             "Incorrect gateway consumed energy!");
184
185
  Ptr<EnergySource> src2 = m_node->GetObject<EnergySourceContainer> ()->Get (0);
186
  double consumed2 = src2->GetInitialEnergy () - src2->GetRemainingEnergy ();
187
  double computed2 = cont.Get (0)->GetObject<AcousticModemEnergyModel> ()->GetTxPowerW () * packetDuration * m_sentPackets +
188
    cont.Get (0)->GetObject<AcousticModemEnergyModel> ()->GetIdlePowerW () * (m_simTime - 1 - packetDuration * m_sentPackets);
189
190
  NS_TEST_ASSERT_MSG_EQ_TOL (consumed2, computed2, 1.0e-5,
191
                             "Incorrect node consumed energy!");
192
193
}
194
195
class AcousticModemEnergyDepletionTestCase : public TestCase
196
{
197
public:
198
  AcousticModemEnergyDepletionTestCase ();
199
  ~AcousticModemEnergyDepletionTestCase ();
200
201
  void DepletionHandler (void);
202
  void SendOnePacket (Ptr<Node> node);
203
204
  void DoRun (void);
205
206
  double m_simTime;
207
  uint32_t m_callbackCount;
208
  uint32_t m_packetSize;
209
  Ptr<Node> m_node;
210
};
211
212
AcousticModemEnergyDepletionTestCase::AcousticModemEnergyDepletionTestCase ()
213
  : TestCase ("Acoustic Modem energy depletion test case"),
214
  m_simTime (25),
215
  m_callbackCount (0),
216
  m_packetSize (17)
217
{
218
}
219
220
AcousticModemEnergyDepletionTestCase::~AcousticModemEnergyDepletionTestCase ()
221
{
222
  m_node = NULL;
223
}
224
225
void
226
AcousticModemEnergyDepletionTestCase::DepletionHandler (void)
227
{
228
  // increase callback count
229
  m_callbackCount++;
230
}
231
232
void
233
AcousticModemEnergyDepletionTestCase::SendOnePacket (Ptr<Node> node)
234
{
235
  // create an empty packet
236
  Ptr<Packet> pkt = Create<Packet> (m_packetSize);
237
  // send the packet in broadcast
238
  Ptr<UanNetDevice> dev = node->GetDevice (0)->GetObject<UanNetDevice> ();
239
  dev->Send (pkt, dev->GetBroadcast (), 0);
240
241
  Simulator::Schedule (Seconds (10),
242
                       &AcousticModemEnergyDepletionTestCase::SendOnePacket,
243
                       this,
244
                       node);
245
}
246
247
void
248
AcousticModemEnergyDepletionTestCase::DoRun (void)
249
{
250
  // create a generic node
251
  m_node = CreateObject<Node> ();
252
253
  // create a default underwater channel
254
  Ptr<UanChannel> channel = CreateObject<UanChannel> ();
255
  Ptr<UanNoiseModelDefault> noise = CreateObject<UanNoiseModelDefault> ();
256
  channel->SetPropagationModel (CreateObject<UanPropModelIdeal> ());
257
  channel->SetNoiseModel (noise);
258
259
  // install the underwater communication stack
260
  UanHelper uan;
261
  Ptr<UanNetDevice> devNode = uan.Install (m_node, channel);
262
263
  // set an empty energy source
264
  BasicEnergySourceHelper eh;
265
  eh.Set ("BasicEnergySourceInitialEnergyJ", DoubleValue (0.0));
266
  eh.Install (m_node);
267
268
  // mobility model
269
  Ptr<ConstantPositionMobilityModel> mobility = CreateObject<ConstantPositionMobilityModel> ();
270
  mobility->SetPosition (Vector (0,0,0));
271
  m_node->AggregateObject (mobility);
272
273
  // micro modem energy model
274
  AcousticModemEnergyModelHelper modemHelper;
275
  Ptr<EnergySource> source = m_node->GetObject<EnergySourceContainer> ()->Get (0);
276
  // set the depletion callback
277
  AcousticModemEnergyModel::AcousticModemEnergyDepletionCallback callback =
278
    MakeCallback (&AcousticModemEnergyDepletionTestCase::DepletionHandler, this);
279
  modemHelper.SetDepletionCallback (callback);
280
  DeviceEnergyModelContainer cont = modemHelper.Install (devNode,source);
281
282
  // try to send a packet
283
  Simulator::ScheduleNow (&AcousticModemEnergyDepletionTestCase::SendOnePacket,
284
                          this,
285
                          m_node);
286
287
  Simulator::Stop (Seconds (m_simTime));
288
  Simulator::Run ();
289
  Simulator::Destroy ();
290
291
  NS_TEST_ASSERT_MSG_EQ (m_callbackCount, 1, "Callback not invoked");
292
293
}
294
295
class GliderEnergyTestCase : public TestCase
296
{
297
public:
298
  GliderEnergyTestCase ();
299
  ~GliderEnergyTestCase ();
300
301
  void DoRun (void);
302
  void GetPosition (void);
303
304
  double m_simTime;
305
  Ptr<Node> m_node;
306
};
307
308
GliderEnergyTestCase::GliderEnergyTestCase ()
309
  : TestCase ("Glider energy model test case"),
310
  m_node (NULL)
311
{
312
}
313
314
GliderEnergyTestCase::~GliderEnergyTestCase ()
315
{
316
  m_node = NULL;
317
}
318
319
void
320
GliderEnergyTestCase::GetPosition ()
321
{
322
  Ptr<AuvWaypointMobilityModel> model = m_node->GetObject<AuvWaypointMobilityModel> ();
323
324
  Simulator::Schedule (Seconds (1),
325
                       &GliderEnergyTestCase::GetPosition,
326
                       this);
327
}
328
329
void
330
GliderEnergyTestCase::DoRun ()
331
{
332
  m_node = CreateObject<Node> ();
333
334
  // create a default underwater channel
335
  Ptr<UanChannel> channel = CreateObject<UanChannel> ();
336
  Ptr<UanNoiseModelDefault> noise = CreateObject<UanNoiseModelDefault> ();
337
  channel->SetPropagationModel (CreateObject<UanPropModelIdeal> ());
338
  channel->SetNoiseModel (noise);
339
340
  // install the underwater communication stack
341
  UanHelper uan;
342
  Ptr<UanNetDevice> devNode = uan.Install (m_node, channel);
343
344
  // install the glider components
345
  AuvGliderHelper gh;
346
  gh.Install (m_node);
347
348
  Ptr<EnergySource> motorSrc = m_node->GetObject<EnergySourceContainer> ()->Get (0);
349
  Ptr<EnergySource> modemSrc = m_node->GetObject<EnergySourceContainer> ()->Get (1);
350
351
  AcousticModemEnergyModelHelper umem;
352
  umem.Install (devNode, modemSrc);
353
354
  // move the vehicle somewhere
355
  Ptr<AuvWaypointMobilityModel> mob = m_node->GetObject<AuvWaypointMobilityModel> ();
356
  mob->AddWaypoint (Waypoint (Seconds (0), Vector (0,0,0)));
357
  mob->AddWaypoint (Waypoint (Seconds (20), Vector (4.5,0,-10)));
358
  GetPosition ();
359
360
  // run the simulation
361
  Simulator::Stop (Seconds (25));
362
  Simulator::Run ();
363
  Simulator::Destroy ();
364
365
  double motorConsumption = motorSrc->GetInitialEnergy () - motorSrc->GetRemainingEnergy ();
366
  double motorEstimated = 19 * 0.96999;
367
  NS_TEST_ASSERT_MSG_EQ_TOL (motorConsumption, motorEstimated, 1.0e-4,
368
                             "Incorrect motor consumed energy!");
369
370
  double modemConsumption = modemSrc->GetInitialEnergy () - modemSrc->GetRemainingEnergy ();
371
  double modemEstimated = 24 * 0.158;
372
  NS_TEST_ASSERT_MSG_EQ_TOL (modemConsumption, modemEstimated, 1.0e-4,
373
                             "Incorrect modem consumed energy!");
374
}
375
376
class RemusEnergyTestCase : public TestCase
377
{
378
public:
379
  RemusEnergyTestCase ();
380
  ~RemusEnergyTestCase ();
381
382
  void DoRun (void);
383
  void GetPosition (void);
384
385
  double m_simTime;
386
  Ptr<Node> m_node;
387
};
388
389
RemusEnergyTestCase::RemusEnergyTestCase ()
390
  : TestCase ("Remus energy model test case"),
391
  m_node (NULL)
392
{
393
}
394
395
RemusEnergyTestCase::~RemusEnergyTestCase ()
396
{
397
  m_node = NULL;
398
}
399
400
void
401
RemusEnergyTestCase::GetPosition ()
402
{
403
  Ptr<AuvWaypointMobilityModel> model = m_node->GetObject<AuvWaypointMobilityModel> ();
404
405
  Simulator::Schedule (Seconds (1),
406
                       &RemusEnergyTestCase::GetPosition,
407
                       this);
408
}
409
410
void
411
RemusEnergyTestCase::DoRun ()
412
{
413
  m_node = CreateObject<Node> ();
414
415
  // create a default underwater channel
416
  Ptr<UanChannel> channel = CreateObject<UanChannel> ();
417
  Ptr<UanNoiseModelDefault> noise = CreateObject<UanNoiseModelDefault> ();
418
  channel->SetPropagationModel (CreateObject<UanPropModelIdeal> ());
419
  channel->SetNoiseModel (noise);
420
421
  // install the underwater communication stack
422
  UanHelper uan;
423
  Ptr<UanNetDevice> devNode = uan.Install (m_node, channel);
424
425
  // install the remus components
426
  AuvRemusHelper rh;
427
  rh.Install (m_node);
428
429
  Ptr<EnergySource> src = m_node->GetObject<EnergySourceContainer> ()->Get (0);
430
431
  AcousticModemEnergyModelHelper umem;
432
  umem.Install (devNode, src);
433
434
  // move the vehicle somewhere
435
  Ptr<AuvWaypointMobilityModel> mob = m_node->GetObject<AuvWaypointMobilityModel> ();
436
  mob->AddWaypoint (Waypoint (Seconds (0), Vector (0,0,0)));
437
  mob->AddWaypoint (Waypoint (Seconds (50), Vector (100,0,0)));
438
  GetPosition ();
439
440
  // run the simulation
441
  Simulator::Stop (Seconds (55));
442
  Simulator::Run ();
443
  Simulator::Destroy ();
444
445
  double consumed = src->GetInitialEnergy () - src->GetRemainingEnergy ();
446
  // motor + modem idle energy
447
  double estimated = 20 * 49 + 0.158 * 54;
448
449
  NS_TEST_ASSERT_MSG_EQ_TOL (consumed, estimated, 1.0e-5,
450
                             "Incorrect consumed energy!");
451
}
452
453
// -------------------------------------------------------------------------- //
454
455
/**
456
 * Unit test suite for underwater energy model. Include test on acoustic modem,
457
 * acoustic modem energy depletion, glider energy model, remus energy model.
458
 */
459
class AuvEnergyModelTestSuite : public TestSuite
460
{
461
public:
462
  AuvEnergyModelTestSuite ();
463
};
464
465
AuvEnergyModelTestSuite::AuvEnergyModelTestSuite ()
466
  : TestSuite ("auv-energy-model", UNIT)
467
{
468
  AddTestCase (new AcousticModemEnergyTestCase, TestCase::QUICK);
469
  AddTestCase (new AcousticModemEnergyDepletionTestCase, TestCase::QUICK);
470
  AddTestCase (new GliderEnergyTestCase, TestCase::QUICK);
471
  AddTestCase (new RemusEnergyTestCase, TestCase::QUICK);
472
}
473
474
// create an instance of the test suite
475
AuvEnergyModelTestSuite g_auvEnergyModelTestSuite;
476
477
} // namespace ns3
(-)a/src/auv/test/auv-mobility-test.cc (+431 lines)
Line 0    Link Here 
1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2010 Andrea Sacco
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: Andrea Sacco <andrea.sacco85@gmail.com>
19
 */
20
21
#include "ns3/remus-mobility-model.h"
22
#include "ns3/glider-mobility-model.h"
23
#include "ns3/auv-waypoint-mobility-model.h"
24
#include "ns3/test.h"
25
#include "ns3/simulator.h"
26
#include "ns3/node.h"
27
#include "ns3/nstime.h"
28
#include "ns3/vector.h"
29
#include "ns3/log.h"
30
#include "ns3/gnuplot.h"
31
#include "ns3/auv-glider-helper.h"
32
#include "ns3/auv-remus-helper.h"
33
#include "ns3/uan-channel.h"
34
#include "ns3/uan-noise-model-default.h"
35
#include "ns3/uan-prop-model-ideal.h"
36
#include "ns3/uan-net-device.h"
37
#include "ns3/uan-helper.h"
38
39
#include <cmath>
40
#include <iomanip>
41
42
using namespace ns3;
43
44
class RemusMobilityTestCase : public TestCase
45
{
46
public:
47
  RemusMobilityTestCase (void);
48
  ~RemusMobilityTestCase (void);
49
50
  virtual void DoRun (void);
51
  void DoSubmergeTest (void);
52
  void DoEmergeTest (void);
53
  void DoNavigationTest (int16_t dir);
54
55
private:
56
  void SubmergeCb (Ptr<MobilityModel> mob);
57
  void EmergeCb (Ptr<MobilityModel> mob);
58
  void SpeedCb (int16_t dir);
59
60
  Ptr<RemusMobilityModel> m_remusMob;
61
};
62
63
RemusMobilityTestCase::RemusMobilityTestCase ()
64
  : TestCase ("Test the Remus mobility model")
65
{
66
}
67
68
RemusMobilityTestCase::~RemusMobilityTestCase ()
69
{
70
  m_remusMob = 0;
71
}
72
73
void
74
RemusMobilityTestCase::DoSubmergeTest (void)
75
{
76
  m_remusMob->SetSubmergeCallback (MakeCallback (&RemusMobilityTestCase::SubmergeCb,
77
                                                 this));
78
  // makes the vehicle submerge to 100m
79
  m_remusMob->Submerge (-100);
80
}
81
82
void
83
RemusMobilityTestCase::DoEmergeTest (void)
84
{
85
  m_remusMob->SetEmergeCallback (MakeCallback (&RemusMobilityTestCase::EmergeCb,
86
                                               this));
87
  m_remusMob->Emerge (0);
88
}
89
90
void
91
RemusMobilityTestCase::DoNavigationTest (int16_t dir)
92
{
93
94
  if (dir == 1)
95
    {
96
      m_remusMob->SetPitch (0.);
97
      m_remusMob->SetDirection (90);
98
      m_remusMob->SetSpeed (2);
99
    }
100
  if (dir == -1)
101
    {
102
      m_remusMob->SetVelocity (Vector (0,-2,0));
103
    }
104
105
  Simulator::Schedule (Seconds (2),
106
                       &RemusMobilityTestCase::SpeedCb,
107
                       this,
108
                       dir);
109
}
110
111
void
112
RemusMobilityTestCase::SubmergeCb (Ptr<MobilityModel> mob)
113
{
114
  double depth = m_remusMob->GetDepth ();
115
116
  // depth should be -100
117
  NS_ASSERT (depth == -100);
118
}
119
120
void
121
RemusMobilityTestCase::EmergeCb (Ptr<MobilityModel> mob)
122
{
123
  double depth = m_remusMob->GetDepth ();
124
125
  // the depth should be 0m
126
  NS_ASSERT (depth == 0);
127
}
128
129
void
130
RemusMobilityTestCase::SpeedCb (int16_t dir)
131
{
132
  Vector pos = m_remusMob->GetPosition ();
133
134
  if (dir == 1)
135
    {
136
      // after 2 seconds along +y at 2m/s
137
      NS_ASSERT (pos.y == 4);
138
    }
139
  if (dir == -1)
140
    {
141
      // after 2 seconds along -y at 2m/s
142
      NS_ASSERT (pos.y == 0);
143
    }
144
145
  m_remusMob->Stop ();
146
}
147
148
void
149
RemusMobilityTestCase::DoRun (void)
150
{
151
  Ptr<Node> auv = CreateObject<Node> ();
152
153
  // create a default underwater channel
154
  Ptr<UanChannel> channel = CreateObject<UanChannel> ();
155
  Ptr<UanNoiseModelDefault> noise = CreateObject<UanNoiseModelDefault> ();
156
  channel->SetPropagationModel (CreateObject<UanPropModelIdeal> ());
157
  channel->SetNoiseModel (noise);
158
159
  // install the underwater communication stack
160
  UanHelper uan;
161
  Ptr<UanNetDevice> devNode = uan.Install (auv, channel);
162
163
  AuvRemusHelper helper;
164
  helper.Install (auv);
165
166
  m_remusMob = auv->GetObject<AuvWaypointMobilityModel> ()->GetValidatorMobilityModel ()->GetObject<RemusMobilityModel> ();
167
  NS_ASSERT (m_remusMob != NULL);
168
169
  m_remusMob->SetPosition (Vector (0.,0.,0.));
170
171
  Time now = Simulator::Now ();
172
173
  // submerge
174
  Simulator::Schedule (now,
175
                       &RemusMobilityTestCase::DoSubmergeTest,
176
                       this);
177
178
  // emerge
179
  now += Seconds (100);
180
  Simulator::Schedule (now,
181
                       &RemusMobilityTestCase::DoEmergeTest,
182
                       this);
183
184
  // direction, pitch, speed
185
  now += Seconds (100);
186
  Simulator::Schedule (now,
187
                       &RemusMobilityTestCase::DoNavigationTest,
188
                       this,
189
                       1);
190
191
  // velocity
192
  now += Seconds (100);
193
  Simulator::Schedule (now,
194
                       &RemusMobilityTestCase::DoNavigationTest,
195
                       this,
196
                       -1);
197
198
  Simulator::Run ();
199
  Simulator::Destroy ();
200
}
201
202
class GliderMobilityTestCase : public TestCase
203
{
204
public:
205
  GliderMobilityTestCase (void);
206
  ~GliderMobilityTestCase (void);
207
208
  virtual void DoRun (void);
209
  void DoSubmergeTest (void);
210
  void DoEmergeTest (void);
211
  void DoNavigationTest (int16_t dir);
212
  void DoBuoyancyTest (void);
213
214
private:
215
  void SubmergeCb (Ptr<MobilityModel> mob);
216
  void EmergeCb (Ptr<MobilityModel> mob);
217
  void SpeedCb (int16_t dir);
218
219
  Ptr<GliderMobilityModel> m_gliderMob;
220
  EventId m_id;
221
  Vector m_lastEndPos;
222
};
223
224
GliderMobilityTestCase::GliderMobilityTestCase ()
225
  : TestCase ("Test the Seaglider mobility model")
226
{
227
}
228
229
GliderMobilityTestCase::~GliderMobilityTestCase ()
230
{
231
  m_gliderMob = 0;
232
}
233
234
void
235
GliderMobilityTestCase::DoSubmergeTest (void)
236
{
237
  m_gliderMob->SetSubmergeCallback (MakeCallback (&GliderMobilityTestCase::SubmergeCb,
238
                                                  this));
239
  // submerge to 1000m
240
  m_gliderMob->Submerge (-1000);
241
}
242
243
void
244
GliderMobilityTestCase::DoEmergeTest (void)
245
{
246
  m_gliderMob->SetEmergeCallback (MakeCallback (&GliderMobilityTestCase::EmergeCb,
247
                                                this));
248
  // emerge to water surface
249
  m_gliderMob->Emerge (0);
250
}
251
252
void
253
GliderMobilityTestCase::DoNavigationTest (int16_t dir)
254
{
255
256
  if (dir == 1)
257
    {
258
      m_gliderMob->SetPitch (-60);
259
      m_gliderMob->SetDirection (45);
260
      m_gliderMob->SetSpeed (0.3);
261
    }
262
  else if (dir == -1)
263
    {
264
      m_gliderMob->SetVelocity (Vector (0.2, -0.2, 0.2));
265
    }
266
267
  // proceed along the set direction for 60 seconds
268
  Simulator::Schedule (Seconds (60),
269
                       &GliderMobilityTestCase::SpeedCb,
270
                       this,
271
                       dir);
272
}
273
274
void
275
GliderMobilityTestCase::DoBuoyancyTest (void)
276
{
277
  double U = 0.25;
278
  double W = 0.3;
279
280
  m_gliderMob->SetVelocity (Vector (U, .0, W));
281
282
  double buoyancy = m_gliderMob->GetBuoyancy ();
283
284
  // test the buoyancy error against 1e-15 tolerance
285
  NS_ASSERT ((buoyancy - 139.05836821925641) < 1e-15);
286
}
287
288
void
289
GliderMobilityTestCase::SubmergeCb (Ptr<MobilityModel> mob)
290
{
291
  double depth = m_gliderMob->GetDepth ();
292
293
  // depth should be -1000
294
  NS_ASSERT (depth == -1000);
295
296
  m_lastEndPos = m_gliderMob->GetPosition ();
297
}
298
299
void
300
GliderMobilityTestCase::EmergeCb (Ptr<MobilityModel> mob)
301
{
302
  double depth = m_gliderMob->GetDepth ();
303
304
  // the depth should be 0m
305
  NS_ASSERT (depth == 0);
306
307
  m_lastEndPos = m_gliderMob->GetPosition ();
308
}
309
310
void
311
GliderMobilityTestCase::SpeedCb (int16_t dir)
312
{
313
  Vector pos = m_gliderMob->GetPosition ();
314
315
  if (dir == 1)
316
    {
317
      double x = pos.x - m_lastEndPos.x;
318
      double y = pos.y - m_lastEndPos.y;
319
      double z = pos.z - m_lastEndPos.z;
320
321
      double dx = x - (std::cos (45 * M_PI / 180) * std::cos (-60 * M_PI / 180) * 0.3 * 60);
322
      double dy = y - (std::sin (45 * M_PI / 180) * std::cos (-60 * M_PI / 180) * 0.3 * 60);
323
      double dz = z - (std::sin (-60 * M_PI / 180) * 0.3 * 60);
324
325
      // test the error against 0.1 mm tolerance
326
      NS_ASSERT (dx < 1e-4);
327
      NS_ASSERT (dy < 1e-4);
328
      NS_ASSERT (dz < 1e-4);
329
330
      m_lastEndPos = pos;
331
    }
332
  if (dir == -1)
333
    {
334
      double x = pos.x - m_lastEndPos.x;
335
      double y = pos.y - m_lastEndPos.y;
336
      double z = pos.z - m_lastEndPos.z;
337
338
      double dx = x - 0.2 * 60;
339
      double dy = y - (-0.2) * 60;
340
      double dz = z - 0.2 * 60;
341
342
      // test the error against 0.1 mm tolerance
343
      NS_ASSERT (dx < 1e-4);
344
      NS_ASSERT (dy < 1e-4);
345
      NS_ASSERT (dz < 1e-4);
346
347
      m_lastEndPos = pos;
348
349
      Simulator::Cancel (m_id);
350
    }
351
352
  m_gliderMob->Stop ();
353
}
354
355
void
356
GliderMobilityTestCase::DoRun (void)
357
{
358
  Ptr<Node> auv = CreateObject<Node> ();
359
360
  // create a default underwater channel
361
  Ptr<UanChannel> channel = CreateObject<UanChannel> ();
362
  Ptr<UanNoiseModelDefault> noise = CreateObject<UanNoiseModelDefault> ();
363
  channel->SetPropagationModel (CreateObject<UanPropModelIdeal> ());
364
  channel->SetNoiseModel (noise);
365
366
  // install the underwater communication stack
367
  UanHelper uan;
368
  Ptr<UanNetDevice> devNode = uan.Install (auv, channel);
369
370
  AuvGliderHelper helper;
371
  helper.Install (auv);
372
373
  m_gliderMob = auv->GetObject<AuvWaypointMobilityModel> ()->GetValidatorMobilityModel ()->GetObject<GliderMobilityModel> ();
374
  NS_ASSERT (m_gliderMob != NULL);
375
376
  // deploy the AUV
377
  m_gliderMob->SetPosition (Vector (0.,0.,0.));
378
379
  // buoyancy
380
  DoBuoyancyTest ();
381
382
  Time now = Simulator::Now ();
383
384
  // submerge
385
  Simulator::Schedule (now,
386
                       &GliderMobilityTestCase::DoSubmergeTest,
387
                       this);
388
389
  // emerge
390
  now += Seconds (2010);
391
  Simulator::Schedule (now,
392
                       &GliderMobilityTestCase::DoEmergeTest,
393
                       this);
394
395
  // direction, pitch, speed
396
  now += Seconds (2010);
397
  Simulator::Schedule (now,
398
                       &GliderMobilityTestCase::DoNavigationTest,
399
                       this,
400
                       1);
401
402
  // velocity
403
  now += Seconds (100);
404
  Simulator::Schedule (now,
405
                       &GliderMobilityTestCase::DoNavigationTest,
406
                       this,
407
                       -1);
408
409
  now += Seconds (100);
410
411
  Simulator::Stop (now);
412
  Simulator::Run ();
413
  Simulator::Destroy ();
414
415
}
416
417
// -------------------------------------------------------------------------- //
418
419
/**
420
 * Unit test suite for AUV mobility model.
421
 * Glider mobility test: a simulation of buoyancy value, submerge, emerge and
422
 *                       basic navigation.
423
 * REMUS mobility test: a simulation of submerge, emerge and
424
 *                       basic navigation.
425
 */
426
class AuvMobilityTestSuite : public TestSuite
427
{
428
public:
429
  AuvMobilityTestSuite ();
430
};
431
(-)a/src/auv/test/examples-to-run.py (+18 lines)
Line 0    Link Here 
1
#! /usr/bin/env python
2
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
3
4
# A list of C++ examples to run in order to ensure that they remain
5
# buildable and runnable over time.  Each tuple in the list contains
6
#
7
#     (example_name, do_run, do_valgrind_run).
8
#
9
# See test.py for more information.
10
cpp_examples = []
11
12
# A list of Python examples to run in order to ensure that they remain
13
# runnable over time.  Each tuple in the list contains
14
#
15
#     (example_name, do_run).
16
#
17
# See test.py for more information.
18
python_examples = []
(-)a/src/auv/wscript (+41 lines)
Line 0    Link Here 
1
# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
3
def build(bld):
4
    module = bld.create_ns3_module('auv', ['uan', 'mobility', 'energy'])
5
    module.source = [
6
		'model/auv-mobility-model.cc',
7
                'model/glider-mobility-model.cc',
8
                'model/remus-mobility-model.cc',
9
                'model/glider-energy-model.cc',
10
                'model/remus-energy-model.cc',
11
                'model/auv-waypoint-mobility-model.cc',
12
                'helper/auv-mobility-helper.cc',
13
                'helper/auv-glider-helper.cc',
14
                'helper/auv-remus-helper.cc',
15
        ]
16
17
    module_test = bld.create_ns3_module_test_library('auv')
18
    module_test.source = [
19
        'test/auv-mobility-test.cc',
20
        'test/auv-energy-model-test.cc',
21
        ]
22
23
24
    headers = bld(features='ns3header')
25
    headers.module = 'auv'
26
    headers.source = [
27
		'model/auv-mobility-model.h',
28
                'model/glider-mobility-model.h',
29
                'model/remus-mobility-model.h',
30
                'model/glider-energy-model.h',
31
                'model/remus-energy-model.h',
32
                'model/auv-waypoint-mobility-model.h',
33
                'helper/auv-mobility-helper.h',
34
                'helper/auv-glider-helper.h',
35
                'helper/auv-remus-helper.h',
36
        ]
37
38
    if bld.env.ENABLE_EXAMPLES:
39
        bld.recurse('examples')
40
        
41
        bld.ns3_python_bindings()

Return to bug 2404