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{
34
35/**
36 * \ingroup energy
37 *
38 * Battery types.
39 * These are grouped according to their chemical characteristics
40 * present during a charge/discharge curve.
41 */
43{
44 LION_LIPO = 0, //!< Lithium-ion and Lithium-polymer batteries
45 NIMH_NICD = 1, //!< Nickel-metal hydride and Nickel cadmium batteries
46 LEADACID = 2 //!< Lead Acid Batteries
47};
48
49/**
50 * \ingroup energy
51 *
52 * Battery models that described the parameters of the the battery presets.
53 */
55{
56 PANASONIC_HHR650D_NIMH = 0, //!< Panasonic HHR650D NiMh battery
57 CSB_GP1272_LEADACID = 1, //!< CSB GP1272 Lead acid battery
58 PANASONIC_CGR18650DA_LION = 2, //!< Panasonic CGR18650DA Li-Ion battery
59 RSPRO_LGP12100_LEADACID = 3, //!< RS Pro LGP12100 Lead acid battery
60 PANASONIC_N700AAC_NICD = 4 //!< Panasonic N700AAC NiCd battery
61};
62
63/**
64 * \ingroup energy
65 *
66 * The structure containing the the parameter values that describe a
67 * battery preset.
68 */
70{
71 GenericBatteryType batteryType; //!< The type of battery used in the preset.
72 std::string description; //!< Additional information about the battery.
73 double vFull; //!< Initial voltage of the battery, in Volts
74 double qMax; //!< The maximum capacity of the battery, in Ah
75 double vNom; //!< Nominal voltage of the battery, in Volts
76 double qNom; //!< Battery capacity at the end of the nominal zone, in Ah
77 double vExp; //!< Battery voltage at the end of the exponential zone, in Volts
78 double qExp; //!< Capacity value at the end of the exponential zone, in Ah
79 double internalResistance; //!< Internal resistance of the battery, in Ohms
80 double typicalCurrent; //!< Typical discharge current used to fit the curves
81 double cuttoffVoltage; //!< The threshold voltage where the battery is considered depleted
82};
83
84/**
85 * \ingroup energy
86 *
87 * Contains the values that form the battery presents available in this module.
88 */
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
145/**
146 * \ingroup energy
147 * \brief A generic battery model for Li-Ion, NiCd, NiMh and Lead acid batteries
148 *
149 * The generic battery model can be used to describe the discharge behavior of
150 * the battery chemestries supported by the model.
151 */
153{
154 public:
155 /**
156 * \brief Get the type ID.
157 * \return The object TypeId.
158 */
159 static TypeId GetTypeId();
160
162
163 ~GenericBatteryModel() override;
164
165 /**
166 * Implements GetInitialEnergy. It returns the amount of energy in Joules stored in the
167 * battery when fully charged. This energy is different to the total amount of usable energy
168 * in the battery. This is because the battery cannot be used until Voltage = 0, only until
169 * it reaches the cutoff voltage.
170 *
171 * \return The initial energy stored in the fully charged battery, in Joules.
172 */
173 double GetInitialEnergy() const override;
174
175 /**
176 * Implements GetSupplyVoltage.
177 *
178 * \return Supply voltage at the energy source.
179 */
180 double GetSupplyVoltage() const override;
181
182 /**
183 * Implements GetRemainingEnergy.
184 *
185 * \return Remaining energy in energy source, in Joules
186 */
187 double GetRemainingEnergy() override;
188
189 /**
190 * Implements GetEnergyFraction. For the generic battery model, energy fraction
191 * is equivalent to the remaining usable capacity (i.e. The SoC).
192 *
193 * \return Energy fraction.
194 */
195 double GetEnergyFraction() override;
196
197 /**
198 * Implements UpdateEnergySource.
199 */
200 void UpdateEnergySource() override;
201
202 /**
203 * This function sets the interval between each energy update.
204 *
205 * \param interval Energy update interval.
206 */
207 void SetEnergyUpdateInterval(Time interval);
208
209 /**
210 * This function is used to change the initial capacity in the battery.
211 * A value of 0 means that the battery is fully charged. The value cannot
212 * be set to a value bigger than the rated capacity (fully discharged) or
213 * less than 0 (fully charged).
214 *
215 * \param drainedCapacity The capacity drained so far in the battery.
216 */
217 void SetDrainedCapacity(double drainedCapacity);
218
219 /**
220 * Obtain the amount of drained capacity from the battery based on the
221 * integral of the current over time (Coulomb counting method).
222 *
223 * \return The drainedCapacity (Ah)
224 */
225 double GetDrainedCapacity() const;
226
227 /**
228 * Calculates an estimate of the State of Charge (SoC).
229 * In essence, the amount of usable capacity remaining in the battery (%).
230 *
231 * \return The percentage of usable capacity remaining in the battery.
232 */
233 double GetStateOfCharge() const;
234
235 /**
236 * \return The interval between each energy update.
237 */
239
240 private:
241 void DoInitialize() override;
242 void DoDispose() override;
243
244 /**
245 * Handles the battery reaching its cutoff voltage. This function notifies
246 * all the energy models aggregated to the node about the usable energy in the
247 * battery has being depleted. Each energy model is then responsible for its own handler.
248 */
250
251 /**
252 * Handles the battery reaching its full voltage. This function notifies
253 * all the energy models aggregated to the node about the battery reaching its
254 * full energy charge.
255 */
256 void BatteryChargedEvent();
257
258 /**
259 * Calculates remaining energy. This function uses the total current from all
260 * device models to calculate the amount of energy to decrease. The energy to
261 * decrease is given by:
262 * energy to decrease = total current * supply voltage * time duration
263 * This function subtracts the calculated energy to decrease from remaining
264 * energy.
265 */
267
268 /**
269 * Get the battery voltage in function of the discharge current.
270 * It consider different discharge curves for different discharge currents
271 * and the remaining energy of the battery.
272 *
273 * \param current The actual discharge current value (+i).
274 * \return The voltage of the battery.
275 */
276 double GetVoltage(double current);
277
278 /**
279 * Obtain the battery voltage as a result of a charge current.
280 *
281 * \param current The actual charge current value (-i).
282 * \return The voltage of the battery.
283 */
284 double GetChargeVoltage(double current);
285
286 private:
287 TracedValue<double> m_remainingEnergyJ; //!< Remaining energy, in Joules
288 double m_drainedCapacity; //!< Capacity drained from the battery, in Ah
289 double m_currentFiltered; //!< The step response (a.k.a. low pass filter)
290 double m_entn; //!< The previous value of the exponential zone
291 //!< in NiMh,NiCd and LeadAcid.
292 double m_expZone; //!< Voltage value of the exponential zone
293 Time m_energyUpdateLapseTime; //!< The lapse of time between the last battery energy update and
294 //!< the current time.
295 double m_supplyVoltageV; //!< Actual voltage of the battery
296 double m_lowBatteryTh; //!< Low battery threshold, as a fraction of the initial energy
297 EventId m_energyUpdateEvent; //!< Energy update event
298 Time m_lastUpdateTime; //!< Last update time
299 Time m_energyUpdateInterval; //!< Energy update interval
300 double m_vFull; //!< Initial voltage of the battery, in Volts
301 double m_vNom; //!< Nominal voltage of the battery, in Volts
302 double m_vExp; //!< Battery voltage at the end of the exponential zone, in Volts
303 double m_internalResistance; //!< Internal resistance of the battery, in Ohms
304 double m_qMax; //!< The maximum capacity of the battery, in Ah
305 double m_qNom; //!< Battery capacity at the end of the nominal zone, in Ah
306 double m_qExp; //!< Capacity value at the end of the exponential zone, in Ah
307 double m_typicalCurrent; //!< Typical discharge current used to fit the curves
308 double m_cutoffVoltage; //!< The threshold voltage where the battery is considered depleted
309 GenericBatteryType m_batteryType; //!< Indicates the battery type used by the model
310};
311
312} // namespace ns3
313
314#endif /* GENERIC_BATTERY_MODEL_H */
Introspection did not find any typical Config paths.
Definition: energy-source.h:87
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
Trace classes with value semantics.
Definition: traced-value.h:116
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.