Skip to content

feat(battery): enable use of BAT_n_I_OVERWRITE for all battery estimation sources#26953

Open
sfuhrer wants to merge 1 commit intomainfrom
pr-battery-overwrite-non-analog-main
Open

feat(battery): enable use of BAT_n_I_OVERWRITE for all battery estimation sources#26953
sfuhrer wants to merge 1 commit intomainfrom
pr-battery-overwrite-non-analog-main

Conversation

@sfuhrer
Copy link
Copy Markdown
Contributor

@sfuhrer sfuhrer commented Apr 2, 2026

Solved Problem

BAT_n_I_OVERWRITE is only applied when the battery source is "analog". I see no reason to not apply it the same way for all estimation types (as the parameter meta data already implies).

Solution

Move the logic for the current overwrite out of the analog battery class into the generic one.

Changelog Entry

For release notes:

feat(battery): enable use of `BAT_n_I_OVERWRITE` for all battery estimation sources

Test coverage

SITL tested. Setting BAT_1_I_OVERWRITE to 1A is correctly displayed and the accumulated mAh increases.

Possible Alternatives

One can say that only analog estimation has a large error (which is true to some extend). In that case we should update the parameter description to make it clear that it only applies to analog.

Context

The "battery current overwrite" is useful to enable on systems that are expected to sit idle (disarmed) on the ground for a prolonged time, and don't have a very accurate current estimate.

Original PR for the current overwrite.

@sfuhrer sfuhrer requested review from alexcekay and mahima-yoga April 2, 2026 08:36
…tion sources

Signed-off-by: Silvan <silvan@auterion.com>
@sfuhrer sfuhrer force-pushed the pr-battery-overwrite-non-analog-main branch from a9c1d93 to dd652d0 Compare April 2, 2026 08:44
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 2, 2026

🔎 FLASH Analysis

px4_fmu-v5x [Total VM Diff: 8 byte (0 %)]
    FILE SIZE        VM SIZE    
--------------  -------------- 
+0.1%     +16  +0.1%     +16    .ramfunc
  +1.7%      +4  +1.7%      +4    param_get
  +1.4%      +4  +1.4%      +4    param_get_default_value
   +33%      +4   +33%      +4    param_get_index
  +9.1%      +4  +9.1%      +4    param_get_system_default_value
   +14%      +1   +14%      +1    ___ZN4ListIP13MavlinkStreamE8IteratorppEv.isra.0_veneer
 -12.5%      -1 -12.5%      -1    __clock_abstime2ticks_veneer
-0.0%     -19  [ = ]       0    .debug_abbrev
-0.0%     -16  [ = ]       0    .debug_aranges
-0.0%     -40  [ = ]       0    .debug_frame
-0.0%    -449  [ = ]       0    .debug_info
-0.0%    -220  [ = ]       0    .debug_line
 -75.0%      -3  [ = ]       0    [Unmapped]
  -0.0%    -217  [ = ]       0    [section .debug_line]
-0.0%    -254  [ = ]       0    .debug_loclists
-0.0%     -19  [ = ]       0    .debug_rnglists
-0.0%     -31  [ = ]       0    .debug_str
-0.4%      -1  [ = ]       0    .shstrtab
-0.0%     -35  [ = ]       0    .strtab
  [DEL]     -35  [ = ]       0    AnalogBattery::updateTopics()
   +80%     +16  [ = ]       0    __nxsem_wait_veneer
 -41.0%     -16  [ = ]       0    __up_block_task_veneer
-0.0%     -16  [ = ]       0    .symtab
 -25.0%     -16  [ = ]       0    AnalogBattery::get_current_channel()
  [DEL]     -16  [ = ]       0    AnalogBattery::updateTopics()
   +25%     +16  [ = ]       0    Battery::Battery()
   +50%     +16  [ = ]       0    Battery::updateCurrent()
 -50.0%     -16  [ = ]       0    Battery::updateVoltage()
 -25.0%     -16  [ = ]       0    Commander::handleCommandActuatorTest()
  +100%     +16  [ = ]       0    Commander::updateParameters()
 -33.3%     -16  [ = ]       0    ConstLayer::contains()
   +50%     +16  [ = ]       0    ConstLayer::store()
 -50.0%     +16  [ = ]       0    [1 Others]
  +0.6%     +64  [ = ]       0    [section .symtab]
   +33%     +16  [ = ]       0    ___ZN3Ekf23constrainStateVariancesEv_veneer
   +50%     +16  [ = ]       0    ___ZN4ListIP13MavlinkStreamE8IteratorppEv.isra.0_veneer
 -33.3%     -16  [ = ]       0    __clock_abstime2ticks_veneer
   +67%     +32  [ = ]       0    __nxsem_wait_veneer
 -25.0%     -16  [ = ]       0    __stm32_ep0out_ctrlsetup.isra.0_veneer
 -40.0%     -32  [ = ]       0    __up_block_task_veneer
 -50.0%     -16  [ = ]       0    param_for_index
  -7.7%     -16  [ = ]       0    param_get_cplusplus()
 -50.0%     -16  [ = ]       0    param_get_index
 -50.0%     -32  [ = ]       0    param_hash_check
-0.1%      -8  [ = ]       0    [Unmapped]
-0.0%      -8  -0.0%      -8    .text
 -98.0%     +50 -98.0%     +50    [13 Others]
   +21%     +40   +21%     +40    Battery::updateBatteryStatus()
  +0.0%     +40  +0.0%     +40    [section .text]
  +500%     +30  +500%     +30    Battery::updateCurrent()
  +3.3%     +24  +3.3%     +24    Battery::Battery()
   +10%     +14   +10%     +14    BatteryStatus::~BatteryStatus()
  +2.7%      +8  +2.7%      +8    Battery::updateParams()
  +0.0%      +8  +0.0%      +8    px4::parameters
   +33%      +4   +33%      +4    ConstLayer::contains()
   +17%      +4   +17%      +4    ConstLayer::get()
  +2.6%      +4  +2.6%      +4    param_find_internal()
   +25%      +4   +25%      +4    param_for_index
  -2.0%      -4  -2.0%      -4    Commander::updateParameters()
  -3.0%      -4  -3.0%      -4    FlightTaskAuto::rcHelpModifyYaw()
  -0.0%      -8  -0.0%      -8    g_cromfs_image
 -20.0%     -10 -20.0%     -10    AnalogBattery::~AnalogBattery()
  -7.1%     -12  -7.1%     -12    AnalogBattery::updateParams()
 -10.1%     -32 -10.1%     -32    AnalogBattery::updateBatteryStatusADC()
  [DEL]     -48  [DEL]     -48    AnalogBattery::updateTopics()
 -21.4%     -60 -21.4%     -60    AnalogBattery::AnalogBattery()
 -13.9%     -60 -13.9%     -60    Battery::computeRemainingTime()
-0.0% -1.07Ki  +0.0%      +8    TOTAL

px4_fmu-v6x [Total VM Diff: -168 byte (-0.01 %)]
    FILE SIZE        VM SIZE    
--------------  -------------- 
-0.0%     -19  [ = ]       0    .debug_abbrev
-0.0%     -16  [ = ]       0    .debug_aranges
-0.0%     -60  [ = ]       0    .debug_frame
-0.0%    -524  [ = ]       0    .debug_info
-0.0%    -345  [ = ]       0    .debug_line
  +600%      +6  [ = ]       0    [Unmapped]
  -0.0%    -351  [ = ]       0    [section .debug_line]
-0.0%    -271  [ = ]       0    .debug_loclists
-0.0%     -34  [ = ]       0    .debug_rnglists
  +200%      +2  [ = ]       0    [Unmapped]
  -0.0%     -36  [ = ]       0    [section .debug_rnglists]
-0.0%     -19  [ = ]       0    .debug_str
-0.8%      -2  [ = ]       0    .shstrtab
-0.0%     -34  [ = ]       0    .strtab
  [DEL]     -35  [ = ]       0    AnalogBattery::updateTopics()
  +0.0%      +1  [ = ]       0    do_not_explicitly_use_this_namespace::Param<>::update()
-0.0%     -16  [ = ]       0    .symtab
 -25.0%     -16  [ = ]       0    AnalogBattery::get_current_channel()
  [DEL]     -16  [ = ]       0    AnalogBattery::updateTopics()
   +25%     +16  [ = ]       0    Battery::Battery()
   +50%     +16  [ = ]       0    Battery::updateCurrent()
 -50.0%     -16  [ = ]       0    Battery::updateVoltage()
 -25.0%     -16  [ = ]       0    Commander::handleCommandActuatorTest()
  +100%     +16  [ = ]       0    Commander::updateParameters()
  +100%     +16  [ = ]       0    ConstLayer::containedAsBitset()
  +100%     +16  [ = ]       0    ConstLayer::contains()
 -33.3%     -16  [ = ]       0    ConstLayer::store()
   +25%     +16  [ = ]       0    DynamicSparseLayer::DynamicSparseLayer()
  -0.7%     -80  [ = ]       0    [section .symtab]
  +100%     +16  [ = ]       0    param_for_index
  +100%     +16  [ = ]       0    param_get_index
  +100%     +32  [ = ]       0    param_hash_check
 -25.0%     -16  [ = ]       0    param_import_internal()
+3.4%    +168  [ = ]       0    [Unmapped]
-0.0%    -168  -0.0%    -168    .text
   +21%     +40   +21%     +40    Battery::updateBatteryStatus()
  +0.0%     +36  +0.0%     +36    [section .text]
  +500%     +30  +500%     +30    Battery::updateCurrent()
  +3.3%     +24  +3.3%     +24    Battery::Battery()
   +10%     +14   +10%     +14    BatteryStatus::~BatteryStatus()
  +0.0%     +12  +0.0%     +12    g_cromfs_image
  +2.7%      +8  +2.7%      +8    Battery::updateParams()
  +0.1%      +8  +0.1%      +8    px4::parameters
  -2.0%      -4  -2.0%      -4    Commander::updateParameters()
  -5.6%      -4  -5.6%      -4    ConstLayer::containedAsBitset()
 -25.0%      -4 -25.0%      -4    ConstLayer::contains()
 -14.3%      -4 -14.3%      -4    ConstLayer::get()
  -2.6%      -8  -2.6%      -8    param_hash_check
 -20.0%     -10 -20.0%     -10    AnalogBattery::~AnalogBattery()
  -7.1%     -12  -7.1%     -12    AnalogBattery::updateParams()
  -4.5%     -20  -4.5%     -20    param_reset_specific
 -10.1%     -32 -10.1%     -32    AnalogBattery::updateBatteryStatusADC()
  [DEL]     -48  [DEL]     -48    AnalogBattery::updateTopics()
 -21.4%     -60 -21.4%     -60    AnalogBattery::AnalogBattery()
 -13.9%     -60 -13.9%     -60    Battery::computeRemainingTime()
 -101.4%     -74 -101.4%     -74    [26 Others]
-0.0% -1.31Ki  -0.0%    -168    TOTAL

Updated: 2026-04-02T08:52:16

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant