Class that manages the battery of the vehicle. More...
#include <BatteryController.hpp>
Public Member Functions | |
BatteryController (II2CController *i2cController=nullptr) | |
Construct a new BatteryController object. | |
~BatteryController () override | |
Destroy the BatteryController object. | |
float | getBatteryPercentage () override |
Get the battery percentage. | |
![]() | |
virtual | ~IBatteryController ()=default |
Private Member Functions | |
void | setCalibration32V2A () |
Set the calibration for 32V and 2A. | |
float | getBusVoltage_V () |
Get the bus voltage in volts. | |
float | getShuntVoltage_V () |
Get the shunt voltage in volts. | |
Private Attributes | |
II2CController * | m_i2cController |
bool | m_ownI2CController |
Class that manages the battery of the vehicle.
Definition at line 27 of file BatteryController.hpp.
|
explicit |
Construct a new BatteryController object.
i2cController | The I2C controller to use for communication with the INA219. If nullptr , a default I2C controller is created. |
This constructor initializes the BatteryController object with the specified I2C controller and address. If i2cController
is nullptr
, a default I2C controller is created.
Definition at line 38 of file BatteryController.cpp.
|
override |
Destroy the BatteryController object.
This destructor releases any resources allocated by the BatteryController object. If the object created its own I2C controller, it is deleted.
Definition at line 51 of file BatteryController.cpp.
|
overridevirtual |
Get the battery percentage.
This function calculates the battery percentage based on the bus and shunt voltages.
Implements IBatteryController.
Definition at line 103 of file BatteryController.cpp.
|
private |
Get the bus voltage in volts.
This function reads the raw bus voltage register value from the INA219 sensor, shifts it to align with the measurement resolution, and converts it to volts.
Definition at line 78 of file BatteryController.cpp.
|
private |
Get the shunt voltage in volts.
This function reads the raw shunt voltage register value from the INA219 sensor, shifts it to align with the measurement resolution, and converts it to volts.
Definition at line 91 of file BatteryController.cpp.
|
private |
Set the calibration for 32V and 2A.
This function writes a predefined calibration value to the calibration register of the INA219 sensor to configure it for a voltage range of 32V and a maximum current of 2A.
Definition at line 65 of file BatteryController.cpp.
|
private |
Definition at line 40 of file BatteryController.hpp.
|
private |
Definition at line 41 of file BatteryController.hpp.