OLD | NEW |
(Empty) | |
| 1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle. |
| 4 * |
| 5 * This program is free software; you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 2 as |
| 7 * published by the Free Software Foundation; |
| 8 * |
| 9 * This program is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with this program; if not, write to the Free Software |
| 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 * |
| 18 * Authors: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu> |
| 19 */ |
| 20 |
| 21 #ifndef RV_BATTERY_MODEL_H |
| 22 #define RV_BATTERY_MODEL_H |
| 23 |
| 24 #include "ns3/traced-value.h" |
| 25 #include "ns3/nstime.h" |
| 26 #include "ns3/event-id.h" |
| 27 #include "energy-source.h" |
| 28 |
| 29 namespace ns3 { |
| 30 |
| 31 /** |
| 32 * \brief Rakhmatov Vrudhula non-linear battery model. |
| 33 * |
| 34 * This (energy source) model implements a analytical non-linear battery model. |
| 35 * It is capable of capturing load capacity and recovery effects of batteries. |
| 36 * Batteries are characterized by 2 parameters: alpha and beta. Which can both |
| 37 * be obtained from the discharge curve of the batteries. |
| 38 * |
| 39 * The model is developed by Daler Rakhmatov & Sarma Vrudhula in: "Battery |
| 40 * Lifetime Prediction for Energy-Aware Computing" and "An Analytical High-Level |
| 41 * Battery Model for Use in Energy Management of Portable Electronic Systems". |
| 42 * |
| 43 * The real-time algorithm is developed by Matthias Handy & Dirk Timmermann in: |
| 44 * "Simulation of Mobile Wireless Networks with Accurate Modeling of non-linear |
| 45 * battery effects". The real-time algorithm is modified by the authors of this |
| 46 * code for improved accuracy and reduced computation (sampling) overhead. |
| 47 */ |
| 48 class RvBatteryModel : public EnergySource |
| 49 { |
| 50 public: |
| 51 static TypeId GetTypeId (void); |
| 52 RvBatteryModel (); |
| 53 virtual ~RvBatteryModel (); |
| 54 |
| 55 /** |
| 56 * \return Initial energy stored (theoretical capacity) in the battery. |
| 57 * |
| 58 * Implements GetInitialEnergy. |
| 59 */ |
| 60 virtual double GetInitialEnergy (void) const; |
| 61 |
| 62 /** |
| 63 * \returns Supply voltage at the energy source. |
| 64 * |
| 65 * Implements GetSupplyVoltage. |
| 66 */ |
| 67 virtual double GetSupplyVoltage (void) const; |
| 68 |
| 69 /** |
| 70 * \return Remaining energy in energy source, in Joules |
| 71 * |
| 72 * Implements GetRemainingEnergy. |
| 73 */ |
| 74 virtual double GetRemainingEnergy (void); |
| 75 |
| 76 /** |
| 77 * \returns Energy fraction. |
| 78 * |
| 79 * Implements GetEnergyFraction. For the RV battery model, energy fraction is |
| 80 * equivalent to battery level. |
| 81 */ |
| 82 virtual double GetEnergyFraction (void); |
| 83 |
| 84 /** |
| 85 * Implements UpdateEnergySource. This function samples the total load (total |
| 86 * current) from all devices to discharge the battery. |
| 87 */ |
| 88 virtual void UpdateEnergySource (void); |
| 89 |
| 90 /** |
| 91 * \param interval Energy update interval. |
| 92 * |
| 93 * This function sets the interval between each energy update. |
| 94 */ |
| 95 void SetSamplingInterval (Time interval); |
| 96 |
| 97 /** |
| 98 * \returns The interval between each energy update. |
| 99 */ |
| 100 Time GetSamplingInterval (void) const; |
| 101 |
| 102 /** |
| 103 * \brief Sets open circuit voltage of battery. |
| 104 * |
| 105 * \param voltage Open circuit voltage. |
| 106 */ |
| 107 void SetOpenCircuitVoltage (double voltage); |
| 108 |
| 109 /** |
| 110 * \return Open circuit voltage of battery. |
| 111 */ |
| 112 double GetOpenCircuitVoltage (void) const; |
| 113 |
| 114 /** |
| 115 * \brief Sets cutoff voltage of battery. |
| 116 * |
| 117 * \param voltage Cutoff voltage. |
| 118 */ |
| 119 void SetCutoffVoltage (double voltage); |
| 120 |
| 121 /** |
| 122 * \returns Cutoff voltage of battery. |
| 123 */ |
| 124 double GetCutoffVoltage (void) const; |
| 125 |
| 126 /** |
| 127 * \brief Sets the alpha value for the battery model. |
| 128 * |
| 129 * \param alpha Alpha. |
| 130 */ |
| 131 void SetAlpha (double alpha); |
| 132 |
| 133 /** |
| 134 * \returns The alpha value used by the battery model. |
| 135 */ |
| 136 double GetAlpha (void) const; |
| 137 |
| 138 /** |
| 139 * \brief Sets the beta value for the battery model. |
| 140 * |
| 141 * \param beta Beta. |
| 142 */ |
| 143 void SetBeta (double beta); |
| 144 |
| 145 /** |
| 146 * \returns The beta value used by the battery model. |
| 147 */ |
| 148 double GetBeta (void) const; |
| 149 |
| 150 /** |
| 151 * \returns Battery level [0, 1]. |
| 152 */ |
| 153 double GetBatteryLevel (void); |
| 154 |
| 155 /** |
| 156 * \returns Lifetime of the battery. |
| 157 */ |
| 158 Time GetLifetime (void) const; |
| 159 |
| 160 /** |
| 161 * \brief Sets the number of terms of the infinite sum for estimating battery |
| 162 * level. |
| 163 * |
| 164 * \param num Number of terms. |
| 165 */ |
| 166 void SetNumOfTerms (int num); |
| 167 |
| 168 /** |
| 169 * \returns The number of terms of the infinite sum for estimating battery |
| 170 * level. |
| 171 */ |
| 172 int GetNumOfTerms (void) const; |
| 173 |
| 174 private: |
| 175 /// Defined in ns3::Object |
| 176 virtual void DoStart (void); |
| 177 |
| 178 /// Defined in ns3::Object |
| 179 virtual void DoDispose (void); |
| 180 |
| 181 /** |
| 182 * Handles the remaining energy going to zero event. This function notifies |
| 183 * all the energy models aggregated to the node about the energy being |
| 184 * depleted. Each energy model is then responsible for its own handler. |
| 185 */ |
| 186 void HandleEnergyDrainedEvent (void); |
| 187 |
| 188 /** |
| 189 * \brief Discharges the battery. |
| 190 * |
| 191 * \param load Load value (total current form devices, in mA). |
| 192 * \param t Time stamp of the load value. |
| 193 * \returns Calculated alpha value. |
| 194 * |
| 195 * Discharge function calculates a value which is then compared to the alpha |
| 196 * value to determine if the battery is dead. It will also update the battery |
| 197 * level. |
| 198 * |
| 199 * Note that the load value passed to Discharge has to be in mA. |
| 200 */ |
| 201 double Discharge (double load, Time t); |
| 202 |
| 203 /** |
| 204 * \brief RV model A function. |
| 205 * |
| 206 * \param t Current time. |
| 207 * \param sk Time stamp in array position k |
| 208 * \param sk_1 Time stamp in array position k-1 |
| 209 * \param beta Beta value used by the battery model. |
| 210 * \returns Result of A function. |
| 211 * |
| 212 * This function computes alpha value using the recorded load profile. |
| 213 */ |
| 214 double RvModelAFunction (Time t, Time sk, Time sk_1, double beta); |
| 215 |
| 216 private: |
| 217 double m_openCircuitVoltage; |
| 218 double m_cutoffVoltage; |
| 219 double m_alpha; // alpha value of RV model, in Coulomb |
| 220 double m_beta; // beta value of RV model, in second^-1 |
| 221 |
| 222 double m_previousLoad; // load value (total current) of previous sampling |
| 223 std::vector<double> m_load; // load profile |
| 224 std::vector<Time> m_timeStamps; // time stamps of load profile |
| 225 Time m_lastSampleTime; |
| 226 uint64_t m_counter; |
| 227 |
| 228 int m_numOfTerms; // # of terms for infinite sum in battery level estimation |
| 229 |
| 230 /** |
| 231 * Battery level is defined as: output of Discharge function / alpha value |
| 232 * |
| 233 * The output of Discharge function is an estimated charge consumption of the |
| 234 * battery. |
| 235 * |
| 236 * The alpha value is the amount of charges stored in the battery, or battery |
| 237 * capacity (in Coulomb). |
| 238 * |
| 239 * When the battery is fully charged (no charge is consumed from the battery) |
| 240 * the battery level is 1. When the battery is fully discharged, the battery |
| 241 * level is 0. |
| 242 * |
| 243 * NOTE Note that the definition in Timmermann's paper is the inverse of this |
| 244 * definition. In the paper, battery level = 1 when the battery is drained. |
| 245 */ |
| 246 TracedValue<double> m_batteryLevel; |
| 247 |
| 248 /** |
| 249 * (1 / sampling interval) = sampling frequency |
| 250 */ |
| 251 Time m_samplingInterval; |
| 252 EventId m_currentSampleEvent; |
| 253 |
| 254 TracedValue<Time> m_lifetime; // time of death of the battery |
| 255 }; |
| 256 |
| 257 } // namespace ns3 |
| 258 |
| 259 #endif /* RV_BATTERY_MODEL_H */ |
OLD | NEW |