Skip to content

Commit

Permalink
battery_status: remove unused smart battery mode
Browse files Browse the repository at this point in the history
  • Loading branch information
MaEtUgR authored and sfuhrer committed Jul 30, 2024
1 parent a18c18e commit ba57924
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 80 deletions.
7 changes: 0 additions & 7 deletions msg/BatteryStatus.msg
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,6 @@ uint8 BATTERY_FAULT_COUNT = 11 # Counter - keep it as last element!

uint16 faults # Smart battery supply status/fault flags (bitmask) for health indication.
uint8 warning # Current battery warning
uint8 mode # Battery mode. Note, the normal operation mode

uint8 BATTERY_MODE_UNKNOWN = 0 # Battery does not support a mode, or if it does, is operational
uint8 BATTERY_MODE_AUTO_DISCHARGING = 1 # Battery is auto discharging (towards storage level)
uint8 BATTERY_MODE_HOT_SWAP = 2 # Battery in hot-swap mode
uint8 BATTERY_MODE_COUNT = 3 # Counter - keep it as last element (once we're fully migrated to events interface we can just comment this)!


uint8 MAX_INSTANCES = 4

Expand Down
18 changes: 0 additions & 18 deletions src/lib/events/enums.json
Original file line number Diff line number Diff line change
Expand Up @@ -660,24 +660,6 @@
}
}
},
"battery_mode_t": {
"type": "uint8_t",
"description": "Smart battery modes of operation",
"entries": {
"0": {
"name": "unknown",
"description": "unknown"
},
"1": {
"name": "autodischarging",
"description": "auto discharging towards storage level"
},
"2": {
"name": "hotswap",
"description": "hot-swap"
}
}
},
"esc_fault_reason_t": {
"type": "uint8_t",
"description": "Bitfield for ESC failure reason",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,6 @@ static constexpr const char *battery_fault_reason_str(battery_fault_reason_t bat
return "";
};


using battery_mode_t = events::px4::enums::battery_mode_t;
static_assert(battery_status_s::BATTERY_MODE_COUNT == (static_cast<uint8_t>(battery_mode_t::_max) + 1)
, "Battery mode flags mismatch!");
static constexpr const char *battery_mode_str(battery_mode_t battery_mode)
{
switch (battery_mode) {
case battery_mode_t::autodischarging: return "auto discharging";

case battery_mode_t::hotswap: return "hot-swap";

default: return "unknown";
}
}


void BatteryChecks::checkAndReport(const Context &context, Report &reporter)
{
if (circuit_breaker_enabled_by_val(_param_cbrk_supply_chk.get(), CBRK_SUPPLY_CHK_KEY)) {
Expand Down Expand Up @@ -133,34 +117,18 @@ void BatteryChecks::checkAndReport(const Context &context, Report &reporter)
_battery_connected_at_arming[index] = battery.connected;
}

if (context.isArmed()) {

if (!battery.connected && _battery_connected_at_arming[index]) { // If disconnected after arming
/* EVENT
*/
reporter.healthFailure<uint8_t>(NavModes::All, health_component_t::battery, events::ID("check_battery_disconnected"),
events::Log::Emergency, "Battery {1} disconnected", index + 1);

if (reporter.mavlink_log_pub()) {
mavlink_log_critical(reporter.mavlink_log_pub(), "Battery %i disconnected\t", index + 1);
}
if (context.isArmed() && !battery.connected && _battery_connected_at_arming[index]) { // If disconnected after arming
/* EVENT
*/
reporter.healthFailure<uint8_t>(NavModes::All, health_component_t::battery, events::ID("check_battery_disconnected"),
events::Log::Emergency, "Battery {1} disconnected", index + 1);

// trigger a battery failsafe action if a battery disconnects in flight
worst_warning = battery_status_s::BATTERY_WARNING_CRITICAL;
if (reporter.mavlink_log_pub()) {
mavlink_log_critical(reporter.mavlink_log_pub(), "Battery %i disconnected\t", index + 1);
}

if (battery.mode != 0) {
/* EVENT
*/
reporter.healthFailure<uint8_t, events::px4::enums::battery_mode_t>(NavModes::All, health_component_t::battery,
events::ID("check_battery_mode"),
events::Log::Critical, "Battery {1} mode: {2}", index + 1, static_cast<battery_mode_t>(battery.mode));

if (reporter.mavlink_log_pub()) {
mavlink_log_critical(reporter.mavlink_log_pub(), "Battery %d is in %s mode!\t", index + 1,
battery_mode_str(static_cast<battery_mode_t>(battery.mode)));
}
}
// trigger a battery failsafe action if a battery disconnects in flight
worst_warning = battery_status_s::BATTERY_WARNING_CRITICAL;
}

if (battery.connected) {
Expand Down
15 changes: 1 addition & 14 deletions src/modules/mavlink/streams/BATTERY_STATUS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,7 @@ class MavlinkStreamBatteryStatus : public MavlinkStream
break;
}

switch (battery_status.mode) {
case (battery_status_s::BATTERY_MODE_AUTO_DISCHARGING):
bat_msg.mode = MAV_BATTERY_MODE_AUTO_DISCHARGING;
break;

case (battery_status_s::BATTERY_MODE_HOT_SWAP):
bat_msg.mode = MAV_BATTERY_MODE_HOT_SWAP;
break;

default:
bat_msg.mode = MAV_BATTERY_MODE_UNKNOWN;
break;
}

bat_msg.mode = MAV_BATTERY_MODE_UNKNOWN;
bat_msg.fault_bitmask = battery_status.faults;

// check if temperature valid
Expand Down

0 comments on commit ba57924

Please sign in to comment.