Battery.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 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 _GAZEBO_BATTERY_HH_
18 #define _GAZEBO_BATTERY_HH_
19 
20 #include <map>
21 #include <string>
22 #include <functional>
23 #include <memory>
24 
25 #include "sdf/sdf.hh"
27 #include "gazebo/util/system.hh"
28 
29 namespace gazebo
30 {
31  namespace common
32  {
33  // Forward declare private data class.
34  class BatteryPrivate;
35 
38 
49  class GZ_COMMON_VISIBLE Battery :
50  public std::enable_shared_from_this<Battery>
51  {
54  public: typedef std::map<uint32_t, double> PowerLoad_M;
55 
57  public: explicit Battery();
58 
60  public: virtual ~Battery();
61 
64  public: virtual void Load(sdf::ElementPtr _sdf);
65 
67  public: virtual void Init();
68 
72  public: virtual void ResetVoltage();
73 
76  public: virtual void UpdateParameters(const sdf::ElementPtr _sdf);
77 
80  public: std::string Name() const;
81 
84  public: uint32_t AddConsumer();
85 
90  public: bool RemoveConsumer(const uint32_t _consumerId);
91 
96  public: bool SetPowerLoad(const uint32_t _consumerId,
97  const double _powerLoad);
98 
103  public: bool PowerLoad(const uint32_t _consumerId,
104  double &_powerLoad) const;
105 
108  public: const PowerLoad_M &PowerLoads() const;
109 
112  public: double Voltage() const;
113 
121  public: void SetUpdateFunc(
122  std::function<double (const BatteryPtr &)> _updateFunc);
123 
127  public: void Update();
128 
130  protected: void InitConsumers();
131 
135  private: double UpdateDefault(const BatteryPtr &_battery);
136 
139  private: BatteryPrivate *dataPtr;
140  };
142  }
143 }
144 #endif
std::map< uint32_t, double > PowerLoad_M
Typedef the powerload map.
Definition: Battery.hh:54
A battery abstraction.
Definition: Battery.hh:49
std::shared_ptr< Battery > BatteryPtr
Definition: CommonTypes.hh:125
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.