22 #include "ns3/assert.h"
23 #include "ns3/double.h"
25 #include "ns3/simulator.h"
26 #include "ns3/trace-source-accessor.h"
41 TypeId(
"ns3::LiIonEnergySource")
43 .SetGroupName(
"Energy")
45 .AddAttribute(
"LiIonEnergySourceInitialEnergyJ",
46 "Initial energy stored in basic energy source.",
50 MakeDoubleChecker<double>())
51 .AddAttribute(
"LiIonEnergyLowBatteryThreshold",
52 "Low battery threshold for LiIon energy source.",
55 MakeDoubleChecker<double>())
56 .AddAttribute(
"InitialCellVoltage",
57 "Initial (maximum) voltage of the cell (fully charged).",
61 MakeDoubleChecker<double>())
62 .AddAttribute(
"NominalCellVoltage",
63 "Nominal voltage of the cell.",
66 MakeDoubleChecker<double>())
67 .AddAttribute(
"ExpCellVoltage",
68 "Cell voltage at the end of the exponential zone.",
71 MakeDoubleChecker<double>())
72 .AddAttribute(
"RatedCapacity",
73 "Rated capacity of the cell.",
76 MakeDoubleChecker<double>())
77 .AddAttribute(
"NomCapacity",
78 "Cell capacity at the end of the nominal zone.",
81 MakeDoubleChecker<double>())
82 .AddAttribute(
"ExpCapacity",
83 "Cell Capacity at the end of the exponential zone.",
86 MakeDoubleChecker<double>())
87 .AddAttribute(
"InternalResistance",
88 "Internal resistance of the cell",
91 MakeDoubleChecker<double>())
92 .AddAttribute(
"TypCurrent",
93 "Typical discharge current used to fit the curves",
96 MakeDoubleChecker<double>())
97 .AddAttribute(
"ThresholdVoltage",
98 "Minimum threshold voltage to consider the battery depleted.",
101 MakeDoubleChecker<double>())
102 .AddAttribute(
"PeriodicEnergyUpdateInterval",
103 "Time between two consecutive periodic energy updates.",
108 .AddTraceSource(
"RemainingEnergy",
109 "Remaining energy at BasicEnergySource.",
111 "ns3::TracedValueCallback::Double");
116 : m_drainedCapacity(0.0),
217 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'.
double CalculateTotalCurrent()
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.
Ptr< Node > GetNode() const
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Model a generic Lithium Ion Battery basing on [1][2].
void DoDispose() override
All child's implementation must call BreakDeviceEnergyModelRefCycle to ensure reference cycles to Dev...
void UpdateEnergySource() override
Implements UpdateEnergySource.
double m_drainedCapacity
capacity drained from the cell, in Ah
void SetInitialEnergy(double initialEnergyJ)
double m_minVoltTh
minimum threshold voltage to consider the battery depleted
virtual void IncreaseRemainingEnergy(double energyJ)
void DoInitialize() override
Initialize() implementation.
double m_supplyVoltageV
actual voltage of the cell
TracedValue< double > m_remainingEnergyJ
remaining energy, in Joules
double m_initialEnergyJ
initial energy, in Joules
double GetRemainingEnergy() override
double m_eFull
initial voltage of the cell, in Volts
void SetEnergyUpdateInterval(Time interval)
double m_internalResistance
internal resistance of the cell, in Ohms
Time m_energyUpdateInterval
energy update interval
~LiIonEnergySource() override
void SetInitialSupplyVoltage(double supplyVoltageV)
double m_eNom
nominal voltage of the cell, in Volts
double m_lowBatteryTh
low battery threshold, as a fraction of the initial energy
double m_eExp
cell voltage at the end of the exponential zone, in Volts
EventId m_energyUpdateEvent
energy update event
double GetEnergyFraction() override
Time GetEnergyUpdateInterval() const
void CalculateRemainingEnergy()
Calculates remaining energy.
double GetInitialEnergy() const override
static TypeId GetTypeId()
Get the type ID.
double m_qNom
cell capacity at the end of the nominal zone, in Ah
double m_qExp
capacity value at the end of the exponential zone, in Ah
double GetVoltage(double current) const
Get the cell voltage in function of the discharge current.
double m_qRated
rated capacity of the cell, in Ah
double GetSupplyVoltage() const override
virtual void DecreaseRemainingEnergy(double energyJ)
double m_typCurrent
typical discharge current used to fit the curves
void HandleEnergyDrainedEvent()
Handles the remaining energy going to zero event.
Time m_lastUpdateTime
last update time
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 SetParent(TypeId tid)
Set the parent TypeId.
#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 > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
#define E(name, start, end)