A generic battery model for Li-Ion, NiCd, NiMh and Lead acid batteries. More...
#include "generic-battery-model.h"
Public Member Functions | |
GenericBatteryModel () | |
~GenericBatteryModel () override | |
double | GetDrainedCapacity () const |
Obtain the amount of drained capacity from the battery based on the integral of the current over time (Coulomb counting method). | |
double | GetEnergyFraction () override |
Implements GetEnergyFraction. | |
Time | GetEnergyUpdateInterval () const |
double | GetInitialEnergy () const override |
Implements GetInitialEnergy. | |
double | GetRemainingEnergy () override |
Implements GetRemainingEnergy. | |
double | GetStateOfCharge () const |
Calculates an estimate of the State of Charge (SoC). | |
double | GetSupplyVoltage () const override |
Implements GetSupplyVoltage. | |
void | SetDrainedCapacity (double drainedCapacity) |
This function is used to change the initial capacity in the battery. | |
void | SetEnergyUpdateInterval (Time interval) |
This function sets the interval between each energy update. | |
void | UpdateEnergySource () override |
Implements UpdateEnergySource. | |
Public Member Functions inherited from ns3::energy::EnergySource | |
EnergySource () | |
~EnergySource () override | |
void | AppendDeviceEnergyModel (Ptr< DeviceEnergyModel > deviceEnergyModelPtr) |
void | ConnectEnergyHarvester (Ptr< EnergyHarvester > energyHarvesterPtr) |
void | DisposeDeviceModels () |
Calls Dispose () method of the device energy models. | |
DeviceEnergyModelContainer | FindDeviceEnergyModels (std::string name) |
DeviceEnergyModelContainer | FindDeviceEnergyModels (TypeId tid) |
Ptr< Node > | GetNode () const |
void | InitializeDeviceModels () |
Calls Start () method of the device energy models. | |
void | SetNode (Ptr< Node > node) |
Sets pointer to node containing this EnergySource. | |
Public Member Functions inherited from ns3::Object | |
Object () | |
Constructor. | |
~Object () override | |
Destructor. | |
void | AggregateObject (Ptr< Object > other) |
Aggregate two Objects together. | |
void | Dispose () |
Dispose of this Object. | |
AggregateIterator | GetAggregateIterator () const |
Get an iterator to the Objects aggregated to this one. | |
TypeId | GetInstanceTypeId () const override |
Get the most derived TypeId for this Object. | |
template<typename T > | |
Ptr< T > | GetObject () const |
Get a pointer to the requested aggregated Object. | |
template<> | |
Ptr< Object > | GetObject () const |
Specialization of () for objects of type ns3::Object. | |
template<typename T > | |
Ptr< T > | GetObject (TypeId tid) const |
Get a pointer to the requested aggregated Object by TypeId. | |
template<> | |
Ptr< Object > | GetObject (TypeId tid) const |
Specialization of (TypeId tid) for objects of type ns3::Object. | |
void | Initialize () |
Invoke DoInitialize on all Objects aggregated to this one. | |
bool | IsInitialized () const |
Check if the object has been initialized. | |
void | UnidirectionalAggregateObject (Ptr< Object > other) |
Aggregate an Object to another Object. | |
Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter > | |
SimpleRefCount () | |
Default constructor. | |
SimpleRefCount (const SimpleRefCount &o) | |
Copy constructor. | |
uint32_t | GetReferenceCount () const |
Get the reference count of the object. | |
SimpleRefCount & | operator= (const SimpleRefCount &o) |
Assignment operator. | |
void | Ref () const |
Increment the reference count. | |
void | Unref () const |
Decrement the reference count. | |
Public Member Functions inherited from ns3::ObjectBase | |
virtual | ~ObjectBase () |
Virtual destructor. | |
void | GetAttribute (std::string name, AttributeValue &value, bool permissive=false) const |
Get the value of an attribute, raising fatal errors if unsuccessful. | |
bool | GetAttributeFailSafe (std::string name, AttributeValue &value) const |
Get the value of an attribute without raising errors. | |
void | SetAttribute (std::string name, const AttributeValue &value) |
Set a single attribute, raising fatal errors if unsuccessful. | |
bool | SetAttributeFailSafe (std::string name, const AttributeValue &value) |
Set a single attribute without raising errors. | |
bool | TraceConnect (std::string name, std::string context, const CallbackBase &cb) |
Connect a TraceSource to a Callback with a context. | |
bool | TraceConnectWithoutContext (std::string name, const CallbackBase &cb) |
Connect a TraceSource to a Callback without a context. | |
bool | TraceDisconnect (std::string name, std::string context, const CallbackBase &cb) |
Disconnect from a TraceSource a Callback previously connected with a context. | |
bool | TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb) |
Disconnect from a TraceSource a Callback previously connected without a context. | |
Static Public Member Functions | |
static TypeId | GetTypeId () |
Get the type ID. | |
Static Public Member Functions inherited from ns3::energy::EnergySource | |
static TypeId | GetTypeId () |
Get the type ID. | |
Static Public Member Functions inherited from ns3::Object | |
static TypeId | GetTypeId () |
Register this type. | |
Static Public Member Functions inherited from ns3::ObjectBase | |
static TypeId | GetTypeId () |
Get the type ID. | |
Private Member Functions | |
void | BatteryChargedEvent () |
Handles the battery reaching its full voltage. | |
void | BatteryDepletedEvent () |
Handles the battery reaching its cutoff voltage. | |
void | CalculateRemainingEnergy () |
Calculates remaining energy. | |
void | DoDispose () override |
All child's implementation must call BreakDeviceEnergyModelRefCycle to ensure reference cycles to DeviceEnergyModel objects are broken. | |
void | DoInitialize () override |
Initialize() implementation. | |
double | GetChargeVoltage (double current) |
Obtain the battery voltage as a result of a charge current. | |
double | GetVoltage (double current) |
Get the battery voltage in function of the discharge current. | |
Private Attributes | |
GenericBatteryType | m_batteryType |
Indicates the battery type used by the model. | |
double | m_currentFiltered |
The step response (a.k.a. | |
double | m_cutoffVoltage |
The threshold voltage where the battery is considered depleted. | |
double | m_drainedCapacity |
Capacity drained from the battery, in Ah. | |
EventId | m_energyUpdateEvent |
Energy update event. | |
Time | m_energyUpdateInterval |
Energy update interval. | |
Time | m_energyUpdateLapseTime |
The lapse of time between the last battery energy update and the current time. | |
double | m_entn |
The previous value of the exponential zone in NiMh,NiCd and LeadAcid. | |
double | m_expZone |
Voltage value of the exponential zone. | |
double | m_internalResistance |
Internal resistance of the battery, in Ohms. | |
Time | m_lastUpdateTime |
Last update time. | |
double | m_lowBatteryTh |
Low battery threshold, as a fraction of the initial energy. | |
double | m_qExp |
Capacity value at the end of the exponential zone, in Ah. | |
double | m_qMax |
The maximum capacity of the battery, in Ah. | |
double | m_qNom |
Battery capacity at the end of the nominal zone, in Ah. | |
TracedValue< double > | m_remainingEnergyJ |
Remaining energy, in Joules. | |
double | m_supplyVoltageV |
Actual voltage of the battery. | |
double | m_typicalCurrent |
Typical discharge current used to fit the curves. | |
double | m_vExp |
Battery voltage at the end of the exponential zone, in Volts. | |
double | m_vFull |
Initial voltage of the battery, in Volts. | |
double | m_vNom |
Nominal voltage of the battery, in Volts. | |
Additional Inherited Members | |
Protected Member Functions inherited from ns3::energy::EnergySource | |
void | BreakDeviceEnergyModelRefCycle () |
This function is called to break reference cycle between EnergySource and DeviceEnergyModel. | |
double | CalculateTotalCurrent () |
void | NotifyEnergyChanged () |
This function notifies all DeviceEnergyModel of energy changed event. | |
void | NotifyEnergyDrained () |
This function notifies all DeviceEnergyModel of energy depletion event. | |
void | NotifyEnergyRecharged () |
This function notifies all DeviceEnergyModel of energy recharged event. | |
Protected Member Functions inherited from ns3::Object | |
Object (const Object &o) | |
Copy an Object. | |
virtual void | NotifyNewAggregate () |
Notify all Objects aggregated to this one of a new Object being aggregated. | |
Protected Member Functions inherited from ns3::ObjectBase | |
void | ConstructSelf (const AttributeConstructionList &attributes) |
Complete construction of ObjectBase; invoked by derived classes. | |
virtual void | NotifyConstructionCompleted () |
Notifier called once the ObjectBase is fully constructed. | |
Related Symbols inherited from ns3::ObjectBase | |
static TypeId | GetObjectIid () |
Ensure the TypeId for ObjectBase gets fully configured to anchor the inheritance tree properly. | |
A generic battery model for Li-Ion, NiCd, NiMh and Lead acid batteries.
The generic battery model can be used to describe the discharge behavior of the battery chemestries supported by the model.
Definition at line 143 of file generic-battery-model.h.
ns3::energy::GenericBatteryModel::GenericBatteryModel | ( | ) |
Definition at line 112 of file generic-battery-model.cc.
References NS_LOG_FUNCTION.
|
override |
Definition at line 122 of file generic-battery-model.cc.
References NS_LOG_FUNCTION.
|
private |
Handles the battery reaching its full voltage.
This function notifies all the energy models aggregated to the node about the battery reaching its full energy charge.
Definition at line 246 of file generic-battery-model.cc.
References ns3::energy::EnergySource::NotifyEnergyRecharged(), and NS_LOG_FUNCTION.
Referenced by UpdateEnergySource().
|
private |
Handles the battery reaching its cutoff voltage.
This function notifies all the energy models aggregated to the node about the usable energy in the battery has being depleted. Each energy model is then responsible for its own handler.
Definition at line 237 of file generic-battery-model.cc.
References ns3::energy::EnergySource::NotifyEnergyDrained(), and NS_LOG_FUNCTION.
Referenced by UpdateEnergySource().
|
private |
Calculates remaining energy.
This function uses the total current from all device models to calculate the amount of energy to decrease. The energy to decrease is given by: energy to decrease = total current * supply voltage * time duration This function subtracts the calculated energy to decrease from remaining energy.
Definition at line 255 of file generic-battery-model.cc.
References ns3::energy::EnergySource::CalculateTotalCurrent(), GetChargeVoltage(), ns3::Time::GetSeconds(), GetVoltage(), m_currentFiltered, m_drainedCapacity, m_energyUpdateLapseTime, m_lastUpdateTime, m_supplyVoltageV, ns3::Simulator::Now(), NS_ASSERT, NS_LOG_FUNCTION, and ns3::Seconds().
Referenced by UpdateEnergySource().
|
overrideprivatevirtual |
All child's implementation must call BreakDeviceEnergyModelRefCycle to ensure reference cycles to DeviceEnergyModel objects are broken.
Defined in ns3::Object
Reimplemented from ns3::energy::EnergySource.
Definition at line 230 of file generic-battery-model.cc.
References ns3::energy::EnergySource::BreakDeviceEnergyModelRefCycle(), and NS_LOG_FUNCTION.
|
overrideprivatevirtual |
Initialize() implementation.
This method is called only once by Initialize(). If the user calls Initialize() multiple times, DoInitialize() is called only the first time.
Subclasses are expected to override this method and chain up to their parent's implementation once they are done. It is safe to call GetObject() and AggregateObject() from within this method.
Reimplemented from ns3::Object.
Definition at line 224 of file generic-battery-model.cc.
References NS_LOG_FUNCTION.
Obtain the battery voltage as a result of a charge current.
current | The actual charge current value (-i). |
Definition at line 291 of file generic-battery-model.cc.
References GetStateOfCharge(), ns3::energy::LEADACID, ns3::energy::LION_LIPO, m_batteryType, m_currentFiltered, m_drainedCapacity, m_energyUpdateLapseTime, m_entn, m_expZone, m_internalResistance, m_qExp, m_qMax, m_qNom, m_remainingEnergyJ, m_typicalCurrent, m_vExp, m_vFull, m_vNom, ns3::energy::NIMH_NICD, ns3::Simulator::Now(), NS_LOG_DEBUG, and ns3::Time::S.
Referenced by CalculateRemainingEnergy().
double ns3::energy::GenericBatteryModel::GetDrainedCapacity | ( | ) | const |
Obtain the amount of drained capacity from the battery based on the integral of the current over time (Coulomb counting method).
Definition at line 155 of file generic-battery-model.cc.
References m_drainedCapacity.
|
overridevirtual |
Implements GetEnergyFraction.
For the generic battery model, energy fraction is equivalent to the remaining usable capacity (i.e. The SoC).
Implements ns3::energy::EnergySource.
Definition at line 183 of file generic-battery-model.cc.
References GetStateOfCharge(), and NS_LOG_FUNCTION.
Time ns3::energy::GenericBatteryModel::GetEnergyUpdateInterval | ( | ) | const |
Definition at line 168 of file generic-battery-model.cc.
References m_energyUpdateInterval, and NS_LOG_FUNCTION.
Referenced by GetTypeId().
|
overridevirtual |
Implements GetInitialEnergy.
It returns the amount of energy in Joules stored in the battery when fully charged. This energy is different to the total amount of usable energy in the battery. This is because the battery cannot be used until Voltage = 0, only until it reaches the cutoff voltage.
Implements ns3::energy::EnergySource.
Definition at line 128 of file generic-battery-model.cc.
|
overridevirtual |
Implements GetRemainingEnergy.
Implements ns3::energy::EnergySource.
Definition at line 175 of file generic-battery-model.cc.
References m_remainingEnergyJ, NS_LOG_FUNCTION, and UpdateEnergySource().
double ns3::energy::GenericBatteryModel::GetStateOfCharge | ( | ) | const |
Calculates an estimate of the State of Charge (SoC).
In essence, the amount of usable capacity remaining in the battery (%).
Definition at line 161 of file generic-battery-model.cc.
References m_drainedCapacity, and m_qMax.
Referenced by GetChargeVoltage(), GetEnergyFraction(), and GetVoltage().
|
overridevirtual |
Implements GetSupplyVoltage.
Implements ns3::energy::EnergySource.
Definition at line 135 of file generic-battery-model.cc.
References m_supplyVoltageV.
|
static |
Get the type ID.
Definition at line 31 of file generic-battery-model.cc.
References ns3::TypeId::AddDeprecatedName(), GetEnergyUpdateInterval(), ns3::energy::LEADACID, ns3::energy::LION_LIPO, m_batteryType, m_cutoffVoltage, m_internalResistance, m_lowBatteryTh, m_qExp, m_qMax, m_qNom, m_remainingEnergyJ, m_typicalCurrent, m_vExp, m_vFull, m_vNom, ns3::MakeDoubleAccessor(), ns3::MakeDoubleChecker(), ns3::MakeEnumAccessor(), ns3::MakeEnumChecker(), ns3::MakeTimeAccessor(), ns3::MakeTimeChecker(), ns3::MakeTraceSourceAccessor(), ns3::energy::NIMH_NICD, ns3::Seconds(), SetEnergyUpdateInterval(), and ns3::TypeId::SetParent().
Get the battery voltage in function of the discharge current.
It consider different discharge curves for different discharge currents and the remaining energy of the battery.
current | The actual discharge current value (+i). |
Definition at line 367 of file generic-battery-model.cc.
References GetStateOfCharge(), ns3::energy::LEADACID, ns3::energy::LION_LIPO, m_batteryType, m_currentFiltered, m_drainedCapacity, m_energyUpdateLapseTime, m_entn, m_expZone, m_internalResistance, m_qExp, m_qMax, m_qNom, m_remainingEnergyJ, m_typicalCurrent, m_vExp, m_vFull, m_vNom, ns3::energy::NIMH_NICD, ns3::Simulator::Now(), NS_ASSERT, NS_LOG_DEBUG, NS_LOG_FUNCTION, and ns3::Time::S.
Referenced by CalculateRemainingEnergy().
void ns3::energy::GenericBatteryModel::SetDrainedCapacity | ( | double | drainedCapacity | ) |
This function is used to change the initial capacity in the battery.
A value of 0 means that the battery is fully charged. The value cannot be set to a value bigger than the rated capacity (fully discharged) or less than 0 (fully charged).
drainedCapacity | The capacity drained so far in the battery. |
Definition at line 148 of file generic-battery-model.cc.
References m_drainedCapacity, m_qMax, and NS_ASSERT.
void ns3::energy::GenericBatteryModel::SetEnergyUpdateInterval | ( | Time | interval | ) |
This function sets the interval between each energy update.
interval | Energy update interval. |
Definition at line 141 of file generic-battery-model.cc.
References m_energyUpdateInterval, and NS_LOG_FUNCTION.
Referenced by GetTypeId().
|
overridevirtual |
Implements UpdateEnergySource.
Implements ns3::energy::EnergySource.
Definition at line 190 of file generic-battery-model.cc.
References BatteryChargedEvent(), BatteryDepletedEvent(), CalculateRemainingEnergy(), ns3::EventId::Cancel(), ns3::Simulator::IsFinished(), m_cutoffVoltage, m_energyUpdateEvent, m_energyUpdateInterval, m_lastUpdateTime, m_supplyVoltageV, m_vFull, ns3::Simulator::Now(), NS_LOG_FUNCTION, ns3::Simulator::Schedule(), and UpdateEnergySource().
Referenced by GetRemainingEnergy(), and UpdateEnergySource().
|
private |
Indicates the battery type used by the model.
Definition at line 300 of file generic-battery-model.h.
Referenced by GetChargeVoltage(), GetTypeId(), and GetVoltage().
|
private |
The step response (a.k.a.
low pass filter)
Definition at line 280 of file generic-battery-model.h.
Referenced by CalculateRemainingEnergy(), GetChargeVoltage(), and GetVoltage().
|
private |
The threshold voltage where the battery is considered depleted.
Definition at line 299 of file generic-battery-model.h.
Referenced by GetTypeId(), and UpdateEnergySource().
|
private |
Capacity drained from the battery, in Ah.
Definition at line 279 of file generic-battery-model.h.
Referenced by CalculateRemainingEnergy(), GetChargeVoltage(), GetDrainedCapacity(), GetStateOfCharge(), GetVoltage(), and SetDrainedCapacity().
|
private |
Energy update event.
Definition at line 288 of file generic-battery-model.h.
Referenced by UpdateEnergySource().
|
private |
Energy update interval.
Definition at line 290 of file generic-battery-model.h.
Referenced by GetEnergyUpdateInterval(), SetEnergyUpdateInterval(), and UpdateEnergySource().
|
private |
The lapse of time between the last battery energy update and the current time.
Definition at line 284 of file generic-battery-model.h.
Referenced by CalculateRemainingEnergy(), GetChargeVoltage(), and GetVoltage().
|
private |
The previous value of the exponential zone in NiMh,NiCd and LeadAcid.
Definition at line 281 of file generic-battery-model.h.
Referenced by GetChargeVoltage(), and GetVoltage().
|
private |
Voltage value of the exponential zone.
Definition at line 283 of file generic-battery-model.h.
Referenced by GetChargeVoltage(), and GetVoltage().
|
private |
Internal resistance of the battery, in Ohms.
Definition at line 294 of file generic-battery-model.h.
Referenced by GetChargeVoltage(), GetTypeId(), and GetVoltage().
|
private |
Last update time.
Definition at line 289 of file generic-battery-model.h.
Referenced by CalculateRemainingEnergy(), and UpdateEnergySource().
|
private |
Low battery threshold, as a fraction of the initial energy.
Definition at line 287 of file generic-battery-model.h.
Referenced by GetTypeId().
|
private |
Capacity value at the end of the exponential zone, in Ah.
Definition at line 297 of file generic-battery-model.h.
Referenced by GetChargeVoltage(), GetTypeId(), and GetVoltage().
|
private |
The maximum capacity of the battery, in Ah.
Definition at line 295 of file generic-battery-model.h.
Referenced by GetChargeVoltage(), GetInitialEnergy(), GetStateOfCharge(), GetTypeId(), GetVoltage(), and SetDrainedCapacity().
|
private |
Battery capacity at the end of the nominal zone, in Ah.
Definition at line 296 of file generic-battery-model.h.
Referenced by GetChargeVoltage(), GetTypeId(), and GetVoltage().
|
private |
Remaining energy, in Joules.
Definition at line 278 of file generic-battery-model.h.
Referenced by GetChargeVoltage(), GetRemainingEnergy(), GetTypeId(), and GetVoltage().
|
private |
Actual voltage of the battery.
Definition at line 286 of file generic-battery-model.h.
Referenced by CalculateRemainingEnergy(), GetSupplyVoltage(), and UpdateEnergySource().
|
private |
Typical discharge current used to fit the curves.
Definition at line 298 of file generic-battery-model.h.
Referenced by GetChargeVoltage(), GetTypeId(), and GetVoltage().
|
private |
Battery voltage at the end of the exponential zone, in Volts.
Definition at line 293 of file generic-battery-model.h.
Referenced by GetChargeVoltage(), GetTypeId(), and GetVoltage().
|
private |
Initial voltage of the battery, in Volts.
Definition at line 291 of file generic-battery-model.h.
Referenced by GetChargeVoltage(), GetInitialEnergy(), GetTypeId(), GetVoltage(), and UpdateEnergySource().
|
private |
Nominal voltage of the battery, in Volts.
Definition at line 292 of file generic-battery-model.h.
Referenced by GetChargeVoltage(), GetTypeId(), and GetVoltage().