Gazebo Common

API Reference

4.8.1
gz/common/Battery.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef IGNITION_COMMON_BATTERY_HH_
18 #define IGNITION_COMMON_BATTERY_HH_
19 
20 #include <cstdint>
21 #include <map>
22 #include <string>
23 #include <functional>
24 #include <memory>
25 
26 #include <gz/common/config.hh>
27 #include <gz/common/Export.hh>
29 
30 namespace ignition
31 {
32  namespace common
33  {
34  // Forward declare private data class.
35  class BatteryPrivate;
36 
47  class IGNITION_COMMON_VISIBLE Battery
48  {
52 
54  public: explicit Battery();
55 
59  public: Battery(const std::string &_name, const double _voltage);
60 
63  public: Battery(const Battery &_battery);
64 
68  public: Battery &operator=(const Battery &_battery);
69 
71  public: virtual ~Battery();
72 
77  public: bool operator==(const Battery &_battery) const;
78 
83  public: bool operator!=(const Battery &_battery) const;
84 
86  public: virtual void Init();
87 
91  public: virtual void ResetVoltage();
92 
95  public: double InitVoltage() const;
96 
99  public: virtual void SetInitVoltage(const double _voltage);
100 
103  public: std::string Name() const;
104 
107  public: void SetName(const std::string &_name) const;
108 
111  public: uint32_t AddConsumer();
112 
117  public: bool RemoveConsumer(const uint32_t _consumerId);
118 
123  public: bool SetPowerLoad(const uint32_t _consumerId,
124  const double _powerLoad);
125 
130  public: bool PowerLoad(const uint32_t _consumerId,
131  double &_powerLoad) const;
132 
135  public: const PowerLoad_M &PowerLoads() const;
136 
139  public: double Voltage() const;
140 
148  public: void SetUpdateFunc(
149  std::function<double (Battery *)> _updateFunc);
150 
154  public: void ResetUpdateFunc();
155 
159  public: void Update();
160 
162  protected: void InitConsumers();
163 
167  private: double UpdateDefault(Battery *_battery);
168 
172  private: std::unique_ptr<BatteryPrivate> dataPtr;
174  };
175 
179  }
180 }
181 #endif
A battery abstraction.
Definition: gz/common/Battery.hh:48
void InitConsumers()
Initialize the list of consumers.
virtual void Init()
Initialize.
std::string Name() const
Return the name of the battery.
Battery(const std::string &_name, const double _voltage)
Constructor that sets the name and initial voltage.
bool operator!=(const Battery &_battery) const
Inequality operator.
void SetUpdateFunc(std::function< double(Battery *)> _updateFunc)
Setup function to update voltage.
void SetName(const std::string &_name) const
Set the name of the battery.
virtual void ResetVoltage()
Reset the battery voltage to the initial value. The initial value might have been loaded from an sdf ...
std::map< uint32_t, double > PowerLoad_M
Typedef the powerload map.
Definition: gz/common/Battery.hh:51
virtual void SetInitVoltage(const double _voltage)
Set the initial voltage.
bool SetPowerLoad(const uint32_t _consumerId, const double _powerLoad)
Set consumer power load in watts.
double InitVoltage() const
Return the initial voltage.
bool PowerLoad(const uint32_t _consumerId, double &_powerLoad) const
Get consumer power load in watts.
virtual ~Battery()
Destructor.
double Voltage() const
Get the real voltage in volts.
Battery(const Battery &_battery)
Copy constructor.
Battery & operator=(const Battery &_battery)
Assignment operator.
void ResetUpdateFunc()
Reset function to update voltage, upon destruction of current callback function.
bool operator==(const Battery &_battery) const
Equal to operator.
const PowerLoad_M & PowerLoads() const
Get list of power loads in watts.
bool RemoveConsumer(const uint32_t _consumerId)
Remove a consumer.
void Update()
Update the battery. This will in turn trigger the function set using the SetUpdateFunc function.
uint32_t AddConsumer()
Create a unique consumer.
#define IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
Microsoft Visual Studio does not automatically export the interface information for member variables ...
Definition: gz/common/SuppressWarning.hh:65
#define IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
Definition: gz/common/SuppressWarning.hh:68
std::shared_ptr< Battery > BatteryPtr
Definition: gz/common/Battery.hh:178
Forward declarations for the common classes.