A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
generic-battery-discharge-example.py
Go to the documentation of this file.
1# Copyright (c) 2023 Tokushima University
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: Alberto Gallegos Ramonet <alramonet@is.tokushima-u.ac.jp>
17#
18
19# Panasonic HHR650D NiMh battery (single cell)
20# Demonstrates the discharge behavior of a NIMH battery discharged with a
21# constant current of 6.5 A (1C)
22
23try:
24 from ns import ns
25except ModuleNotFoundError:
26 raise SystemExit(
27 "Error: ns3 Python module not found;"
28 " Python bindings may not be enabled"
29 " or your PYTHONPATH might not be properly configured"
30 )
31
32
33def main(argv):
34 """The main function in this Battery discharge example
35
36 Parameters:
37 argv: System parameters to use if necessary
38 """
39
40 ns.core.LogComponentEnable("GenericBatteryModel", ns.core.LOG_LEVEL_DEBUG)
41
42 node = ns.network.Node()
43 batteryHelper = ns.energy.GenericBatteryModelHelper()
44 batteryModel = ns.CreateObject("GenericBatteryModel")
45 devicesEnergyModel = ns.energy.SimpleDeviceEnergyModel()
46
47 batteryModel.SetAttribute("FullVoltage", ns.core.DoubleValue(1.39)) # Vfull
48 batteryModel.SetAttribute("MaxCapacity", ns.core.DoubleValue(7.0)) # Q
49
50 batteryModel.SetAttribute("NominalVoltage", ns.core.DoubleValue(1.18)) # Vnom
51 batteryModel.SetAttribute("NominalCapacity", ns.core.DoubleValue(6.25)) # QNom
52
53 batteryModel.SetAttribute("ExponentialVoltage", ns.core.DoubleValue(1.28)) # Vexp
54 batteryModel.SetAttribute("ExponentialCapacity", ns.core.DoubleValue(1.3)) # Qexp
55
56 batteryModel.SetAttribute("InternalResistance", ns.core.DoubleValue(0.0046)) # R
57 batteryModel.SetAttribute("TypicalDischargeCurrent", ns.core.DoubleValue(1.3)) # i typical
58 batteryModel.SetAttribute("CutoffVoltage", ns.core.DoubleValue(1.0)) # End of charge.
59
60 batteryModel.SetAttribute("BatteryType", ns.core.EnumValue(ns.NIMH_NICD)) # Battery type
61
62 devicesEnergyModel.SetEnergySource(batteryModel)
63 batteryModel.AppendDeviceEnergyModel(devicesEnergyModel)
64 devicesEnergyModel.SetNode(node)
65
66 devicesEnergyModel.SetCurrentA(6.5)
67
68 ns.core.Simulator.Stop(ns.core.Seconds(3600))
69 ns.core.Simulator.Run()
70 ns.core.Simulator.Destroy()
71
72
73if __name__ == "__main__":
74 import sys
75
76 main(sys.argv)