FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(mavlink): handle unknown battery time remaining by msli-dev · Pull Request #27929 · PX4/PX4-Autopilot · GitHub

fix(mavlink): handle unknown battery time remaining - #27929

Merged
dakejahl merged 1 commit into
PX4:mainfrom
msli-dev:fix/mavlink-battery-time-remaining
Jul 16, 2026
Merged

dakejahl merged 1 commit into
PX4:mainfrom
msli-dev:fix/mavlink-battery-time-remaining

Conversation

Copy link
Copy Markdown
Contributor

Description

Convert an unavailable MAVLink BATTERY_STATUS.time_remaining value to NAN
when publishing battery_status.

MAVLink uses 0 to indicate that the remaining battery time estimate is not
provided, while the uORB battery_status.time_remaining_s field uses NAN as
its invalid value.

Previously, battery_status_s was zero-initialized and
time_remaining_s was not explicitly assigned. This left the field at
0.0f, which was treated as a valid estimate by battery checks. It was also
converted back to a MAVLink value of 1 second by the BATTERY_STATUS stream.

This change maps:

  • Positive time_remaining values to time_remaining_s
  • Zero or invalid values to NAN

Impact

This prevents an unavailable battery time estimate from being interpreted as
zero or one second remaining, which could incorrectly affect RTL battery-time
checks and downstream MAVLink consumers.

Test coverage

  • Verified that an incoming BATTERY_STATUS with time_remaining = 0
    publishes battery_status.time_remaining_s = NAN.
  • Verified that a positive time_remaining value is preserved in uORB.
  • Verified that the outgoing MAVLink BATTERY_STATUS.time_remaining remains
    0 when no estimate is available.

github-actions Bot added kind:bug Something is broken or behaving incorrectly. scope:offboard Offboard mode, external setpoints, companion-computer control, or offboard failsafe behavior. scope:mavlink MAVLink module, streams, commands, or protocol handling. labels Jul 16, 2026

Copy link
Copy Markdown
Contributor

🔎 FLASH Analysis

px4_fmu-v5x [Total VM Diff: 24 byte (0 %)]
    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +24  +0.0%     +24    .text
    [NEW]     +60  [NEW]     +60    CSWTCH.1936
    [NEW]     +42  [NEW]     +42    CSWTCH.2550
    +8.0%     +28  +8.0%     +28    MavlinkReceiver::handle_message_battery_status()
    [NEW]     +15  [NEW]     +15    CSWTCH.3470
    -0.7%      -4  -0.7%      -4    MavlinkReceiver::handle_message_hil_sensor()
    [DEL]     -15  [DEL]     -15    CSWTCH.3468
    [DEL]     -42  [DEL]     -42    CSWTCH.2549
    [DEL]     -60  [DEL]     -60    CSWTCH.1935
  +0.0%     +55  [ = ]       0    .debug_abbrev
  -0.0%      -2  [ = ]       0    .debug_info
  +0.0%     +27  [ = ]       0    .debug_line
     +33%      +1  [ = ]       0    [Unmapped]
    +0.0%     +26  [ = ]       0    [section .debug_line]
  -0.3%     -24  [ = ]       0    [Unmapped]
  +0.0%     +80  +0.0%     +24    TOTAL

px4_fmu-v6x [Total VM Diff: 24 byte (0 %)]
    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +24  +0.0%     +24    .text
    [NEW]     +60  [NEW]     +60    CSWTCH.1936
    [NEW]     +42  [NEW]     +42    CSWTCH.2550
    +8.0%     +28  +8.0%     +28    MavlinkReceiver::handle_message_battery_status()
    [NEW]     +15  [NEW]     +15    CSWTCH.3470
    -0.7%      -4  -0.7%      -4    MavlinkReceiver::handle_message_hil_sensor()
    [DEL]     -15  [DEL]     -15    CSWTCH.3468
    [DEL]     -42  [DEL]     -42    CSWTCH.2549
    [DEL]     -60  [DEL]     -60    CSWTCH.1935
  +0.0%     +55  [ = ]       0    .debug_abbrev
  -0.0%      -2  [ = ]       0    .debug_info
  +0.0%     +19  [ = ]       0    .debug_line
    [DEL]      -7  [ = ]       0    [Unmapped]
    +0.0%     +26  [ = ]       0    [section .debug_line]
  -0.0%     -12  [ = ]       0    .debug_loclists
  -0.4%     -24  [ = ]       0    [Unmapped]
  +0.0%     +60  +0.0%     +24    TOTAL

Updated: 2026-07-16T10:43:35

Copy link
Copy Markdown
Contributor

@msli-dev u have any logs? I just want to make sure it doesnt break anything else. Overall the aproach makes sense.

dakejahl merged commit eddc929 into PX4:main Jul 16, 2026
31 checks passed
msli-dev deleted the fix/mavlink-battery-time-remaining branch July 16, 2026 22:28
mrpollo pushed a commit that referenced this pull request Aug 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:bug Something is broken or behaving incorrectly. scope:mavlink MAVLink module, streams, commands, or protocol handling. scope:offboard Offboard mode, external setpoints, companion-computer control, or offboard failsafe behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL