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) {
45  } else if ( state == CoreSensors::Flags::Charged ) {
47  capacity = voltage;
48  } else {
50  }
51 
52  if (charging_state == Discharging) {
54  } else if ( charger_flag & CoreSensors::Flags::AdapterType ) {
56  } else {
58  }
59 };
60 
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
static double low
Definition: battery.hpp:65
Source charging_source
Definition: battery.hpp:69
static const uint8_t BatteryStateMask
Level level() const
Definition: battery.cpp:61
static const uint8_t Charging
static const uint8_t AdapterType
State charging_state
Definition: battery.hpp:68
float percent() const
Definition: battery.cpp:68
double voltage
Definition: battery.hpp:67
static double capacity
Definition: battery.hpp:64
void f(int i) ecl_debug_throw_decl(StandardException)
static double dangerous
Definition: battery.hpp:66
static const uint8_t Charged


kobuki_driver
Author(s): Daniel Stonier , Younghun Ju , Jorge Santos Simon
autogenerated on Fri Sep 18 2020 03:22:01