Add Power configuration UI#3852
Open
Williangalvani wants to merge 2 commits intobluerobotics:masterfrom
Open
Conversation
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
Reviewer's GuideAdds 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 BatteryCardsequenceDiagram
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
Sequence diagram for voltage multiplier calibration helpersequenceDiagram
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
Class diagram for new PowerConfiguration and BatteryCard componentsclassDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In PowerConfiguration,
battery_voltageandbattery_currentassumemavlink_store_getalways returns a number; consider guarding againstundefinedor sentinel values (e.g. -1 forcurrent_battery) before doing the division to avoid propagatingNaNinto the UI. - The
detectCurrentSensorlogic 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.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
Add a new power configuration section to the vehicle setup UI for configuring and calibrating battery monitoring and sensors.
New Features:
Bug Fixes:
Enhancements: