-
Notifications
You must be signed in to change notification settings - Fork 7
BMS
Ashish Jaiswal edited this page Jul 21, 2026
·
2 revisions
Battery Management System interface for monitoring battery parameters (voltage, current, and capacity) from the onboard INA219 sensor.
Selects which battery parameter Bms_Get() returns.
typedef enum BMS_Option {
Voltage, // Battery voltage (mV)
Current, // Current through battery (mA)
mAh_Consumed, // Charge consumed (mAh)
mAh_Remain, // Charge remaining (mAh)
Battery_Capicity, // Total battery capacity (mAh)
Estimated_Capacity // Estimated battery capacity (mAh)
} BMS_Option_e;Retrieves a battery management system parameter. Returns the value in the unit
listed for that option above, or 0 if an undefined option is passed.
Battery values change continuously, so read them inside plutoLoop():
void plutoLoop ( void ) {
uint16_t mv = Bms_Get ( Voltage ); // pack voltage in mV, e.g. 3700 = 3.70 V
Monitor_Print ( "Battery mV: ", mv );
}Battery values change continuously, so read them inside plutoLoop().
#include "PlutoPilot.h"
void plutoLoop ( void ) {
uint16_t voltage = Bms_Get ( Voltage ); // mV
uint16_t current = Bms_Get ( Current ); // mA
uint16_t remaining = Bms_Get ( mAh_Remain ); // mAh
uint16_t capacity = Bms_Get ( Battery_Capicity ); // mAh
// Remaining charge as a percentage of total capacity.
uint8_t percent = capacity ? ( uint8_t ) ( ( remaining * 100 ) / capacity ) : 0;
Monitor_Print ( "Voltage(mV): ", voltage );
Monitor_Print ( "Current(mA): ", current );
Monitor_Print ( "Charge(%): ", percent );
// Low-battery warning.
if ( percent < 20 ) {
Monitor_Println ( "Low Battery Warning" );
}
}MagisV2 © 2026 Drona Aviation | Licensed under GPL-3.0 | Report Issues