A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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
32namespace ns3
33{
34namespace energy
35{
36
37/**
38 * \ingroup energy
39 *
40 * Battery types.
41 * These are grouped according to their chemical characteristics
42 * present during a charge/discharge curve.
43 */
45{
46 LION_LIPO = 0, //!< Lithium-ion and Lithium-polymer batteries
47 NIMH_NICD = 1, //!< Nickel-metal hydride and Nickel cadmium batteries
48 LEADACID = 2 //!< Lead Acid Batteries
49};
50
51/**
52 * \ingroup energy
53 *
54 * Battery models that described the parameters of the the battery presets.
55 */
57{
58 PANASONIC_HHR650D_NIMH = 0, //!< Panasonic HHR650D NiMh battery
59 CSB_GP1272_LEADACID = 1, //!< CSB GP1272 Lead acid battery
60 PANASONIC_CGR18650DA_LION = 2, //!< Panasonic CGR18650DA Li-Ion battery
61 RSPRO_LGP12100_LEADACID = 3, //!< RS Pro LGP12100 Lead acid battery
62 PANASONIC_N700AAC_NICD = 4 //!< Panasonic N700AAC NiCd battery
63};
64
65/**
66 * \ingroup energy
67 *
68 * The structure containing the the parameter values that describe a
69 * battery preset.
70 */
72{
73 GenericBatteryType batteryType; //!< The type of battery used in the preset.
74 std::string description; //!< Additional information about the battery.
75 double vFull; //!< Initial voltage of the battery, in Volts
76 double qMax; //!< The maximum capacity of the battery, in Ah
77 double vNom; //!< Nominal voltage of the battery, in Volts
78 double qNom; //!< Battery capacity at the end of the nominal zone, in Ah
79 double vExp; //!< Battery voltage at the end of the exponential zone, in Volts
80 double qExp; //!< Capacity value at the end of the exponential zone, in Ah
81 double internalResistance; //!< Internal resistance of the battery, in Ohms
82 double typicalCurrent; //!< Typical discharge current used to fit the curves
83 double cuttoffVoltage; //!< The threshold voltage where the battery is considered depleted
84};
85
86/**
87 * \ingroup energy
88 *
89 * Contains the values that form the battery presents available in this module.
90 */
92 "Panasonic HHR650D | NiMH | 1.2V 6.5Ah | Size: D",
93 1.39,
94 7.0,
95 1.18,
96 6.25,
97 1.28,
98 1.3,
99 0.0046,
100 1.3,
101 1.0},
102 {LEADACID,
103 "CSB GP1272 | Lead Acid | 12V 7.2Ah",
104 12.8,
105 7.2,
106 11.5,
107 4.5,
108 12.5,
109 2,
110 0.056,
111 0.36,
112 8.0},
113 {LION_LIPO,
114 "Panasonic CGR18650DA | Li-Ion | 3.6V 2.45Ah | Size: A",
115 4.17,
116 2.33,
117 3.57,
118 2.14,
119 3.714,
120 1.74,
121 0.0830,
122 0.466,
123 3.0},
124 {LEADACID,
125 "Rs PRO LGP12100 | Lead Acid | 12V 100Ah",
126 12.60,
127 130,
128 12.44,
129 12.3,
130 12.52,
131 12,
132 0.00069,
133 5,
134 11},
135 {NIMH_NICD,
136 "PANASONIC N-700AAC | NiCd | 1.2V 700mAh | Size: AA",
137 1.38,
138 0.790,
139 1.17,
140 0.60,
141 1.25,
142 0.24,
143 0.016,
144 0.7,
145 0.8}};
146
147/**
148 * \ingroup energy
149 * \brief A generic battery model for Li-Ion, NiCd, NiMh and Lead acid batteries
150 *
151 * The generic battery model can be used to describe the discharge behavior of
152 * the battery chemestries supported by the model.
153 */
155{
156 public:
157 /**
158 * \brief Get the type ID.
159 * \return The object TypeId.
160 */
161 static TypeId GetTypeId();
162
164
165 ~GenericBatteryModel() override;
166
167 /**
168 * Implements GetInitialEnergy. It returns the amount of energy in Joules stored in the
169 * battery when fully charged. This energy is different to the total amount of usable energy
170 * in the battery. This is because the battery cannot be used until Voltage = 0, only until
171 * it reaches the cutoff voltage.
172 *
173 * \return The initial energy stored in the fully charged battery, in Joules.
174 */
175 double GetInitialEnergy() const override;
176
177 /**
178 * Implements GetSupplyVoltage.
179 *
180 * \return Supply voltage at the energy source.
181 */
182 double GetSupplyVoltage() const override;
183
184 /**
185 * Implements GetRemainingEnergy.
186 *
187 * \return Remaining energy in energy source, in Joules
188 */
189 double GetRemainingEnergy() override;
190
191 /**
192 * Implements GetEnergyFraction. For the generic battery model, energy fraction
193 * is equivalent to the remaining usable capacity (i.e. The SoC).
194 *
195 * \return Energy fraction.
196 */
197 double GetEnergyFraction() override;
198
199 /**
200 * Implements UpdateEnergySource.
201 */
202 void UpdateEnergySource() override;
203
204 /**
205 * This function sets the interval between each energy update.
206 *
207 * \param interval Energy update interval.
208 */
209 void SetEnergyUpdateInterval(Time interval);
210
211 /**
212 * This function is used to change the initial capacity in the battery.
213 * A value of 0 means that the battery is fully charged. The value cannot
214 * be set to a value bigger than the rated capacity (fully discharged) or
215 * less than 0 (fully charged).
216 *
217 * \param drainedCapacity The capacity drained so far in the battery.
218 */
219 void SetDrainedCapacity(double drainedCapacity);
220
221 /**
222 * Obtain the amount of drained capacity from the battery based on the
223 * integral of the current over time (Coulomb counting method).
224 *
225 * \return The drainedCapacity (Ah)
226 */
227 double GetDrainedCapacity() const;
228
229 /**
230 * Calculates an estimate of the State of Charge (SoC).
231 * In essence, the amount of usable capacity remaining in the battery (%).
232 *
233 * \return The percentage of usable capacity remaining in the battery.
234 */
235 double GetStateOfCharge() const;
236
237 /**
238 * \return The interval between each energy update.
239 */
241
242 private:
243 void DoInitialize() override;
244 void DoDispose() override;
245
246 /**
247 * Handles the battery reaching its cutoff voltage. This function notifies
248 * all the energy models aggregated to the node about the usable energy in the
249 * battery has being depleted. Each energy model is then responsible for its own handler.
250 */
252
253 /**
254 * Handles the battery reaching its full voltage. This function notifies
255 * all the energy models aggregated to the node about the battery reaching its
256 * full energy charge.
257 */
258 void BatteryChargedEvent();
259
260 /**
261 * Calculates remaining energy. This function uses the total current from all
262 * device models to calculate the amount of energy to decrease. The energy to
263 * decrease is given by:
264 * energy to decrease = total current * supply voltage * time duration
265 * This function subtracts the calculated energy to decrease from remaining
266 * energy.
267 */
269
270 /**
271 * Get the battery voltage in function of the discharge current.
272 * It consider different discharge curves for different discharge currents
273 * and the remaining energy of the battery.
274 *
275 * \param current The actual discharge current value (+i).
276 * \return The voltage of the battery.
277 */
278 double GetVoltage(double current);
279
280 /**
281 * Obtain the battery voltage as a result of a charge current.
282 *
283 * \param current The actual charge current value (-i).
284 * \return The voltage of the battery.
285 */
286 double GetChargeVoltage(double current);
287
288 private:
289 TracedValue<double> m_remainingEnergyJ; //!< Remaining energy, in Joules
290 double m_drainedCapacity; //!< Capacity drained from the battery, in Ah
291 double m_currentFiltered; //!< The step response (a.k.a. low pass filter)
292 double m_entn; //!< The previous value of the exponential zone
293 //!< in NiMh,NiCd and LeadAcid.
294 double m_expZone; //!< Voltage value of the exponential zone
295 Time m_energyUpdateLapseTime; //!< The lapse of time between the last battery energy update and
296 //!< the current time.
297 double m_supplyVoltageV; //!< Actual voltage of the battery
298 double m_lowBatteryTh; //!< Low battery threshold, as a fraction of the initial energy
299 EventId m_energyUpdateEvent; //!< Energy update event
300 Time m_lastUpdateTime; //!< Last update time
301 Time m_energyUpdateInterval; //!< Energy update interval
302 double m_vFull; //!< Initial voltage of the battery, in Volts
303 double m_vNom; //!< Nominal voltage of the battery, in Volts
304 double m_vExp; //!< Battery voltage at the end of the exponential zone, in Volts
305 double m_internalResistance; //!< Internal resistance of the battery, in Ohms
306 double m_qMax; //!< The maximum capacity of the battery, in Ah
307 double m_qNom; //!< Battery capacity at the end of the nominal zone, in Ah
308 double m_qExp; //!< Capacity value at the end of the exponential zone, in Ah
309 double m_typicalCurrent; //!< Typical discharge current used to fit the curves
310 double m_cutoffVoltage; //!< The threshold voltage where the battery is considered depleted
311 GenericBatteryType m_batteryType; //!< Indicates the battery type used by the model
312};
313
314} // namespace energy
315} // namespace ns3
316
317#endif /* GENERIC_BATTERY_MODEL_H */
An identifier for simulation events.
Definition: event-id.h:56
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Trace classes with value semantics.
Definition: traced-value.h:116
a unique identifier for an interface.
Definition: type-id.h:59
Energy source base class.
Definition: energy-source.h:88
A generic battery model for Li-Ion, NiCd, NiMh and Lead acid batteries.
void DoDispose() override
All child's implementation must call BreakDeviceEnergyModelRefCycle to ensure reference cycles to Dev...
double m_expZone
Voltage value of the exponential zone.
double m_cutoffVoltage
The threshold voltage where the battery is considered depleted.
double GetChargeVoltage(double current)
Obtain the battery voltage as a result of a charge current.
static TypeId GetTypeId()
Get the type ID.
void BatteryChargedEvent()
Handles the battery reaching its full voltage.
double GetEnergyFraction() override
Implements GetEnergyFraction.
EventId m_energyUpdateEvent
Energy update event.
double m_lowBatteryTh
Low battery threshold, as a fraction of the initial energy.
double m_currentFiltered
The step response (a.k.a.
Time m_energyUpdateLapseTime
The lapse of time between the last battery energy update and the current time.
double m_qMax
The maximum capacity of the battery, in Ah.
double m_supplyVoltageV
Actual voltage of the battery.
double m_qNom
Battery capacity at the end of the nominal zone, in Ah.
double m_drainedCapacity
Capacity drained from the battery, in Ah.
double m_vFull
Initial voltage of the battery, in Volts.
double m_entn
The previous value of the exponential zone in NiMh,NiCd and LeadAcid.
double m_qExp
Capacity value at the end of the exponential zone, in Ah.
void SetDrainedCapacity(double drainedCapacity)
This function is used to change the initial capacity in the battery.
double GetSupplyVoltage() const override
Implements GetSupplyVoltage.
TracedValue< double > m_remainingEnergyJ
Remaining energy, in Joules.
double GetRemainingEnergy() override
Implements GetRemainingEnergy.
void BatteryDepletedEvent()
Handles the battery reaching its cutoff voltage.
double GetVoltage(double current)
Get the battery voltage in function of the discharge current.
double m_typicalCurrent
Typical discharge current used to fit the curves.
GenericBatteryType m_batteryType
Indicates the battery type used by the model.
void DoInitialize() override
Initialize() implementation.
double GetStateOfCharge() const
Calculates an estimate of the State of Charge (SoC).
double GetInitialEnergy() const override
Implements GetInitialEnergy.
double m_vNom
Nominal voltage of the battery, in Volts.
double GetDrainedCapacity() const
Obtain the amount of drained capacity from the battery based on the integral of the current over time...
void CalculateRemainingEnergy()
Calculates remaining energy.
void UpdateEnergySource() override
Implements UpdateEnergySource.
double m_vExp
Battery voltage at the end of the exponential zone, in Volts.
void SetEnergyUpdateInterval(Time interval)
This function sets the interval between each energy update.
double m_internalResistance
Internal resistance of the battery, in Ohms.
Time m_energyUpdateInterval
Energy update interval.
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.
GenericBatteryType
Battery types.
@ PANASONIC_HHR650D_NIMH
Panasonic HHR650D NiMh battery.
@ CSB_GP1272_LEADACID
CSB GP1272 Lead acid battery.
@ PANASONIC_CGR18650DA_LION
Panasonic CGR18650DA Li-Ion battery.
@ PANASONIC_N700AAC_NICD
Panasonic N700AAC NiCd battery.
@ RSPRO_LGP12100_LEADACID
RS Pro LGP12100 Lead acid battery.
@ LEADACID
Lead Acid Batteries.
@ NIMH_NICD
Nickel-metal hydride and Nickel cadmium batteries.
@ LION_LIPO
Lithium-ion and Lithium-polymer batteries.
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.
GenericBatteryType batteryType
The type of battery used in the preset.
double qMax
The maximum capacity of the battery, in Ah.
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 typicalCurrent
Typical discharge current used to fit the curves.
double internalResistance
Internal resistance of the battery, in Ohms.
double qNom
Battery capacity at the end of the nominal zone, in Ah.
double vFull
Initial voltage of the battery, in Volts.
double vExp
Battery voltage at the end of the exponential zone, in Volts.
double vNom
Nominal voltage of the battery, in Volts.