Public Member Functions | Private Attributes | List of all members
BatteryMonitor Class Reference

A driver for analog battery monitors. More...

#include <battery_monitor.h>

Public Member Functions

bool has_current_sense () const
 Checks if current sense is available. As there isn't hardware to detect this, this simply checks if the current multiplier is non-zero. More...
 
bool has_voltage_sense () const
 Checks if voltage sense is available. As there isn't hardware to detect this, this simply checks if the voltage multiplier is non-zero. More...
 
void init (const BatteryMonitorHardwareStruct &def, AnalogDigitalConverter *adc, float voltage_multiplier=0, float current_multiplier=0)
 Initialize the battery monitor. More...
 
float read_current () const
 Read the current battery current. More...
 
float read_voltage () const
 Read the current battery voltage. More...
 
void set_current_multiplier (double multiplier)
 Sets the current multiplier for the battery monitor. More...
 
void set_voltage_multiplier (double multiplier)
 Sets the voltage multiplier for the battery monitor. More...
 

Private Attributes

float current_multiplier_ {0}
 
AnalogPin current_pin_
 
float voltage_multiplier_ {0}
 
AnalogPin voltage_pin_
 

Detailed Description

A driver for analog battery monitors.

These battery monitors provide an analog voltage proportional to the battery voltage and/or current. This class handles setting up pins and unit conversions. This class does not initialize the ADC.

Definition at line 44 of file battery_monitor.h.

Member Function Documentation

bool BatteryMonitor::has_current_sense ( ) const

Checks if current sense is available. As there isn't hardware to detect this, this simply checks if the current multiplier is non-zero.

Returns
If the current multiplier is non-zero.

Definition at line 68 of file battery_monitor.cpp.

bool BatteryMonitor::has_voltage_sense ( ) const

Checks if voltage sense is available. As there isn't hardware to detect this, this simply checks if the voltage multiplier is non-zero.

Returns
If the voltage multiplier is non-zero.

Definition at line 63 of file battery_monitor.cpp.

void BatteryMonitor::init ( const BatteryMonitorHardwareStruct def,
AnalogDigitalConverter adc,
float  voltage_multiplier = 0,
float  current_multiplier = 0 
)

Initialize the battery monitor.

Does not initialize the ADC. The ADC must be initialized before calling.

Parameters
defThe hardware definition struct for the battery monitor, mostly pin info
adcThe ADC used for the monitor. Must be initialized already
voltage_multiplierThe voltage multiplier. Set to 0 for no voltage sense. See set_voltage_multiplier.
current_multiplierThe current multiplier. Set to 0 for no current sense. See set_current_multiplier

Definition at line 34 of file battery_monitor.cpp.

float BatteryMonitor::read_current ( ) const

Read the current battery current.

Returns
The current battery current, or 0 if current sense is not available

Definition at line 48 of file battery_monitor.cpp.

float BatteryMonitor::read_voltage ( ) const

Read the current battery voltage.

Returns
The current battery voltage, or 0 if voltage sense is not available

Definition at line 44 of file battery_monitor.cpp.

void BatteryMonitor::set_current_multiplier ( double  multiplier)

Sets the current multiplier for the battery monitor.

Analog battery monitors which support current measurement generate a voltage proportional to the current through them. This voltage is read by the ADC, and then multiplied by the current multiplier to measure the current. I.e BatteryCurrent = ADCVoltage * CurrentMultiplier. This number can be obtained from the spec sheet for the battery monitor. This value is in amps per volt.

Parameters
multiplier

Definition at line 58 of file battery_monitor.cpp.

void BatteryMonitor::set_voltage_multiplier ( double  multiplier)

Sets the voltage multiplier for the battery monitor.

Because the battery voltage is usually much too high for the ADC to read, analog battery monitors use a voltage divider or similar to reduce the voltage to a reasonable level. The voltage read by the ADC is multiplied by the voltage multiplier to get the actual reading. I.e BatteryVoltage = ADCVoltage * VoltageMultiplier. This number can be obtained from the spec sheet for the battery monitor, or through simple math for DIY monitors. This value is in volts per volt (i.e. unitless).

Parameters
multiplierThe new voltage multiplier

Definition at line 53 of file battery_monitor.cpp.

Member Data Documentation

float BatteryMonitor::current_multiplier_ {0}
private

Definition at line 111 of file battery_monitor.h.

AnalogPin BatteryMonitor::current_pin_
private

Definition at line 109 of file battery_monitor.h.

float BatteryMonitor::voltage_multiplier_ {0}
private

Definition at line 110 of file battery_monitor.h.

AnalogPin BatteryMonitor::voltage_pin_
private

Definition at line 108 of file battery_monitor.h.


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


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Thu Apr 15 2021 05:07:58