A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
23
try
:
24
from
ns
import
ns
25
except
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
33
def
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.LogComponentEnable("GenericBatteryModel"
, ns.LOG_LEVEL_DEBUG)
41
42
node = ns.Node()
43
batteryHelper = ns.GenericBatteryModelHelper()
44
batteryModel = ns.CreateObject[ns.energy.GenericBatteryModel]()
45
devicesEnergyModel = ns.energy.SimpleDeviceEnergyModel()
46
47
batteryModel.SetAttribute(
"FullVoltage"
, ns.DoubleValue(1.39))
# Vfull
48
batteryModel.SetAttribute(
"MaxCapacity"
, ns.DoubleValue(7.0))
# Q
49
50
batteryModel.SetAttribute(
"NominalVoltage"
, ns.DoubleValue(1.18))
# Vnom
51
batteryModel.SetAttribute(
"NominalCapacity"
, ns.DoubleValue(6.25))
# QNom
52
53
batteryModel.SetAttribute(
"ExponentialVoltage"
, ns.DoubleValue(1.28))
# Vexp
54
batteryModel.SetAttribute(
"ExponentialCapacity"
, ns.DoubleValue(1.3))
# Qexp
55
56
batteryModel.SetAttribute(
"InternalResistance"
, ns.DoubleValue(0.0046))
# R
57
batteryModel.SetAttribute(
"TypicalDischargeCurrent"
, ns.DoubleValue(1.3))
# i typical
58
batteryModel.SetAttribute(
"CutoffVoltage"
, ns.DoubleValue(1.0))
# End of charge.
59
60
batteryModel.SetAttribute(
61
"BatteryType"
, ns.EnumValue[ns.energy.GenericBatteryType](ns.energy.NIMH_NICD)
62
)
# Battery type
63
64
devicesEnergyModel.SetEnergySource(batteryModel)
65
batteryModel.AppendDeviceEnergyModel(devicesEnergyModel)
66
devicesEnergyModel.SetNode(node)
67
68
devicesEnergyModel.SetCurrentA(6.5)
69
70
ns.Simulator.Stop(ns.Seconds(3600))
71
ns.Simulator.Run()
72
ns.Simulator.Destroy()
73
74
75
if
__name__ ==
"__main__"
:
76
import
sys
77
78
main(sys.argv)
src
energy
examples
generic-battery-discharge-example.py
Generated on Tue May 28 2024 23:35:14 for ns-3 by
1.9.6