The Battery Monitor plugin displays real-time battery voltage and current with color-coded status indication (green=safe, red=critical, gray=disabled/unavailable). It reuses existing flight controller backend methods and follows the Model-View separation pattern.
Key Features:
- 500ms periodic updates
- Integrated at configuration step 08_batt1.param
- Real-time monitoring with color-coded status display
- Parameter upload capability for immediate tuning validation
┌─────────────────────────────────────────────────────────┐
│ GUI Layer (frontend_tkinter_battery_monitor.py) │
│ - UI layout, periodic updates, color-coded display │
│ - Upload button for selected parameter changes │
└──────────────────┬──────────────────────────────────────┘
│
┌──────────────────▼──────────────────────────────────────┐
│ Data Model (data_model_battery_monitor.py) │
│ - Business logic, status determination, data retrieval │
│ - Parameter editor integration for uploads │
└──────────────────┬──────────────────────────────────────┘
│
┌──────────────────▼──────────────────────────────────────┐
│ Backend (backend_flightcontroller.py) │
│ - MAVLink telemetry (existing, reused methods) │
│ - Parameter upload and validation │
└─────────────────────────────────────────────────────────┘
Responsibilities: Status determination, data retrieval coordination, backend abstraction, parameter editor integration
Key Methods:
is_battery_monitoring_enabled()- Check BATT_MONITOR != 0get_battery_status()- Returns (voltage, current) tuple or Noneget_voltage_status()- Returns "safe"/"critical"/"disabled"/"unavailable"get_battery_status_color()- Maps status to "green"/"red"/"gray"
Parameter Editor Integration:
- Optional
parameter_editorreference for upload capability - Enables parameter changes to be uploaded directly from plugin
- Maintains separation of concerns through optional dependency
Responsibilities: UI layout, periodic updates, visual presentation, parameter upload workflow
Key Features:
- Large, bold value displays with color-coding
- Informational text explaining status indicators
- 500ms periodic refresh via tkinter
after() on_activate()/on_deactivate()for plugin lifecycle- Upload button for selected parameters (when parameter editor available)
- Progress window integration for upload feedback
- Automatic table refresh after parameter upload
- Timer fires (500ms) →
_periodic_update()called - Check connection → Model verifies FC connection status
- Retrieve data → Model gets battery voltage/current from backend
- Determine status → Model evaluates voltage against thresholds (BATT_ARM_VOLT, MOT_BAT_VOLT_MAX)
- Update display → GUI formats values, applies color-coding, updates labels
- Schedule next → Timer scheduled for next update
- User clicks upload →
_on_upload_button_clicked()invoked - Gather selections → Retrieve selected parameters from parameter editor table
- Validate preconditions → Check FC connection and parameter selection
- Execute workflow → Call
upload_params_with_progress()with callbacks - Progress feedback → Display reset/download progress windows as needed
- Update FC values → Refresh parameter objects with new FC values
- Refresh table → Repopulate parameter editor table to show updated values
- Configuration Step: 08_batt1.param (all vehicle types)
- Plugin Registration:
@plugin_factory(PLUGIN_BATTERY_MONITOR)decorator - Backend Reuse: Leverages existing
backend_flightcontroller.pymethods (no new backend code required) - Parameter Editor Integration: Optional injection for upload capability
- UI Services Reuse: Leverages
ParameterEditorUiServicesfor consistent upload workflows
BDD pytest tests cover complete user workflows:
- Monitoring: Status determination, threshold validation, error handling, UI updates
- Parameter Upload: Selection, validation, progress feedback, error recovery
- Integration: Plugin lifecycle, data model + frontend interaction, table refresh
Test files:
tests/bdd_battery_monitor.py- End-to-end user scenariostests/acceptance_battery_monitor.py- Data model + frontend integrationtests/unit_data_model_battery_monitor.py- Data model unit tests
- 500ms update interval: Balances responsiveness with system load
- Color-coded display: Immediate visual feedback (green/red/gray)
- Backend reuse: No telemetry logic duplication, proven implementation
- Step 08 placement: Contextually relevant during battery configuration
- Optional parameter editor: Plugin works standalone for monitoring, enhanced with upload capability when editor available
- Centralized upload workflow: Reuses
upload_params_with_progress()for consistency across application - Immediate validation: Upload button enables users to test battery parameter changes without advancing to next step