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
# SPDX-License-Identifier: GPL-2.0-only
4
#
5
# Author: Alberto Gallegos Ramonet <alramonet@is.tokushima-u.ac.jp>
6
#
7
8
# Panasonic HHR650D NiMh battery (single cell)
9
# Demonstrates the discharge behavior of a NIMH battery discharged with a
10
# constant current of 6.5 A (1C)
11
12
try
:
13
from
ns
import
ns
14
except
ModuleNotFoundError:
15
raise
SystemExit(
16
"Error: ns3 Python module not found;"
17
" Python bindings may not be enabled"
18
" or your PYTHONPATH might not be properly configured"
19
)
20
21
22
def
main(argv):
23
"""The main function in this Battery discharge example
24
25
Parameters:
26
argv: System parameters to use if necessary
27
"""
28
29
ns.LogComponentEnable(
"GenericBatteryModel"
, ns.LOG_LEVEL_DEBUG)
30
31
node = ns.Node()
32
batteryHelper = ns.GenericBatteryModelHelper()
33
batteryModel = ns.CreateObject[ns.energy.GenericBatteryModel]()
34
devicesEnergyModel = ns.energy.SimpleDeviceEnergyModel()
35
36
batteryModel.SetAttribute(
"FullVoltage"
, ns.DoubleValue(1.39))
# Vfull
37
batteryModel.SetAttribute(
"MaxCapacity"
, ns.DoubleValue(7.0))
# Q
38
39
batteryModel.SetAttribute(
"NominalVoltage"
, ns.DoubleValue(1.18))
# Vnom
40
batteryModel.SetAttribute(
"NominalCapacity"
, ns.DoubleValue(6.25))
# QNom
41
42
batteryModel.SetAttribute(
"ExponentialVoltage"
, ns.DoubleValue(1.28))
# Vexp
43
batteryModel.SetAttribute(
"ExponentialCapacity"
, ns.DoubleValue(1.3))
# Qexp
44
45
batteryModel.SetAttribute(
"InternalResistance"
, ns.DoubleValue(0.0046))
# R
46
batteryModel.SetAttribute(
"TypicalDischargeCurrent"
, ns.DoubleValue(1.3))
# i typical
47
batteryModel.SetAttribute(
"CutoffVoltage"
, ns.DoubleValue(1.0))
# End of charge.
48
49
batteryModel.SetAttribute(
50
"BatteryType"
, ns.EnumValue[ns.energy.GenericBatteryType](ns.energy.NIMH_NICD)
51
)
# Battery type
52
53
devicesEnergyModel.SetEnergySource(batteryModel)
54
batteryModel.AppendDeviceEnergyModel(devicesEnergyModel)
55
devicesEnergyModel.SetNode(node)
56
57
devicesEnergyModel.SetCurrentA(6.5)
58
59
ns.Simulator.Stop(ns.Seconds(3600))
60
ns.Simulator.Run()
61
ns.Simulator.Destroy()
62
63
64
if
__name__ ==
"__main__"
:
65
import
sys
66
67
main(sys.argv)
src
energy
examples
generic-battery-discharge-example.py
Generated on Fri Nov 8 2024 13:59:00 for ns-3 by
1.11.0