Gazebo Common

API Reference

4.7.0
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 <map>
21 #include <string>
22 #include <functional>
23 #include <memory>
24 
25 #include <gz/common/config.hh>
26 #include <gz/common/Export.hh>
28 
29 namespace ignition
30 {
31  namespace common
32  {
33  // Forward declare private data class.
34  class BatteryPrivate;
35 
46  class IGNITION_COMMON_VISIBLE Battery
47  {
51 
53  public: explicit Battery();
54 
58  public: Battery(const std::string &_name, const double _voltage);
59 
62  public: Battery(const Battery &_battery);
63 
67  public: Battery &operator=(const Battery &_battery);
68 
70  public: virtual ~Battery();
71 
76  public: bool operator==(const Battery &_battery) const;
77 
82  public: bool operator!=(const Battery &_battery) const;
83 
85  public: virtual void Init();
86 
90  public: virtual void ResetVoltage();
91 
94  public: double InitVoltage() const;
95 
98  public: virtual void SetInitVoltage(const double _voltage);
99 
102  public: std::string Name() const;
103 
106  public: void SetName(const std::string &_name) const;
107 
110  public: uint32_t AddConsumer();
111 
116  public: bool RemoveConsumer(const uint32_t _consumerId);
117 
122  public: bool SetPowerLoad(const uint32_t _consumerId,
123  const double _powerLoad);
124 
129  public: bool PowerLoad(const uint32_t _consumerId,
130  double &_powerLoad) const;
131 
134  public: const PowerLoad_M &PowerLoads() const;
135 
138  public: double Voltage() const;
139 
147  public: void SetUpdateFunc(
148  std::function<double (Battery *)> _updateFunc);
149 
153  public: void ResetUpdateFunc();
154 
158  public: void Update();
159 
161  protected: void InitConsumers();
162 
166  private: double UpdateDefault(Battery *_battery);
167 
171  private: std::unique_ptr<BatteryPrivate> dataPtr;
173  };
174 
178  }
179 }
180 #endif
uint32_t AddConsumer()
Create a unique consumer.
virtual void Init()
Initialize.
Forward declarations for the common classes.
STL class.
STL class.
double InitVoltage() const
Return the initial voltage.
#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
std::string Name() const
Return the name of the battery.
void SetName(const std::string &_name) const
Set the name of the battery.
void ResetUpdateFunc()
Reset function to update voltage, upon destruction of current callback function.
bool RemoveConsumer(const uint32_t _consumerId)
Remove a consumer.
A battery abstraction.
Definition: gz/common/Battery.hh:46
void InitConsumers()
Initialize the list of consumers.
std::shared_ptr< Battery > BatteryPtr
Definition: gz/common/Battery.hh:177
virtual ~Battery()
Destructor.
STL class.
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.
void Update()
Update the battery. This will in turn trigger the function set using the SetUpdateFunc function.
bool PowerLoad(const uint32_t _consumerId, double &_powerLoad) const
Get consumer power load in watts.
virtual void ResetVoltage()
Reset the battery voltage to the initial value. The initial value might have been loaded from an sdf ...
bool operator==(const Battery &_battery) const
Equal to operator.
const PowerLoad_M & PowerLoads() const
Get list of power loads in watts.
double Voltage() const
Get the real voltage in volts.
bool operator!=(const Battery &_battery) const
Inequality operator.
std::map< uint32_t, double > PowerLoad_M
Typedef the powerload map.
Definition: gz/common/Battery.hh:50
Battery & operator=(const Battery &_battery)
Assignment operator.
void SetUpdateFunc(std::function< double(Battery *)> _updateFunc)
Setup function to update voltage.
#define IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
Definition: gz/common/SuppressWarning.hh:68