21 #include "rv-battery-model.h"
23 #include "ns3/assert.h"
24 #include "ns3/double.h"
25 #include "ns3/trace-source-accessor.h"
26 #include "ns3/simulator.h"
33 NS_OBJECT_ENSURE_REGISTERED (RvBatteryModel);
36 RvBatteryModel::GetTypeId (
void)
38 static TypeId tid = TypeId (
"ns3::RvBatteryModel")
39 .SetParent<EnergySource> ()
40 .AddConstructor<RvBatteryModel> ()
41 .AddAttribute (
"RvBatteryModelPeriodicEnergyUpdateInterval",
42 "RV battery model sampling interval.",
47 .AddAttribute (
"RvBatteryModelOpenCircuitVoltage",
48 "RV battery model open circuit voltage.",
52 MakeDoubleChecker<double> ())
53 .AddAttribute (
"RvBatteryModelCutoffVoltage",
54 "RV battery model cutoff voltage.",
58 MakeDoubleChecker<double> ())
59 .AddAttribute (
"RvBatteryModelAlphaValue",
60 "RV battery model alpha value.",
61 DoubleValue (35220.0),
64 MakeDoubleChecker<double> ())
65 .AddAttribute (
"RvBatteryModelBetaValue",
66 "RV battery model beta value.",
70 MakeDoubleChecker<double> ())
71 .AddAttribute (
"RvBatteryModelNumOfTerms",
72 "The number of terms of the infinite sum for estimating battery level.",
76 MakeIntegerChecker<int> ())
77 .AddTraceSource (
"RvBatteryModelBatteryLevel",
78 "RV battery model battery level.",
80 .AddTraceSource (
"RvBatteryModelBatteryLifetime",
81 "RV battery model battery lifetime.",
87 RvBatteryModel::RvBatteryModel ()
90 m_lastSampleTime =
Seconds (0.0);
96 RvBatteryModel::~RvBatteryModel ()
113 return (m_openCircuitVoltage - m_cutoffVoltage) / 2 + m_cutoffVoltage;
149 NS_LOG_DEBUG (
"RvBatteryModel:Updating remaining energy!");
151 m_currentSampleEvent.
Cancel ();
156 NS_LOG_DEBUG (
"RvBatteryModel:Calculated alpha = " << calculatedAlpha <<
167 if (calculatedAlpha >= m_alpha)
175 m_previousLoad = currentLoad;
201 m_openCircuitVoltage = voltage;
208 return m_openCircuitVoltage;
215 NS_ASSERT (voltage <= m_openCircuitVoltage);
216 m_cutoffVoltage = voltage;
223 return m_cutoffVoltage;
293 NS_LOG_DEBUG (
"RvBatteryModel:Starting battery level update!");
318 if (load != m_previousLoad)
320 m_load.push_back (load);
321 m_previousLoad = load;
324 m_timeStamps[m_timeStamps.size () - 1] = m_lastSampleTime;
328 m_timeStamps.push_back (
Seconds (0.0));
330 m_timeStamps.push_back (t);
334 m_timeStamps[m_timeStamps.size () - 1] = t;
337 m_lastSampleTime = t;
340 NS_ASSERT (m_load.size () == m_timeStamps.size () - 1);
341 double calculatedAlpha = 0.0;
342 if (m_timeStamps.size () == 1)
351 for (uint64_t i = 1; i < m_timeStamps.size (); i++)
359 return calculatedAlpha;
373 for (
int m = 1; m <= m_numOfTerms; m++)
375 double square = beta * beta * m * m;
376 sum += (std::exp (-square * (firstDelta)) - std::exp (-square * (secondDelta))) / square;
378 return delta + 2 * sum;
double Discharge(double load, Time t)
Discharges the battery.
void SetOpenCircuitVoltage(double voltage)
Sets open circuit voltage of battery.
#define NS_LOG_FUNCTION(parameters)
Time GetSamplingInterval(void) const
virtual double GetSupplyVoltage(void) const
double GetBeta(void) const
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
void SetBeta(double beta)
Sets the beta value for the battery model.
virtual double GetInitialEnergy(void) const
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
void HandleEnergyDrainedEvent(void)
void SetNumOfTerms(int num)
Sets the number of terms of the infinite sum for estimating battery level.
void SetCutoffVoltage(double voltage)
Sets cutoff voltage of battery.
double GetAlpha(void) const
virtual void DoInitialize(void)
Defined in ns3::Object.
void BreakDeviceEnergyModelRefCycle(void)
double GetSeconds(void) const
Time GetLifetime(void) const
void SetSamplingInterval(Time interval)
virtual void DoDispose(void)
Defined in ns3::Object.
double CalculateTotalCurrent(void)
double RvModelAFunction(Time t, Time sk, Time sk_1, double beta)
RV model A function.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
void NotifyEnergyDrained(void)
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
TracedValue< double > m_batteryLevel
#define NS_LOG_DEBUG(msg)
virtual double GetRemainingEnergy(void)
virtual void UpdateEnergySource(void)
double GetOpenCircuitVoltage(void) const
static bool IsFinished(void)
int GetNumOfTerms(void) const
double GetCutoffVoltage(void) const
void SetAlpha(double alpha)
Sets the alpha value for the battery model.
virtual double GetEnergyFraction(void)
double GetBatteryLevel(void)