Skip to content

Support MAVLink BATTERY_STATUS_V2#7

Open
hunt0r wants to merge 12 commits into
masterfrom
support-mavlink-battery-status-v2
Open

Support MAVLink BATTERY_STATUS_V2#7
hunt0r wants to merge 12 commits into
masterfrom
support-mavlink-battery-status-v2

Conversation

@hunt0r

@hunt0r hunt0r commented May 25, 2026

Copy link
Copy Markdown
Owner

This is a draft useful for anchoring discussion on ArduPilot#33196

@hunt0r hunt0r force-pushed the support-mavlink-battery-status-v2 branch from 0a6d621 to d40823a Compare May 25, 2026 23:57
@hunt0r hunt0r force-pushed the master branch 2 times, most recently from c48d113 to fbe129c Compare May 27, 2026 03:32
@hunt0r hunt0r force-pushed the support-mavlink-battery-status-v2 branch from d40823a to da448a3 Compare May 27, 2026 19:51
Comment on lines +339 to +346
#if AP_BATTERY_ENABLED
void send_battery_status(const uint8_t instance) const;
bool send_battery_status();
#if AP_MAVLINK_BATTERY_STATUS_V2_ENABLED
void send_battery_status_v2(const uint8_t instance) const;
bool send_battery_status_v2();
#endif // AP_MAVLINK_BATTERY_STATUS_V2_ENABLED
#endif // AP_BATTERY_ENABLED

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look into making these private.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe even via a separate tiny PR.

Comment on lines +406 to +408
#if AP_BATTERY_ENABLED
int8_t battery_remaining_pct(const uint8_t instance) const;
#endif

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead move this up to the others, or down to the privates.

#if HAL_WITH_MCU_MONITORING
void send_mcu_status(void);
#endif
#if AP_BATTERY_ENABLED

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if AP_BATTERY_ENABLED
#if AP_MAVLINK_BATTERY_STATUS_ENABLED

break;
#endif

#if AP_BATTERY_ENABLED

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if AP_MAVLINK_BATTERY_STATUS_ENABLED

}
}

// return true if reported consumed and remaining capacities are relative to a full battery

@peterbarker peterbarker May 27, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand to say what the alternative is - what might you be otherwise relative to?

return status_flags;
}

status_flags |= MAV_BATTERY_STATUS_FLAGS_NOT_READY_TO_USE |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

struct {
   uint32_t oldval;
   uint32_t newval;
} conversions[] {
    { MAV_BATTERY_FAULT_DEEP_DISCHARGE, MAV_BATTERY_STATUS_FLAGS_FAULT_UNDER_VOLT |MAV_BATTERY_STATUS_FLAGS_BAD_BATTERY },
    .
    .
};

(and iterate that to convert from one to the other

Comment on lines +11601 to +11609
self.get_sim_time(drain_mav=True) # required for timeout in run_cmd_get_ack to work
self.send_poll_message("BATTERY_STATUS_V2")
self.run_cmd_get_ack(
mavutil.mavlink.MAV_CMD_REQUEST_MESSAGE,
mavutil.mavlink.MAV_RESULT_ACCEPTED,
timeout=timeout_sec,
)
status_v2 = self.assert_receive_message("BATTERY_STATUS_V2",
timeout=timeout_sec)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.get_sim_time(drain_mav=True) # required for timeout in run_cmd_get_ack to work
self.send_poll_message("BATTERY_STATUS_V2")
self.run_cmd_get_ack(
mavutil.mavlink.MAV_CMD_REQUEST_MESSAGE,
mavutil.mavlink.MAV_RESULT_ACCEPTED,
timeout=timeout_sec,
)
status_v2 = self.assert_receive_message("BATTERY_STATUS_V2",
timeout=timeout_sec)
status_v2 = self.poll_message("BATTERY_STATUS_V2")

status_v2 = self.assert_receive_message("BATTERY_STATUS_V2",
timeout=timeout_sec)
status_v1 = self.assert_receive_message("BATTERY_STATUS",
timeout=timeout_sec,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
timeout=timeout_sec,

condition=f"BATTERY_STATUS.id=={status_v2.id}",
)

status_v1_voltage = status_v1.voltages[0] * 0.001

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert_received_message_values (with poll True)

raise NotAchievedException("Power-monitor BATTERY_STATUS_V2 should not report capacity relative to full")

self.start_subtest("Set BATTERY_STATUS_V2 stream rate")
self.set_message_rate_hz("BATTERY_STATUS_V2", 2)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        self.context_set_message_rate_hz("BATTERY_STATUS_V2", 2)

@hunt0r hunt0r force-pushed the support-mavlink-battery-status-v2 branch from da448a3 to c01c4a1 Compare May 28, 2026 14:07
@hunt0r hunt0r force-pushed the master branch 2 times, most recently from af38ddf to b8103d1 Compare June 7, 2026 12:39
@@ -75,6 +75,10 @@
#define AP_MAVLINK_MSG_WIND_ENABLED AP_AHRS_ENABLED
#endif

#ifndef AP_MAVLINK_BATTERY_STATUS_V2_ENABLED

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#ifndef AP_MAVLINK_BATTERY_STATUS_V2_ENABLED
#ifndef AP_MAVLINK_MSG_BATTERY_STATUS_V2_ENABLED

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants