A Discrete-Event Network Simulator
API
generic-battery-model.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 Andrea Sacco: Li-Ion battery
3  * Copyright (c) 2023 Tokushima University, Japan:
4  * NiMh,NiCd,LeaAcid batteries and preset and multi-cell extensions.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Author: Andrea Sacco <andrea.sacco85@gmail.com>
20  * Alberto Gallegos Ramonet <alramonet@is.tokushima-u.ac.jp>
21  */
22 
23 #ifndef GENERIC_BATTERY_MODEL_H
24 #define GENERIC_BATTERY_MODEL_H
25 
26 #include "energy-source.h"
27 
28 #include <ns3/event-id.h>
29 #include <ns3/nstime.h>
30 #include <ns3/traced-value.h>
31 
32 namespace ns3
33 {
34 
43 {
44  LION_LIPO = 0,
45  NIMH_NICD = 1,
46  LEADACID = 2
47 };
48 
55 {
61 };
62 
70 {
72  std::string description;
73  double vFull;
74  double qMax;
75  double vNom;
76  double qNom;
77  double vExp;
78  double qExp;
80  double typicalCurrent;
81  double cuttoffVoltage;
82 };
83 
90  "Panasonic HHR650D | NiMH | 1.2V 6.5Ah | Size: D",
91  1.39,
92  7.0,
93  1.18,
94  6.25,
95  1.28,
96  1.3,
97  0.0046,
98  1.3,
99  1.0},
100  {LEADACID,
101  "CSB GP1272 | Lead Acid | 12V 7.2Ah",
102  12.8,
103  7.2,
104  11.5,
105  4.5,
106  12.5,
107  2,
108  0.056,
109  0.36,
110  8.0},
111  {LION_LIPO,
112  "Panasonic CGR18650DA | Li-Ion | 3.6V 2.45Ah | Size: A",
113  4.17,
114  2.33,
115  3.57,
116  2.14,
117  3.714,
118  1.74,
119  0.0830,
120  0.466,
121  3.0},
122  {LEADACID,
123  "Rs PRO LGP12100 | Lead Acid | 12V 100Ah",
124  12.60,
125  130,
126  12.44,
127  12.3,
128  12.52,
129  12,
130  0.00069,
131  5,
132  11},
133  {NIMH_NICD,
134  "PANASONIC N-700AAC | NiCd | 1.2V 700mAh | Size: AA",
135  1.38,
136  0.790,
137  1.17,
138  0.60,
139  1.25,
140  0.24,
141  0.016,
142  0.7,
143  0.8}};
144 
153 {
154  public:
159  static TypeId GetTypeId();
160 
162 
163  ~GenericBatteryModel() override;
164 
173  double GetInitialEnergy() const override;
174 
180  double GetSupplyVoltage() const override;
181 
187  double GetRemainingEnergy() override;
188 
195  double GetEnergyFraction() override;
196 
200  void UpdateEnergySource() override;
201 
207  void SetEnergyUpdateInterval(Time interval);
208 
217  void SetDrainedCapacity(double drainedCapacity);
218 
225  double GetDrainedCapacity() const;
226 
233  double GetStateOfCharge() const;
234 
239 
240  private:
241  void DoInitialize() override;
242  void DoDispose() override;
243 
249  void BatteryDepletedEvent();
250 
256  void BatteryChargedEvent();
257 
267 
276  double GetVoltage(double current);
277 
284  double GetChargeVoltage(double current);
285 
286  private:
290  double m_entn;
292  double m_expZone;
296  double m_lowBatteryTh;
300  double m_vFull;
301  double m_vNom;
302  double m_vExp;
304  double m_qMax;
305  double m_qNom;
306  double m_qExp;
310 };
311 
312 } // namespace ns3
313 
314 #endif /* GENERIC_BATTERY_MODEL_H */
An identifier for simulation events.
Definition: event-id.h:55
A generic battery model for Li-Ion, NiCd, NiMh and Lead acid batteries.
double m_entn
The previous value of the exponential zone in NiMh,NiCd and LeadAcid.
double m_expZone
Voltage value of the exponential zone.
void BatteryChargedEvent()
Handles the battery reaching its full voltage.
double GetEnergyFraction() override
Implements GetEnergyFraction.
Time m_lastUpdateTime
Last update time.
double m_lowBatteryTh
Low battery threshold, as a fraction of the initial energy.
double m_typicalCurrent
Typical discharge current used to fit the curves.
double GetStateOfCharge() const
Calculates an estimate of the State of Charge (SoC).
double GetDrainedCapacity() const
Obtain the amount of drained capacity from the battery based on the integral of the current over time...
Time m_energyUpdateInterval
Energy update interval.
void UpdateEnergySource() override
Implements UpdateEnergySource.
double m_currentFiltered
The step response (a.k.a.
double m_qMax
The maximum capacity of the battery, in Ah.
void CalculateRemainingEnergy()
Calculates remaining energy.
double GetVoltage(double current)
Get the battery voltage in function of the discharge current.
void DoInitialize() override
Initialize() implementation.
double m_vExp
Battery voltage at the end of the exponential zone, in Volts.
TracedValue< double > m_remainingEnergyJ
Remaining energy, in Joules.
double GetSupplyVoltage() const override
Implements GetSupplyVoltage.
double m_vNom
Nominal voltage of the battery, in Volts.
EventId m_energyUpdateEvent
Energy update event.
double GetChargeVoltage(double current)
Obtain the battery voltage as a result of a charge current.
double GetRemainingEnergy() override
Implements GetRemainingEnergy.
double m_internalResistance
Internal resistance of the battery, in Ohms.
void SetEnergyUpdateInterval(Time interval)
This function sets the interval between each energy update.
void DoDispose() override
All child's implementation must call BreakDeviceEnergyModelRefCycle to ensure reference cycles to Dev...
GenericBatteryType m_batteryType
Indicates the battery type used by the model.
double m_qNom
Battery capacity at the end of the nominal zone, in Ah.
static TypeId GetTypeId()
Get the type ID.
double m_vFull
Initial voltage of the battery, in Volts.
double m_drainedCapacity
Capacity drained from the battery, in Ah.
Time m_energyUpdateLapseTime
The lapse of time between the last battery energy update and the current time.
double m_cutoffVoltage
The threshold voltage where the battery is considered depleted.
void SetDrainedCapacity(double drainedCapacity)
This function is used to change the initial capacity in the battery.
double m_qExp
Capacity value at the end of the exponential zone, in Ah.
void BatteryDepletedEvent()
Handles the battery reaching its cutoff voltage.
double GetInitialEnergy() const override
Implements GetInitialEnergy.
double m_supplyVoltageV
Actual voltage of the battery.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
GenericBatteryType
Battery types.
static BatteryPresets g_batteryPreset[]
Contains the values that form the battery presents available in this module.
BatteryModel
Battery models that described the parameters of the the battery presets.
@ NIMH_NICD
Nickel-metal hydride and Nickel cadmium batteries.
@ LION_LIPO
Lithium-ion and Lithium-polymer batteries.
@ LEADACID
Lead Acid Batteries.
@ PANASONIC_CGR18650DA_LION
Panasonic CGR18650DA Li-Ion battery.
@ CSB_GP1272_LEADACID
CSB GP1272 Lead acid battery.
@ PANASONIC_HHR650D_NIMH
Panasonic HHR650D NiMh battery.
@ RSPRO_LGP12100_LEADACID
RS Pro LGP12100 Lead acid battery.
@ PANASONIC_N700AAC_NICD
Panasonic N700AAC NiCd battery.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
The structure containing the the parameter values that describe a battery preset.
std::string description
Additional information about the battery.
double cuttoffVoltage
The threshold voltage where the battery is considered depleted.
double qExp
Capacity value at the end of the exponential zone, in Ah.
double vExp
Battery voltage at the end of the exponential zone, in Volts.
GenericBatteryType batteryType
The type of battery used in the preset.
double internalResistance
Internal resistance of the battery, in Ohms.
double vFull
Initial voltage of the battery, in Volts.
double qNom
Battery capacity at the end of the nominal zone, in Ah.
double typicalCurrent
Typical discharge current used to fit the curves.
double vNom
Nominal voltage of the battery, in Volts.
double qMax
The maximum capacity of the battery, in Ah.