Skip to content

Add Power configuration UI#3852

Open
Williangalvani wants to merge 2 commits intobluerobotics:masterfrom
Williangalvani:power-configuration
Open

Add Power configuration UI#3852
Williangalvani wants to merge 2 commits intobluerobotics:masterfrom
Williangalvani:power-configuration

Conversation

@Williangalvani
Copy link
Member

@Williangalvani Williangalvani commented Mar 24, 2026

Screenshot 2026-03-24 at 13 46 11

Summary by Sourcery

Add a new power configuration section to the vehicle setup UI for configuring and calibrating battery monitoring and sensors.

New Features:

  • Introduce a Power configuration panel in the vehicle setup flow with dedicated support for primary and secondary battery configuration.
  • Add a reusable BatteryCard component that exposes key battery monitor parameters, presets for common power sensors, and guided calibration dialogs for voltage and current.

Bug Fixes:

  • Prevent the inline parameter editor from skipping updates when a parameter has a falsy value by checking for null instead of truthiness.

Enhancements:

  • Wire up live battery voltage and current readings into the power configuration UI to assist with calibration.

The truthiness check `if (this.param?.value)` treated 0 as falsy,
so `internal_new_value_as_string` was never set and the field showed
the placeholder label instead of "0". Use `this.param != null` to
check for parameter existence regardless of its value.

Made-with: Cursor
Add a Power subtab under Vehicle Setup > Configure, modeled after
QGC's APMPowerComponent. Supports Battery 1/2 monitor selection,
power sensor presets (including Blue Robotics PSM), capacity, arming
voltage, and advanced calibration with voltage multiplier and amps
per volt calculation dialogs.

Made-with: Cursor
@sourcery-ai
Copy link

sourcery-ai bot commented Mar 24, 2026

Reviewer's Guide

Adds a new Power configuration section to the vehicle setup UI, including a reusable battery configuration card component with sensor presets and calibration helpers, wires it into the existing configuration navigation, and fixes a null-check bug in the inline parameter editor.

Sequence diagram for applying a power sensor preset in BatteryCard

sequenceDiagram
  actor User
  participant Configure as ConfigureComponent
  participant PowerConfiguration as PowerConfigurationComponent
  participant BatteryCard as BatteryCardComponent
  participant AutopilotStore as autopilot_data
  participant Mavlink2Rest as mavlink2rest

  User->>Configure: Select_Power_tab
  Configure->>PowerConfiguration: Render_PowerConfiguration
  PowerConfiguration->>BatteryCard: Render_BatteryCard_with_params

  User->>BatteryCard: Select_sensor_preset_from_dropdown
  BatteryCard->>BatteryCard: applySensorPreset(selected)
  BatteryCard->>AutopilotStore: Read_system_id
  alt Each_parameter_present
    BatteryCard->>Mavlink2Rest: setParam(voltPinParam.name, preset.voltPin, system_id)
    BatteryCard->>Mavlink2Rest: setParam(currPinParam.name, preset.currPin, system_id)
    BatteryCard->>Mavlink2Rest: setParam(voltMultParam.name, preset.voltMult, system_id)
    BatteryCard->>Mavlink2Rest: setParam(ampPerVoltParam.name, preset.ampPerVolt, system_id)
    BatteryCard->>Mavlink2Rest: setParam(ampOffsetParam.name, preset.ampOffset, system_id)
  end
  Mavlink2Rest-->>AutopilotStore: Parameters_updated_via_MAVLink
  AutopilotStore-->>BatteryCard: Updated_parameter_values
  BatteryCard-->>User: Updated_sensor_selection_and_advanced_values
Loading

Sequence diagram for voltage multiplier calibration helper

sequenceDiagram
  actor User
  participant BatteryCard as BatteryCardComponent
  participant AutopilotStore as autopilot_data
  participant Mavlink2Rest as mavlink2rest

  User->>BatteryCard: Click_Calculate_on_Voltage_Multiplier
  BatteryCard->>BatteryCard: show_voltage_calc = true
  BatteryCard-->>User: Show_voltage_calculation_dialog

  User->>BatteryCard: Enter_measured_voltage_and_click_Calculate_And_Set
  BatteryCard->>BatteryCard: calculateVoltageMultiplier()
  alt can_calculate_voltage_and_voltMultParam_present
    BatteryCard->>BatteryCard: newMult = measured_voltage * voltMultParam.value / voltage
    BatteryCard->>Mavlink2Rest: setParam(voltMultParam.name, newMult, AutopilotStore.system_id)
    BatteryCard->>BatteryCard: show_voltage_calc = false
    BatteryCard->>BatteryCard: measured_voltage = null
  else Invalid_input
    BatteryCard-->>User: Keep_dialog_open_with_disabled_button
  end
Loading

Class diagram for new PowerConfiguration and BatteryCard components

classDiagram
  class ConfigureComponent {
    +components
    +data()
  }

  class PowerConfigurationComponent {
    +computed params_finished_loaded() boolean
    +computed battery_voltage() number
    +computed battery_current() number
    +method parameter(name string) Parameter
  }

  class BatteryCardComponent {
    +prop title string
    +prop monitorParam Parameter
    +prop capacityParam Parameter
    +prop armVoltParam Parameter
    +prop voltPinParam Parameter
    +prop currPinParam Parameter
    +prop voltMultParam Parameter
    +prop ampPerVoltParam Parameter
    +prop ampOffsetParam Parameter
    +prop voltage number
    +prop current number

    +data selected_sensor string
    +data show_advanced boolean
    +data show_voltage_calc boolean
    +data show_current_calc boolean
    +data measured_voltage number
    +data measured_current number

    +computed monitor_enabled() boolean
    +computed sensor_options() string[]
    +computed can_calculate_voltage() boolean
    +computed can_calculate_current() boolean
    +computed sensor_fingerprint() string

    +method detectCurrentSensor() void
    +method applySensorPreset(selected string) void
    +method calculateVoltageMultiplier() void
    +method calculateAmpsPerVolt() void
  }

  class InlineParameterEditorComponent {
    +data internal_new_value number
    +data internal_new_value_as_string string
    +prop param Parameter
    +method validationLogic()
    +method updateInternalNewValue()
    +method render()
  }

  ConfigureComponent --> PowerConfigurationComponent : uses_as_tab_component
  PowerConfigurationComponent --> BatteryCardComponent : renders
  BatteryCardComponent --> InlineParameterEditorComponent : uses_for_param_editing

  class AutopilotStore {
    +finished_loading boolean
    +system_id number
    +parameter(name string) Parameter
  }

  class MavlinkStore {
  }

  class Mavlink2Rest {
    +setParam(name string, value number, system_id number) void
  }

  PowerConfigurationComponent --> AutopilotStore : reads_parameters
  PowerConfigurationComponent --> MavlinkStore : reads_telemetry_via_mavlink_store_get
  BatteryCardComponent --> AutopilotStore : reads_system_id
  BatteryCardComponent --> Mavlink2Rest : updates_parameters

  class Parameter {
    +name string
    +value any
  }

  BatteryCardComponent --> Parameter : receives_as_props
  InlineParameterEditorComponent --> Parameter : edits_value
Loading

File-Level Changes

Change Details Files
Wire the new Power configuration view into the vehicle setup screen.
  • Import the PowerConfiguration component into the vehicle Configure view.
  • Register PowerConfiguration in the component list.
  • Add a new 'Power' tab item pointing to the PowerConfiguration component.
core/frontend/src/components/vehiclesetup/Configure.vue
Fix null-handling bug in inline parameter editor string representation.
  • Change the param existence check from truthiness on param.value to a direct null check on param.
  • Ensure internal_new_value_as_string is updated whenever a parameter object is present, including when its value is 0.
core/frontend/src/components/parameter-editor/InlineParameterEditor.vue
Introduce a reusable battery configuration card with sensor presets and calibration tools.
  • Create a BatteryCard component that renders battery monitor, sensor selection, advanced pin/gain parameters, and capacity/arming voltage inputs using existing parameter editor components.
  • Add sensor preset definitions and logic to detect the current preset from parameter values and to apply presets via mavlink2rest.setParam.
  • Implement voltage multiplier and amps-per-volt calibration dialogs that compute new parameter values from measured vs reported voltage/current and write them through mavlink2rest.
  • Expose props for all relevant battery parameters and live voltage/current readings, and manage internal UI state (selected sensor, advanced toggle, dialogs).
core/frontend/src/components/vehiclesetup/configuration/power/BatteryCard.vue
Add a PowerConfiguration container that composes battery cards with autopilot parameters and live telemetry.
  • Create a PowerConfiguration component that renders BatteryCard for Battery 1 and conditionally Battery 2, wiring in the corresponding BATT/BATT2 parameters from the autopilot store.
  • Derive live battery voltage and current from SYS_STATUS MAVLink telemetry using mavlink_store_get and present them in BatteryCard.
  • Gate rendering on autopilot parameter loading completion and constrain the layout width.
core/frontend/src/components/vehiclesetup/configuration/power/PowerConfiguration.vue

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • In PowerConfiguration, battery_voltage and battery_current assume mavlink_store_get always returns a number; consider guarding against undefined or sentinel values (e.g. -1 for current_battery) before doing the division to avoid propagating NaN into the UI.
  • The detectCurrentSensor logic compares the current parameter values to the presets using exact equality on floats; introducing a small tolerance for the multiplier and amps/volt fields would make preset detection more robust after minor user adjustments or rounding differences.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In PowerConfiguration, `battery_voltage` and `battery_current` assume `mavlink_store_get` always returns a number; consider guarding against `undefined` or sentinel values (e.g. -1 for `current_battery`) before doing the division to avoid propagating `NaN` into the UI.
- The `detectCurrentSensor` logic compares the current parameter values to the presets using exact equality on floats; introducing a small tolerance for the multiplier and amps/volt fields would make preset detection more robust after minor user adjustments or rounding differences.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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