APM:Libraries
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
AP_BattMonitor Class Reference

#include <AP_BattMonitor.h>

Collaboration diagram for AP_BattMonitor:
[legend]

Classes

struct  BattMonitor_State
 
struct  cells
 

Public Types

enum  BatteryFailsafe { BatteryFailsafe_None = 0, BatteryFailsafe_Low, BatteryFailsafe_Critical }
 

Public Member Functions

 FUNCTOR_TYPEDEF (battery_failsafe_handler_fn_t, void, const char *, const int8_t)
 
 AP_BattMonitor (uint32_t log_battery_bit, battery_failsafe_handler_fn_t battery_failsafe_handler_fn, const int8_t *failsafe_priorities)
 
 AP_BattMonitor (const AP_BattMonitor &other)=delete
 
AP_BattMonitoroperator= (const AP_BattMonitor &)=delete
 
uint8_t num_instances (void) const
 
void init ()
 
void read ()
 Read the battery voltage and current for all batteries. Should be called at 10hz. More...
 
bool healthy (uint8_t instance) const
 
bool healthy () const
 
bool has_consumed_energy (uint8_t instance) const
 has_consumed_energy - returns true if battery monitor instance provides consumed energy info More...
 
bool has_consumed_energy () const
 
bool has_current (uint8_t instance) const
 has_current - returns true if battery monitor instance provides current info More...
 
bool has_current () const
 
float voltage (uint8_t instance) const
 voltage - returns battery voltage in millivolts More...
 
float voltage () const
 
float voltage_resting_estimate (uint8_t instance) const
 
float voltage_resting_estimate () const
 
float current_amps (uint8_t instance) const
 current_amps - returns the instantaneous current draw in amperes More...
 
float current_amps () const
 
float consumed_mah (uint8_t instance) const
 consumed_mah - returns total current drawn since start-up in milliampere.hours More...
 
float consumed_mah () const
 
float consumed_wh (uint8_t instance) const
 consumed_wh - returns total energy drawn since start-up in watt.hours More...
 
float consumed_wh () const
 
virtual uint8_t capacity_remaining_pct (uint8_t instance) const
 capacity_remaining_pct - returns the % battery capacity remaining (0 ~ 100) More...
 
uint8_t capacity_remaining_pct () const
 
int32_t pack_capacity_mah (uint8_t instance) const
 pack_capacity_mah - returns the capacity of the battery pack in mAh when the pack is full More...
 
int32_t pack_capacity_mah () const
 
BatteryFailsafe check_failsafe (const uint8_t instance)
 returns the failsafe state of the battery More...
 
void check_failsafes (void)
 
bool has_failsafed (void) const
 returns true if a battery failsafe has ever been triggered More...
 
int8_t get_highest_failsafe_priority (void) const
 returns the highest failsafe action that has been triggered More...
 
enum AP_BattMonitor_Params::BattMonitor_Type get_type ()
 get_type - returns battery monitor type More...
 
enum AP_BattMonitor_Params::BattMonitor_Type get_type (uint8_t instance)
 
void set_monitoring (uint8_t instance, uint8_t mon)
 set_monitoring - sets the monitor type (used for example sketch only) More...
 
bool overpower_detected () const
 true when (voltage * current) > watt_max More...
 
bool overpower_detected (uint8_t instance) const
 
bool has_cell_voltages ()
 
bool has_cell_voltages (const uint8_t instance) const
 
const cellsget_cell_voltages () const
 
const cellsget_cell_voltages (const uint8_t instance) const
 
bool get_temperature (float &temperature) const
 
bool get_temperature (float &temperature, const uint8_t instance) const
 
float get_resistance () const
 
float get_resistance (uint8_t instance) const
 

Static Public Member Functions

static AP_BattMonitorbattery ()
 

Static Public Attributes

static const struct AP_Param::GroupInfo var_info []
 

Protected Attributes

AP_BattMonitor_Params _params [AP_BATT_MONITOR_MAX_INSTANCES]
 parameters More...
 

Private Member Functions

void convert_params (void)
 number of monitors More...
 

Private Attributes

BattMonitor_State state [AP_BATT_MONITOR_MAX_INSTANCES]
 
AP_BattMonitor_Backenddrivers [AP_BATT_MONITOR_MAX_INSTANCES]
 
uint32_t _log_battery_bit
 
uint8_t _num_instances
 
battery_failsafe_handler_fn_t _battery_failsafe_handler_fn
 
const int8_t * _failsafe_priorities
 
int8_t _highest_failsafe_priority
 
bool _has_triggered_failsafe
 

Static Private Attributes

static AP_BattMonitor_singleton
 

Friends

class AP_BattMonitor_Backend
 
class AP_BattMonitor_Analog
 
class AP_BattMonitor_SMBus
 
class AP_BattMonitor_SMBus_Solo
 
class AP_BattMonitor_SMBus_Maxell
 
class AP_BattMonitor_UAVCAN
 

Detailed Description

Definition at line 30 of file AP_BattMonitor.h.

Member Enumeration Documentation

◆ BatteryFailsafe

Enumerator
BatteryFailsafe_None 
BatteryFailsafe_Low 
BatteryFailsafe_Critical 

Definition at line 42 of file AP_BattMonitor.h.

Constructor & Destructor Documentation

◆ AP_BattMonitor() [1/2]

AP_BattMonitor::AP_BattMonitor ( uint32_t  log_battery_bit,
battery_failsafe_handler_fn_t  battery_failsafe_handler_fn,
const int8_t *  failsafe_priorities 
)

Definition at line 34 of file AP_BattMonitor.cpp.

Here is the call graph for this function:

◆ AP_BattMonitor() [2/2]

AP_BattMonitor::AP_BattMonitor ( const AP_BattMonitor other)
delete

Member Function Documentation

◆ battery()

static AP_BattMonitor& AP_BattMonitor::battery ( )
inlinestatic

Definition at line 56 of file AP_BattMonitor.h.

Referenced by AP::battery().

Here is the caller graph for this function:

◆ capacity_remaining_pct() [1/2]

uint8_t AP_BattMonitor::capacity_remaining_pct ( uint8_t  instance) const
virtual

capacity_remaining_pct - returns the % battery capacity remaining (0 ~ 100)

Definition at line 286 of file AP_BattMonitor.cpp.

Referenced by GCS_MAVLINK::send_battery_status(), AP_Frsky_Telem::send_D(), and AP_Frsky_Telem::send_SPort().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ capacity_remaining_pct() [2/2]

uint8_t AP_BattMonitor::capacity_remaining_pct ( ) const
inline

Definition at line 126 of file AP_BattMonitor.h.

Referenced by capacity_remaining_pct(), and consumed_wh().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_failsafe()

AP_BattMonitor::BatteryFailsafe AP_BattMonitor::check_failsafe ( const uint8_t  instance)

returns the failsafe state of the battery

Definition at line 358 of file AP_BattMonitor.cpp.

Referenced by check_failsafes(), and pack_capacity_mah().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_failsafes()

void AP_BattMonitor::check_failsafes ( void  )

Definition at line 305 of file AP_BattMonitor.cpp.

Referenced by pack_capacity_mah(), and read().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ consumed_mah() [1/2]

float AP_BattMonitor::consumed_mah ( uint8_t  instance) const

consumed_mah - returns total current drawn since start-up in milliampere.hours

Definition at line 268 of file AP_BattMonitor.cpp.

Referenced by AP_Frsky_Telem::calc_batt(), DataFlash_Class::Log_Write_Current_instance(), and GCS_MAVLINK::send_battery_status().

Here is the caller graph for this function:

◆ consumed_mah() [2/2]

float AP_BattMonitor::consumed_mah ( ) const
inline

Definition at line 118 of file AP_BattMonitor.h.

Referenced by check_failsafe(), check_failsafes(), consumed_mah(), and current_amps().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ consumed_wh() [1/2]

float AP_BattMonitor::consumed_wh ( uint8_t  instance) const

consumed_wh - returns total energy drawn since start-up in watt.hours

consumed_wh - returns energy consumed since start-up in Watt.hours

Definition at line 277 of file AP_BattMonitor.cpp.

Referenced by DataFlash_Class::Log_Write_Current_instance(), and GCS_MAVLINK::send_battery_status().

Here is the caller graph for this function:

◆ consumed_wh() [2/2]

float AP_BattMonitor::consumed_wh ( ) const
inline

Definition at line 122 of file AP_BattMonitor.h.

Referenced by consumed_mah(), and consumed_wh().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ convert_params()

void AP_BattMonitor::convert_params ( void  )
private

number of monitors

Definition at line 113 of file AP_BattMonitor.cpp.

Referenced by init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ current_amps() [1/2]

float AP_BattMonitor::current_amps ( uint8_t  instance) const

current_amps - returns the instantaneous current draw in amperes

Definition at line 259 of file AP_BattMonitor.cpp.

Referenced by AP_Frsky_Telem::calc_batt(), AP_Compass_Backend::correct_field(), AP_MotorsMulticopter::get_current_limit_max_throttle(), DataFlash_Class::Log_Write_Current_instance(), AP_Motors6DOF::output_armed_stabilizing(), GCS_MAVLINK::send_battery2(), GCS_MAVLINK::send_battery_status(), AP_Frsky_Telem::send_D(), and AP_Frsky_Telem::send_SPort().

Here is the caller graph for this function:

◆ current_amps() [2/2]

float AP_BattMonitor::current_amps ( ) const
inline

Definition at line 114 of file AP_BattMonitor.h.

Referenced by current_amps(), and voltage_resting_estimate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FUNCTOR_TYPEDEF()

AP_BattMonitor::FUNCTOR_TYPEDEF ( battery_failsafe_handler_fn_t  ,
void  ,
const char *  ,
const int8_t   
)

◆ get_cell_voltages() [1/2]

const cells& AP_BattMonitor::get_cell_voltages ( ) const
inline

Definition at line 156 of file AP_BattMonitor.h.

Referenced by get_cell_voltages(), DataFlash_Class::Log_Write_Current_instance(), and GCS_MAVLINK::send_battery_status().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_cell_voltages() [2/2]

const AP_BattMonitor::cells & AP_BattMonitor::get_cell_voltages ( const uint8_t  instance) const

Definition at line 455 of file AP_BattMonitor.cpp.

◆ get_highest_failsafe_priority()

int8_t AP_BattMonitor::get_highest_failsafe_priority ( void  ) const
inline

returns the highest failsafe action that has been triggered

Definition at line 140 of file AP_BattMonitor.h.

◆ get_resistance() [1/2]

float AP_BattMonitor::get_resistance ( ) const
inline

Definition at line 164 of file AP_BattMonitor.h.

Referenced by AP_MotorsMulticopter::get_current_limit_max_throttle(), get_resistance(), and DataFlash_Class::Log_Write_Current_instance().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_resistance() [2/2]

float AP_BattMonitor::get_resistance ( uint8_t  instance) const
inline

Definition at line 165 of file AP_BattMonitor.h.

◆ get_temperature() [1/2]

bool AP_BattMonitor::get_temperature ( float &  temperature) const
inline

Definition at line 160 of file AP_BattMonitor.h.

Referenced by get_temperature(), DataFlash_Class::Log_Write_Current_instance(), and GCS_MAVLINK::send_battery_status().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_temperature() [2/2]

bool AP_BattMonitor::get_temperature ( float &  temperature,
const uint8_t  instance 
) const

Definition at line 465 of file AP_BattMonitor.cpp.

Here is the call graph for this function:

◆ get_type() [1/2]

enum AP_BattMonitor_Params::BattMonitor_Type AP_BattMonitor::get_type ( uint8_t  instance)
inline

Definition at line 144 of file AP_BattMonitor.h.

Here is the call graph for this function:

◆ get_type() [2/2]

enum AP_BattMonitor_Params::BattMonitor_Type AP_BattMonitor::get_type ( )
inline

get_type - returns battery monitor type

Definition at line 143 of file AP_BattMonitor.h.

Referenced by init(), and read().

Here is the caller graph for this function:

◆ has_cell_voltages() [1/2]

bool AP_BattMonitor::has_cell_voltages ( )
inline

Definition at line 154 of file AP_BattMonitor.h.

Referenced by has_cell_voltages(), and DataFlash_Class::Log_Write_Current_instance().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ has_cell_voltages() [2/2]

bool AP_BattMonitor::has_cell_voltages ( const uint8_t  instance) const

Definition at line 445 of file AP_BattMonitor.cpp.

Here is the call graph for this function:

◆ has_consumed_energy() [1/2]

bool AP_BattMonitor::has_consumed_energy ( uint8_t  instance) const

has_consumed_energy - returns true if battery monitor instance provides consumed energy info

Definition at line 215 of file AP_BattMonitor.cpp.

Referenced by GCS_MAVLINK::send_battery_status().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ has_consumed_energy() [2/2]

bool AP_BattMonitor::has_consumed_energy ( ) const
inline

Definition at line 97 of file AP_BattMonitor.h.

Referenced by has_consumed_energy(), and healthy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ has_current() [1/2]

bool AP_BattMonitor::has_current ( uint8_t  instance) const

has_current - returns true if battery monitor instance provides current info

Definition at line 226 of file AP_BattMonitor.cpp.

Referenced by AP_Compass_Backend::correct_field(), AP_MotorsMulticopter::get_current_limit_max_throttle(), AP_Motors6DOF::output_armed_stabilizing(), GCS_MAVLINK::send_battery2(), and GCS_MAVLINK::send_battery_status().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ has_current() [2/2]

bool AP_BattMonitor::has_current ( ) const
inline

Definition at line 101 of file AP_BattMonitor.h.

Referenced by check_failsafe(), has_consumed_energy(), and has_current().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ has_failsafed()

bool AP_BattMonitor::has_failsafed ( void  ) const
inline

returns true if a battery failsafe has ever been triggered

Definition at line 137 of file AP_BattMonitor.h.

◆ healthy() [1/2]

bool AP_BattMonitor::healthy ( uint8_t  instance) const

Definition at line 210 of file AP_BattMonitor.cpp.

◆ healthy() [2/2]

bool AP_BattMonitor::healthy ( void  ) const
inline

Definition at line 93 of file AP_BattMonitor.h.

Referenced by healthy(), and num_instances().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init()

void AP_BattMonitor::init ( void  )

Definition at line 50 of file AP_BattMonitor.cpp.

Referenced by num_instances().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ num_instances()

uint8_t AP_BattMonitor::num_instances ( void  ) const
inline

Definition at line 83 of file AP_BattMonitor.h.

Referenced by AP_Arming::battery_checks(), DataFlash_Class::Log_Write_Current(), GCS_MAVLINK::send_battery2(), GCS_MAVLINK::send_battery_status(), and AP_Frsky_Telem::send_SPort_Passthrough().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

AP_BattMonitor& AP_BattMonitor::operator= ( const AP_BattMonitor )
delete

◆ overpower_detected() [1/2]

bool AP_BattMonitor::overpower_detected ( ) const

true when (voltage * current) > watt_max

Definition at line 423 of file AP_BattMonitor.cpp.

Referenced by set_monitoring().

Here is the caller graph for this function:

◆ overpower_detected() [2/2]

bool AP_BattMonitor::overpower_detected ( uint8_t  instance) const

Definition at line 432 of file AP_BattMonitor.cpp.

◆ pack_capacity_mah() [1/2]

int32_t AP_BattMonitor::pack_capacity_mah ( uint8_t  instance) const

pack_capacity_mah - returns the capacity of the battery pack in mAh when the pack is full

Definition at line 296 of file AP_BattMonitor.cpp.

Referenced by AP_Frsky_Telem::calc_param().

Here is the caller graph for this function:

◆ pack_capacity_mah() [2/2]

int32_t AP_BattMonitor::pack_capacity_mah ( ) const
inline

Definition at line 130 of file AP_BattMonitor.h.

Referenced by capacity_remaining_pct(), and pack_capacity_mah().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read()

void AP_BattMonitor::read ( void  )

Read the battery voltage and current for all batteries. Should be called at 10hz.

Definition at line 187 of file AP_BattMonitor.cpp.

Referenced by num_instances().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_monitoring()

void AP_BattMonitor::set_monitoring ( uint8_t  instance,
uint8_t  mon 
)
inline

set_monitoring - sets the monitor type (used for example sketch only)

Definition at line 147 of file AP_BattMonitor.h.

Here is the call graph for this function:

◆ voltage() [1/2]

float AP_BattMonitor::voltage ( uint8_t  instance) const

voltage - returns battery voltage in millivolts

voltage - returns battery voltage in volts

Definition at line 237 of file AP_BattMonitor.cpp.

Referenced by AP_Arming::battery_checks(), AP_Frsky_Telem::calc_batt(), AP_MotorsMulticopter::get_current_limit_max_throttle(), DataFlash_Class::Log_Write_Current_instance(), GCS_MAVLINK::send_battery2(), AP_Frsky_Telem::send_D(), and AP_Frsky_Telem::send_SPort().

Here is the caller graph for this function:

◆ voltage() [2/2]

float AP_BattMonitor::voltage ( ) const
inline

Definition at line 105 of file AP_BattMonitor.h.

Referenced by check_failsafes(), has_current(), read(), voltage(), and voltage_resting_estimate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ voltage_resting_estimate() [1/2]

float AP_BattMonitor::voltage_resting_estimate ( uint8_t  instance) const

get voltage with sag removed (based on battery current draw and resistance) this will always be greater than or equal to the raw voltage

Definition at line 248 of file AP_BattMonitor.cpp.

Referenced by DataFlash_Class::Log_Write_Current_instance(), and AP_MotorsMulticopter::update_lift_max_from_batt_voltage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ voltage_resting_estimate() [2/2]

float AP_BattMonitor::voltage_resting_estimate ( ) const
inline

Definition at line 110 of file AP_BattMonitor.h.

Referenced by check_failsafe(), voltage(), and voltage_resting_estimate().

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ AP_BattMonitor_Analog

friend class AP_BattMonitor_Analog
friend

Definition at line 33 of file AP_BattMonitor.h.

Referenced by init().

◆ AP_BattMonitor_Backend

friend class AP_BattMonitor_Backend
friend

Definition at line 32 of file AP_BattMonitor.h.

◆ AP_BattMonitor_SMBus

friend class AP_BattMonitor_SMBus
friend

Definition at line 34 of file AP_BattMonitor.h.

◆ AP_BattMonitor_SMBus_Maxell

friend class AP_BattMonitor_SMBus_Maxell
friend

Definition at line 36 of file AP_BattMonitor.h.

Referenced by init().

◆ AP_BattMonitor_SMBus_Solo

friend class AP_BattMonitor_SMBus_Solo
friend

Definition at line 35 of file AP_BattMonitor.h.

Referenced by init().

◆ AP_BattMonitor_UAVCAN

friend class AP_BattMonitor_UAVCAN
friend

Definition at line 37 of file AP_BattMonitor.h.

Referenced by init().

Member Data Documentation

◆ _battery_failsafe_handler_fn

battery_failsafe_handler_fn_t AP_BattMonitor::_battery_failsafe_handler_fn
private

Definition at line 184 of file AP_BattMonitor.h.

Referenced by check_failsafes().

◆ _failsafe_priorities

const int8_t* AP_BattMonitor::_failsafe_priorities
private

Definition at line 185 of file AP_BattMonitor.h.

Referenced by check_failsafes().

◆ _has_triggered_failsafe

bool AP_BattMonitor::_has_triggered_failsafe
private

Definition at line 188 of file AP_BattMonitor.h.

Referenced by check_failsafes(), and has_failsafed().

◆ _highest_failsafe_priority

int8_t AP_BattMonitor::_highest_failsafe_priority
private

Definition at line 187 of file AP_BattMonitor.h.

Referenced by check_failsafes(), get_highest_failsafe_priority(), and init().

◆ _log_battery_bit

uint32_t AP_BattMonitor::_log_battery_bit
private

Definition at line 179 of file AP_BattMonitor.h.

Referenced by read().

◆ _num_instances

uint8_t AP_BattMonitor::_num_instances
private

◆ _params

AP_BattMonitor_Params AP_BattMonitor::_params[AP_BATT_MONITOR_MAX_INSTANCES]
protected

◆ _singleton

AP_BattMonitor * AP_BattMonitor::_singleton
staticprivate

Definition at line 175 of file AP_BattMonitor.h.

Referenced by AP_BattMonitor(), and battery().

◆ drivers

AP_BattMonitor_Backend* AP_BattMonitor::drivers[AP_BATT_MONITOR_MAX_INSTANCES]
private

◆ state

BattMonitor_State AP_BattMonitor::state[AP_BATT_MONITOR_MAX_INSTANCES]
private

◆ var_info

const AP_Param::GroupInfo AP_BattMonitor::var_info
static

The documentation for this class was generated from the following files: