-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AP_BattMonitor: Adds smart battery shutdown framework and TI BQ battery monitor #27288
Conversation
Sibling PR: #27287 |
6bc529a
to
6da890b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should hook into the existing battery power off stuff somehow.
ardupilot/libraries/AP_BattMonitor/AP_BattMonitor.cpp
Lines 1013 to 1014 in e83afcf
// Check's each smart battery instance for its powering off state and broadcasts notifications | |
void AP_BattMonitor::checkPoweringOff(void) |
That is for the shutdown signal coming in from the battery rather than the other way round. But we probably should send that mavlink MAV_CMD_POWER_OFF_INITIATED
in this case too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the shutdown functionality unique to the TI BQ? Or is the new driver really just a flag to say that its SMBus battery that can shutdown?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to update
// @Values: 0:Disabled,3:Analog Voltage Only,4:Analog Voltage and Current,5:Solo,6:Bebop,7:SMBus-Generic,8:DroneCAN-BatteryInfo,9:ESC,10:Sum Of Selected Monitors,11:FuelFlow,12:FuelLevelPWM,13:SMBUS-SUI3,14:SMBUS-SUI6,15:NeoDesign,16:SMBus-Maxell,17:Generator-Elec,18:Generator-Fuel,19:Rotoye,20:MPPT,21:INA2XX,22:LTC2946,23:Torqeedo,24:FuelLevelAnalog,25:Synthetic Current and Analog Voltage,26:INA239_SPI,27:EFI,28:AD7091R5,29:Scripting |
I believe the functionality to command shutdown is not unique to the BQ, but that the back-end interface is chipset specific. Shutting down a TI BQ40Z chip is initiated via SMBus ManufactureAccess() which is not consistent between different SMBus batteries. The bootup logic to clear the EMSHUT flag on the other hand is a BQ-specific requirement, which is why I didn't include any sort of abstraction in AP_BatteryMonitor for that sequence. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please look at how MAV_CMD_BATTERY_RESET is done, this should be similar
@@ -3398,6 +3398,18 @@ MAV_RESULT GCS_MAVLINK::handle_preflight_reboot(const mavlink_command_int_t &pac | |||
} | |||
} | |||
|
|||
#if AP_BATTERY_ENABLED | |||
// Check if shutdown is requested | |||
if (is_equal(packet.param1, 2.0f)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this should be in PREFLIGHT_REBOOT_SHUTDOWN
I think we need MAV_CMD_BATTERY_CONTROL command, which takes a bitmask of batterys to apply this to, and which allows for both shutdown and startup
// Semaphore is needed in case this is called from another thread | ||
WITH_SEMAPHORE(_dev->get_semaphore()); | ||
|
||
uint8_t cmd[] = {0x00, 0x10, 0x00}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uint8_t cmd[] = {0x00, 0x10, 0x00}; | |
static const uint8_t cmd[] {0x00, 0x10, 0x00}; |
WITH_SEMAPHORE(_dev->get_semaphore()); | ||
|
||
uint8_t cmd[] = {0x00, 0x10, 0x00}; | ||
if (!_dev->transfer(cmd, 3, nullptr, 0)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!_dev->transfer(cmd, 3, nullptr, 0)) { | |
if (!_dev->transfer(cmd, sizeof(cmd), nullptr, 0)) { |
} else { | ||
_state.is_powering_off = true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} else { | |
_state.is_powering_off = true; | |
} | |
} | |
_state.is_powering_off = true; |
void AP_BattMonitor_SMBus_TIBQ::timer() { | ||
if (_exit_emshut) { | ||
// Exit EMERGENCY SHUTDOWN state in case it was engaged on the last poweroff: | ||
uint8_t cmd[] = {0x00, 0xA7, 0x23}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uint8_t cmd[] = {0x00, 0xA7, 0x23}; | |
static const uint8_t cmd[] {0x00, 0xA7, 0x23}; |
if (_exit_emshut) { | ||
// Exit EMERGENCY SHUTDOWN state in case it was engaged on the last poweroff: | ||
uint8_t cmd[] = {0x00, 0xA7, 0x23}; | ||
if (_dev->transfer(cmd, 3, nullptr, 0)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (_dev->transfer(cmd, 3, nullptr, 0)) { | |
if (_dev->transfer(cmd, sizeof(cmd), nullptr, 0)) { |
// Attempts to shut down all batteries that support doing so | ||
bool AP_BattMonitor::shutdown() | ||
{ | ||
if (!can_shutdown() || _num_instances == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we be returning "true" for "we can shut down all 0 batteries"?
discussed on dev call, decided the lua approach is better |
Closing as it was decided that this would better fit as a script, which is implemented in #27287 |
Adds ability to command shutdown of a smart-battery system via
PREFLIGHT_REBOOT_SHUTDOWN
, with an example BattMonitor backend that supports being commanded to poweroff.We use the TI BQ40Z60 and BQ40Z80 chips at GreenSight in our Dreamer line of drones, and use this shutdown functionality to allow full system shutdown from a companion computer.
Note that the TI BQ BattMonitor backend also includes logic to reset the chip's emergency shutdown flag upon successful boot. This is used to ensure the battery stays on after charging is initiated.
Similar functionality was also implemented in a sibling PR that uses LUA but which lacks the broader framework for battery shutdown.