A Discrete-Event Network Simulator
API
 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
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),
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
88  sem,
89  4.66);
90  now += Seconds (600);
91 
92  PrintCellInfo (es);
93 
94  Simulator::Stop (now);
95  Simulator::Run ();
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 }
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:79
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:60
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
static void Run(void)
Run the simulation until one of:
Definition: simulator.cc:157
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:825
virtual double GetRemainingEnergy(void)
double GetSeconds(void) const
Definition: nstime.h:272
int main(int argc, char **argv)
void AggregateObject(Ptr< Object > other)
Definition: object.cc:242
double Get(void) const
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition: simulator.cc:121
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
static void PrintCellInfo(Ptr< LiIonEnergySource > es)
In this simple example, we show how to create and drain energy from a LiIonEnergySource.
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
virtual double GetSupplyVoltage(void) const
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
Hold a floating point type.
Definition: double.h:41