A battery abstraction. More...
#include <Battery.hh>
Public Types | |
typedef std::map< uint32_t, double > | PowerLoad_M |
Typedef the powerload map. More... | |
Public Member Functions | |
Battery () | |
Constructor. More... | |
Battery (Battery &&_battery) | |
Move constructor. More... | |
Battery (const Battery &_battery) | |
Copy constructor. More... | |
Battery (const std::string &_name, const double _voltage) | |
Constructor that sets the name and initial voltage. More... | |
virtual | ~Battery ()=default |
Destructor. More... | |
uint32_t | AddConsumer () |
Create a unique consumer. More... | |
virtual void | Init () |
Initialize. More... | |
double | InitVoltage () const |
Return the initial voltage. More... | |
std::string | Name () const |
Return the name of the battery. More... | |
bool | operator!= (const Battery &_battery) const |
Inequality operator. More... | |
Battery & | operator= (Battery &&_battery) |
Move assignment operator. More... | |
Battery & | operator= (const Battery &_battery) |
Copy assignment operator. More... | |
bool | operator== (const Battery &_battery) const |
Equal to operator. More... | |
bool | PowerLoad (const uint32_t _consumerId, double &_powerLoad) const |
Get consumer power load in watts. More... | |
const PowerLoad_M & | PowerLoads () const |
Get list of power loads in watts. More... | |
bool | RemoveConsumer (const uint32_t _consumerId) |
Remove a consumer. More... | |
void | ResetUpdateFunc () |
Reset function to update voltage, upon destruction of current callback function. More... | |
virtual void | ResetVoltage () |
Reset the battery voltage to the initial value. The initial value might have been loaded from an sdf element. More... | |
virtual void | SetInitVoltage (const double _voltage) |
Set the initial voltage. More... | |
void | SetName (const std::string &_name) const |
Set the name of the battery. More... | |
bool | SetPowerLoad (const uint32_t _consumerId, const double _powerLoad) |
Set consumer power load in watts. More... | |
void | SetUpdateFunc (std::function< double(Battery *)> _updateFunc) |
Setup function to update voltage. More... | |
void | Update () |
Update the battery. This will in turn trigger the function set using the SetUpdateFunc function. More... | |
double | Voltage () const |
Get the real voltage in volts. More... | |
Protected Member Functions | |
void | InitConsumers () |
Initialize the list of consumers. More... | |
Detailed Description
A battery abstraction.
The default battery model is ideal: It just takes the initial voltage value as its constant voltage value. This behavior can be changed by specifying a custom update function.
The battery handles a list of consumers. It updates itself after each simulation iteration. The update function takes the power loads for each consumer and current voltage value as inputs and returns a new voltage value.
Member Typedef Documentation
◆ PowerLoad_M
typedef std::map<uint32_t, double> PowerLoad_M |
Typedef the powerload map.
- See also
- SetUpdateFunc
Constructor & Destructor Documentation
◆ Battery() [1/4]
|
explicit |
Constructor.
◆ Battery() [2/4]
Battery | ( | const std::string & | _name, |
const double | _voltage | ||
) |
Constructor that sets the name and initial voltage.
- Parameters
-
[in] _name Name of the battery [in] _voltage Initial voltage of the battery
◆ Battery() [3/4]
◆ Battery() [4/4]
◆ ~Battery()
|
virtualdefault |
Destructor.
Member Function Documentation
◆ AddConsumer()
uint32_t AddConsumer | ( | ) |
Create a unique consumer.
- Returns
- Unique consumer identifier.
◆ Init()
|
virtual |
Initialize.
◆ InitConsumers()
|
protected |
Initialize the list of consumers.
◆ InitVoltage()
double InitVoltage | ( | ) | const |
Return the initial voltage.
- Returns
- The initial voltage.
◆ Name()
std::string Name | ( | ) | const |
Return the name of the battery.
- Returns
- The name of the battery.
◆ operator!=()
bool operator!= | ( | const Battery & | _battery | ) | const |
Inequality operator.
- Parameters
-
[in] _battery the battery to compare to
- Returns
- true if names or initial voltages are not the same, false otherwise
◆ operator=() [1/2]
Move assignment operator.
- Parameters
-
[in] _battery The new battery
- Returns
- a reference to this instance
◆ operator=() [2/2]
Copy assignment operator.
- Parameters
-
[in] _battery The new battery
- Returns
- a reference to this instance
◆ operator==()
bool operator== | ( | const Battery & | _battery | ) | const |
Equal to operator.
- Parameters
-
[in] _battery the battery to compare to
- Returns
- true if names and initial voltages are the same, false otherwise
◆ PowerLoad()
bool PowerLoad | ( | const uint32_t | _consumerId, |
double & | _powerLoad | ||
) | const |
Get consumer power load in watts.
- Parameters
-
[in] _consumerId Unique consumer identifier. [out] _powerLoad Power load consumption in watts.
- Returns
- True if getting the power load consumption was successful.
◆ PowerLoads()
const PowerLoad_M& PowerLoads | ( | ) | const |
Get list of power loads in watts.
- Returns
- List of power loads in watts.
◆ RemoveConsumer()
bool RemoveConsumer | ( | const uint32_t | _consumerId | ) |
Remove a consumer.
- Parameters
-
[in] _consumerId Unique consumer identifier.
- Returns
- True if the consumer was removed. False if the consumer id was not found.
◆ ResetUpdateFunc()
void ResetUpdateFunc | ( | ) |
Reset function to update voltage, upon destruction of current callback function.
- See also
- UpdateDefault
◆ ResetVoltage()
|
virtual |
Reset the battery voltage to the initial value. The initial value might have been loaded from an sdf element.
- See also
- Load
◆ SetInitVoltage()
|
virtual |
Set the initial voltage.
- Parameters
-
[in] _voltage Initial voltage.
◆ SetName()
void SetName | ( | const std::string & | _name | ) | const |
Set the name of the battery.
- Parameters
-
[in] _name Name of the battery.
◆ SetPowerLoad()
bool SetPowerLoad | ( | const uint32_t | _consumerId, |
const double | _powerLoad | ||
) |
Set consumer power load in watts.
- Parameters
-
[in] _consumerId Unique consumer identifier. [in] _powerLoad Power load in watts.
- Returns
- True if setting the power load consumption was successful.
◆ SetUpdateFunc()
void SetUpdateFunc | ( | std::function< double(Battery *)> | _updateFunc | ) |
Setup function to update voltage.
- Parameters
-
[in] _updateFunc The update function callback that is used to modify the battery's voltage. The parameter to the update function callback is a reference to an instance of Battery::UpdateData. The update function must return the new battery voltage as a double.
- See also
- UpdateData
◆ Update()
void Update | ( | ) |
Update the battery. This will in turn trigger the function set using the SetUpdateFunc function.
- See also
- SetUpdateFunc.
◆ Voltage()
double Voltage | ( | ) | const |
Get the real voltage in volts.
- Returns
- Voltage.
The documentation for this class was generated from the following file: