A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
li-ion-energy-source.cc
Go to the documentation of this file.
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/simulator.h"
23
#include "ns3/simple-device-energy-model.h"
24
#include "ns3/li-ion-energy-source.h"
25
#include "ns3/energy-source-container.h"
26
27
using namespace
ns3;
28
46
static
void
47
PrintCellInfo
(
Ptr<LiIonEnergySource>
es)
48
{
49
std::cout <<
"At "
<<
Simulator::Now
().
GetSeconds
() <<
" Cell voltage: "
<< es->
GetSupplyVoltage
() <<
" V Remaining Capacity: "
<<
50
es->
GetRemainingEnergy
() / (3.6 * 3600) <<
" Ah"
<< std::endl;
51
52
if
(!
Simulator::IsFinished
())
53
{
54
Simulator::Schedule
(Seconds (20),
55
&
PrintCellInfo
,
56
es);
57
}
58
}
59
60
int
61
main
(
int
argc,
char
**argv)
62
{
63
// uncomment below to see the energy consumption details
64
// LogComponentEnable ("LiIonEnergySource", LOG_LEVEL_DEBUG);
65
66
Ptr<Node>
node = CreateObject<Node> ();
67
68
Ptr<SimpleDeviceEnergyModel>
sem = CreateObject<SimpleDeviceEnergyModel> ();
69
Ptr<EnergySourceContainer>
esCont = CreateObject<EnergySourceContainer> ();
70
Ptr<LiIonEnergySource>
es = CreateObject<LiIonEnergySource> ();
71
esCont->Add (es);
72
es->SetNode (node);
73
sem->SetEnergySource (es);
74
es->AppendDeviceEnergyModel (sem);
75
sem->SetNode (node);
76
node->
AggregateObject
(esCont);
77
78
Time
now =
Simulator::Now
();
79
80
// discharge at 2.33 A for 1700 seconds
81
sem->SetCurrentA (2.33);
82
now += Seconds (1701);
83
84
85
// discharge at 4.66 A for 628 seconds
86
Simulator::Schedule
(now,
87
&
SimpleDeviceEnergyModel::SetCurrentA
,
88
sem,
89
4.66);
90
now += Seconds (600);
91
92
PrintCellInfo
(es);
93
94
Simulator::Stop
(now);
95
Simulator::Run
();
96
Simulator::Destroy
();
97
98
// the cell voltage should be under 3.3v
99
DoubleValue
v;
100
es->GetAttribute (
"ThresholdVoltage"
, v);
101
NS_ASSERT
(es->GetSupplyVoltage () <= v.
Get
());
102
}
ns3::Time
keep track of time values and allow control of global simulation resolution
Definition:
nstime.h:81
ns3::Ptr
smart pointer class similar to boost::intrusive_ptr
Definition:
ptr.h:59
NS_ASSERT
#define NS_ASSERT(condition)
Definition:
assert.h:64
ns3::Simulator::Run
static void Run(void)
Run the simulation until one of:
Definition:
simulator.cc:157
ns3::Simulator::Schedule
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Definition:
simulator.h:824
ns3::LiIonEnergySource::GetRemainingEnergy
virtual double GetRemainingEnergy(void)
Definition:
li-ion-energy-source.cc:167
ns3::Time::GetSeconds
double GetSeconds(void) const
Definition:
nstime.h:274
ns3::SimpleDeviceEnergyModel::SetCurrentA
void SetCurrentA(double current)
Definition:
simple-device-energy-model.cc:91
main
int main(int argc, char **argv)
Definition:
li-ion-energy-source.cc:61
ns3::Object::AggregateObject
void AggregateObject(Ptr< Object > other)
Definition:
object.cc:243
ns3::DoubleValue::Get
double Get(void) const
ns3::Simulator::Destroy
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition:
simulator.cc:121
ns3::Simulator::Now
static Time Now(void)
Return the "current simulation time".
Definition:
simulator.cc:180
PrintCellInfo
static void PrintCellInfo(Ptr< LiIonEnergySource > es)
In this simple example, we show how to create and drain energy from a LiIonEnergySource.
Definition:
li-ion-energy-source.cc:47
ns3::Simulator::Stop
static void Stop(void)
If an event invokes this method, it will be the last event scheduled by the Simulator::run method bef...
Definition:
simulator.cc:165
ns3::LiIonEnergySource::GetSupplyVoltage
virtual double GetSupplyVoltage(void) const
Definition:
li-ion-energy-source.cc:146
ns3::Simulator::IsFinished
static bool IsFinished(void)
If there are no more events lefts to be scheduled, or if simulation time has already reached the "sto...
Definition:
simulator.cc:150
ns3::DoubleValue
Hold a floating point type.
Definition:
double.h:41
src
energy
examples
li-ion-energy-source.cc
Generated on Sat Apr 19 2014 14:06:54 for ns-3 by
1.8.6