11#include "ns3/assert.h"
12#include "ns3/double.h"
14#include "ns3/simulator.h"
15#include "ns3/trace-source-accessor.h"
31 TypeId(
"ns3::energy::LiIonEnergySource")
34 .SetGroupName(
"Energy")
36 .AddAttribute(
"LiIonEnergySourceInitialEnergyJ",
37 "Initial energy stored in basic energy source.",
42 .AddAttribute(
"LiIonEnergyLowBatteryThreshold",
43 "Low battery threshold for LiIon energy source.",
47 .AddAttribute(
"InitialCellVoltage",
48 "Initial (maximum) voltage of the cell (fully charged).",
53 .AddAttribute(
"NominalCellVoltage",
54 "Nominal voltage of the cell.",
58 .AddAttribute(
"ExpCellVoltage",
59 "Cell voltage at the end of the exponential zone.",
63 .AddAttribute(
"RatedCapacity",
64 "Rated capacity of the cell.",
68 .AddAttribute(
"NomCapacity",
69 "Cell capacity at the end of the nominal zone.",
73 .AddAttribute(
"ExpCapacity",
74 "Cell Capacity at the end of the exponential zone.",
78 .AddAttribute(
"InternalResistance",
79 "Internal resistance of the cell",
83 .AddAttribute(
"TypCurrent",
84 "Typical discharge current used to fit the curves",
88 .AddAttribute(
"ThresholdVoltage",
89 "Minimum threshold voltage to consider the battery depleted.",
93 .AddAttribute(
"PeriodicEnergyUpdateInterval",
94 "Time between two consecutive periodic energy updates.",
99 .AddTraceSource(
"RemainingEnergy",
100 "Remaining energy at BasicEnergySource.",
102 "ns3::TracedValueCallback::Double");
107 : m_drainedCapacity(0.0),
208 NS_LOG_DEBUG(
"LiIonEnergySource:Updating remaining energy at node #" <<
GetNode()->GetId());
This class can be used to hold variables of floating point type such as 'double' or 'float'.
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static bool IsFinished()
Check if the simulation should finish.
static Time Now()
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
a unique identifier for an interface.
TypeId AddDeprecatedName(const std::string &name)
Add an deprecated name for a TypeId.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Energy source base class.
void BreakDeviceEnergyModelRefCycle()
This function is called to break reference cycle between EnergySource and DeviceEnergyModel.
void NotifyEnergyDrained()
This function notifies all DeviceEnergyModel of energy depletion event.
double CalculateTotalCurrent()
Ptr< Node > GetNode() const
Model a generic Lithium Ion Battery basing on [1][2].
void UpdateEnergySource() override
Implements UpdateEnergySource.
void SetInitialEnergy(double initialEnergyJ)
double m_minVoltTh
minimum threshold voltage to consider the battery depleted
double m_qNom
cell capacity at the end of the nominal zone, in Ah
EventId m_energyUpdateEvent
energy update event
double m_eNom
nominal voltage of the cell, in Volts
double m_qExp
capacity value at the end of the exponential zone, in Ah
double m_drainedCapacity
capacity drained from the cell, in Ah
Time m_lastUpdateTime
last update time
TracedValue< double > m_remainingEnergyJ
remaining energy, in Joules
void DoInitialize() override
Initialize() implementation.
virtual void IncreaseRemainingEnergy(double energyJ)
double GetRemainingEnergy() override
void SetEnergyUpdateInterval(Time interval)
double GetInitialEnergy() const override
void SetInitialSupplyVoltage(double supplyVoltageV)
double GetEnergyFraction() override
virtual void DecreaseRemainingEnergy(double energyJ)
double GetVoltage(double current) const
Get the cell voltage in function of the discharge current.
double m_internalResistance
internal resistance of the cell, in Ohms
Time GetEnergyUpdateInterval() const
double m_lowBatteryTh
low battery threshold, as a fraction of the initial energy
Time m_energyUpdateInterval
energy update interval
~LiIonEnergySource() override
double m_typCurrent
typical discharge current used to fit the curves
void DoDispose() override
All child's implementation must call BreakDeviceEnergyModelRefCycle to ensure reference cycles to Dev...
double m_supplyVoltageV
actual voltage of the cell
double GetSupplyVoltage() const override
static TypeId GetTypeId()
Get the type ID.
void CalculateRemainingEnergy()
Calculates remaining energy.
double m_qRated
rated capacity of the cell, in Ah
void HandleEnergyDrainedEvent()
Handles the remaining energy going to zero event.
double m_eFull
initial voltage of the cell, in Volts
double m_eExp
cell voltage at the end of the exponential zone, in Volts
double m_initialEnergyJ
initial energy, in Joules
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time Seconds(double value)
Construct a Time in the indicated unit.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Ptr< const AttributeChecker > MakeDoubleChecker()
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
#define E(name, start, end)