Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
src
driver
battery.cpp
Go to the documentation of this file.
1
10
/*****************************************************************************
11
** Includes
12
*****************************************************************************/
13
14
#include "../../include/kobuki_driver/modules/battery.hpp"
15
16
/*****************************************************************************
17
** Namespaces
18
*****************************************************************************/
19
20
namespace
kobuki
{
21
22
/*****************************************************************************
23
** Statics
24
*****************************************************************************/
25
26
double
Battery::capacity
= 16.5;
27
double
Battery::low
= 14.0;
28
double
Battery::dangerous
= 13.2;
29
30
/*****************************************************************************
31
** Implementation
32
*****************************************************************************/
39
Battery::Battery
(
const
uint8_t &new_voltage,
const
uint8_t &charger_flag) :
40
voltage(static_cast<double>(new_voltage)/10.0)
41
{
42
uint8_t state = (charger_flag &
CoreSensors::Flags::BatteryStateMask
);
43
if
( state ==
CoreSensors::Flags::Charging
) {
44
charging_state
=
Charging
;
45
}
else
if
( state ==
CoreSensors::Flags::Charged
) {
46
charging_state
=
Charged
;
47
capacity
=
voltage
;
48
}
else
{
49
charging_state
=
Discharging
;
50
}
51
52
if
(
charging_state
==
Discharging
) {
53
charging_source
=
None
;
54
}
else
if
( charger_flag &
CoreSensors::Flags::AdapterType
) {
55
charging_source
=
Adapter
;
56
}
else
{
57
charging_source
=
Dock
;
58
}
59
};
60
61
Battery::Level
Battery::level
()
const
{
62
if
(
charging_state
==
Charged
) {
return
Maximum
; }
63
if
(
voltage
>
low
) {
return
Healthy
; }
64
if
(
voltage
>
dangerous
) {
return
Low
; }
65
return
Dangerous
;
66
}
67
68
float
Battery::percent
()
const
{
69
// convert battery voltage to percent: 100% -> capacity / 5% -> dangerous
70
float
percent
= ((95*(
voltage
-
dangerous
)) / (
capacity
-
dangerous
)) + 5;
71
return
std::max(std::min(percent, 100.0f), 0.0f);
72
}
73
74
}
// namespace kobuki
kobuki::Battery::low
static double low
Definition:
battery.hpp:65
kobuki::Battery::Battery
Battery()
Definition:
battery.hpp:59
kobuki::Battery::charging_source
Source charging_source
Definition:
battery.hpp:69
kobuki::CoreSensors::Flags::BatteryStateMask
static const uint8_t BatteryStateMask
Definition:
core_sensors.hpp:79
kobuki::Battery::level
Level level() const
Definition:
battery.cpp:61
kobuki::CoreSensors::Flags::Charging
static const uint8_t Charging
Definition:
core_sensors.hpp:82
kobuki::Battery::Discharging
Definition:
battery.hpp:54
kobuki::Battery::Charging
Definition:
battery.hpp:56
kobuki::Battery::Low
Definition:
battery.hpp:49
kobuki::Battery::Maximum
Definition:
battery.hpp:51
kobuki
Definition:
command.hpp:31
kobuki::Battery::Adapter
Definition:
battery.hpp:44
kobuki::CoreSensors::Flags::AdapterType
static const uint8_t AdapterType
Definition:
core_sensors.hpp:77
kobuki::Battery::Dock
Definition:
battery.hpp:45
kobuki::Battery::Healthy
Definition:
battery.hpp:50
kobuki::Battery::Dangerous
Definition:
battery.hpp:48
kobuki::Battery::charging_state
State charging_state
Definition:
battery.hpp:68
kobuki::Battery::percent
float percent() const
Definition:
battery.cpp:68
kobuki::Battery::voltage
double voltage
Definition:
battery.hpp:67
kobuki::Battery::Charged
Definition:
battery.hpp:55
kobuki::Battery::None
Definition:
battery.hpp:43
kobuki::Battery::capacity
static double capacity
Definition:
battery.hpp:64
kobuki::Battery::dangerous
static double dangerous
Definition:
battery.hpp:66
kobuki::Battery::Level
Level
Definition:
battery.hpp:47
kobuki::CoreSensors::Flags::Charged
static const uint8_t Charged
Definition:
core_sensors.hpp:81
kobuki_driver
Author(s): Daniel Stonier
, Younghun Ju
, Jorge Santos Simon
autogenerated on Mon Mar 27 2017 01:02:59