Battery.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015-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 _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 
71  public: virtual void UpdateParameters(const sdf::ElementPtr _sdf);
72 
75  public: std::string Name() const;
76 
79  public: uint32_t AddConsumer();
80 
85  public: bool RemoveConsumer(const uint32_t _consumerId);
86 
91  public: bool SetPowerLoad(const uint32_t _consumerId,
92  const double _powerLoad);
93 
98  public: bool PowerLoad(const uint32_t _consumerId,
99  double &_powerLoad) const;
100 
103  public: const PowerLoad_M &PowerLoads() const;
104 
107  public: double Voltage() const;
108 
116  public: void SetUpdateFunc(
117  std::function<double (const BatteryPtr &)> _updateFunc);
118 
122  public: void Update();
123 
125  protected: void InitConsumers();
126 
130  private: double UpdateDefault(const BatteryPtr &_battery);
131 
134  private: BatteryPrivate *dataPtr;
135  };
137  }
138 }
139 #endif
Forward declarations for the common classes.
Definition: Animation.hh:33
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:144
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.